Note: this discussion is most likely going to be in the context of the next version of farmOS (8.x-2.x) built on Drupal 8. See #2361735: [META] Map out Drupal 8 / farmOS 8.x-2.x Dependencies
In farmOS 7.x-1.x, "Asset" entities are used to represent things like plantings, animals, equipment, etc, and "Log" entities are used to represent events that occur in relation to those assets.
Sometimes there is ambiguity around where a certain piece of data should be stored: on the asset, or on the log. In farmOS 7.x-1.x, revisions to assets are not stored, so changes to fields on assets do not get recorded in a structured way with a timestamp. Generally speaking, this means that fields on assets should be used for unchanging attributes of the assets, like "Name", "Crop", "Sex", etc.
An example of a changing attribute is location. Asset location is assigned by creating Movement logs that reference the asset. So an asset's location is not a field on the asset, but rather determined by looking at the most recent Movement log of that asset.
For some attributes, it's less clear whether a field or a log should be used. For example, assets have a checkbox on them that designates whether they are "Active" or not. Assets that are not active are considered "archived" in farmOS, and are not displayed in most of the UI by default.
The difficult in storing "Active" as a field, however, is that we can't tell exactly when an asset was marked active/inactive. The only timestamp recorded is the asset's "last modified" timestamp, but because that is not directly tied to the "active" field it is not reliable for that purpose.
In Drupal 8, assets will store revisions automatically. So every time you save an asset, it will save a new revision, and that revision will have a timestamp. This will allow more accurate tracking of changes to fields on the asset.
It begs the question, though: should location also be a field on the asset? And should changing locations be stored as revisions instead of movement logs? This question got me thinking more about the question: when should an asset's attribute be store in a field, and when should it be stored in a log?
I would like to propose the following rules for deciding that - for review and discussion - and to be included in the developer documentation:
If the change is specifically for one asset: use revisions.
If the change can apply to multiple assets: use logs.
In the "location" example, these rules explain why it makes sense to use logs instead of revisions. If revisions were used, and you moved 200 cattle, the same movement information and geometry would need to be stored as a revision in each of the cattle assets. With a log, you can store it in one place and reference all the assets.
In the "active" example, it makes more sense to store each active/inactive status on the assets themselves, as revisions.
That's my current thinking at least. Ideas welcome!
Comments
Comment #2
m.stentaNext question: how do we take these ideas, and create a unified experience for users of farmOS? It is already confusing that you need to use logs for some things, and edit the asset for others. How can we make that easier?
One idea might be to enforce a sort of "logs-for-everything" approach - where all editing of assets must happen through logs. So each asset revision would be tied directly to a log. Not sure exactly what that would look like in detail... maybe easier said than done, but it's one idea...
Or, maybe with Drupal 8's inline editing features, it will naturally be more intuitive because users will be able to edit the fields of assets while they are looking at them - without needing to click the "Edit" tab at all. So each asset view page will contain both links for editing specific fields on the asset AND links for adding logs to the asset. That may be the easiest approach, so unless we come up with something better it will probably be where we start.
Comment #3
BruceDawson commentedIn order to address this issue, I think there needs to be a segregation between policy/procedural changes and atomic/mechanical changes.
Policy/procedural changes are those that change the way the business operates. For instance, setting the state of an animal to "sold". This should be handled by Log - partially because Log is better suited for changing business procedures/policies and can be more easily changed in an orthogonal manner.
Atomic/mechanical changes are those that change the way a particular item instance operates. For instance, updating the description of a field to change a typo. These can be easily handled by revisions.
So, the real problem is the user, and that they'll design things a certain way, and then want to quickly redesign, but that's hard. I say let this happen a few times, and try to determine the most common patterns.
Comment #4
BruceDawson commentedI still think that at least the individual asset entities need to have revisions. Logs aren't considered assets (maybe: actions on assets), so its not as important to have revisions on logs - I like revisions because I can judge how "trustworthy" a particular asset/log is by the number and type of revisions on it.
Comment #5
m.stentaAgreed - and I haven't put much consideration into adding revisions to logs (yet). It's less necessary than on assets, in general, because logs are not typically edited more than once or twice. If we can get it for free without much effort in Drupal 8, then I'll do it, but it's not a main priority right now.
Just to clarify: I do plan on adding asset revisions regardless. This discussion is mainly just me brainstorming what types of changes make sense to fall into the "revision" column vs the "log" column. In general logs will cover most things (even if they only apply to one asset), just for consistency. But it will be great to also have asset revisions for more granular history of changes to the asset entity itself.
Comment #6
m.stentaI want to resurrect this discussion, as we've been talking a bit about these distinctions again in chat and on the monthly call.
It also relates to #2630218: Define asset lifespan via logs, I think, which came up again in recent forum discussions: https://farmos.discourse.group/t/additional-log-time-features-any-intere...
Comment #7
m.stentaSpecifically: in farmOS 2.x we are considering some changes (or additional options perhaps) to the way an asset's "geometry" can be stored/changed.
I am writing up a separate issue for that discussion - I will link to it from here...
Comment #8
m.stentaI'm going to close this. Future discussions related to this can happen in the forum.