-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow entities to be deleted/cleared locally #6012
Comments
@lognaturel what happens on instance deletion isn't something we've actually discussed before! It feels fairly clear to me how it should behave, but have a look over the acceptance to check that you agree with the scenarios or if you think I'm missing something. |
Let's say I created EntityA locally with SubmissionA. Then I updated EntityA locally with SubmissionA1. If I delete SubmissionA1, at most I would expect the update to be rolled back, not the whole entity creation. If we delete the entity, then no further follow up is possible. I think this violates some of the goals we described for entity updates: we'd like users in the field to continue being able to make progress even if they make a mistake.
I think this is going to be difficult to do well. What if you had 3 offline updates and you delete the submission responsible for the second one? I don't think it's worth the complexity to keep track of all those revisions and come up with a process for rolling back one in the middle. This is a tricky area indeed! I don't think we want to enable individual entity deletion ever. It will eventually be possible for form submissions to archive entities which will have the effect of hiding them locally but I don't think we want to do anything like that outside of form submissions. The issue is that form submissions are the way we apply changes to entities and those can currently be deleted before they're sent. If a user deletes a submission without that having any impact on the local entity representation, then the server and client can get irrecoverably out of sync. Here are some directions we could go in:
|
@lognaturel ooooft good thinking!
This feels like a good starting point and would allow us to layer on more complex "instance with entity" deletion behaviour later. I think your point about the "ghost" entities convinces me we don't want to allow entities to exist after their instance is deleted. If you're happy with that I'll update the acceptance. |
Sounds good! |
@lognaturel I've updated the acceptance so all "Saved forms and entities" can be reset from project settings (replacing the current "Saved forms" option), but saved forms that have created an entity that's currently dirty/offline can't be deleted. |
I'm liking allowing deletes only as all-or-nothing and grouping form instances and entities! It feels easy to explain and I'm not finding any obvious way to get into a bad state.
I want to explicitly call out that this implies that conceptually, "offline/dirty" entities live alongside the online entities they're based on. This potentially adds quite a bit of complexity. As we drive out the offline data model, I think we should carefully consider whether there are other user-facing requirements that lead to this need. For this need only, we might be able to do something like delete all entities from the entity list and reload from CSV (and then we'd need another answer when we add progressive updates). |
Yeah I agree. I've been mulling this over as it feels like a big add to complexity, yet I'm not clear on what the alternative would be. I don't think we can end up in a scenario where the updated entity is missing until the next update. Is there another possibility you can think of? I think your idea on implementation is going to be what we end up with: we delete our entity storage and "reingest" from the CSVs. |
I've been having a think about different ways to store entities, and far as I can tell we're definitely looking at a SQLite database (per project). Given that, it feels like there are two options for how to structure it: a single table for all entities (with a string column for the entity list and another for properties that uses JSON), or a multi table version with a table for entity lists and then a table for each entity list (with a column for each property and a foreign key linking it to the list). The former is definitely simpler as we avoid anything "dynamic": we don't have to create tables on the fly or migrate them when new properties appear. We haven't actually done it yet, but we will probably need to query properties in the future (for #5623 for instance). This makes the single table option risky as we don't know how performant the SQLite JSON functions will be. Given that I'm going to start #5623 next (probably to just get to a place where understand how it will be structured) and then do an experiment to investigate the JSON performance after. My reasoning for not going straight into the JSON experiment is that there's still an open question around how exactly we'll deal with the fact that we need to be able to query datasets and return references rather than data. That should give us more info to continue discussing this. In the meantime, let me know if there are any alternatives I might have missed or anything that doesn't make sense. |
In Collect on a real Android device, do some quick checks with jsonb column vs normalized:
|
It looks like the JSON functionality is not available in the version of SQLite that ships with Android until Android 14 which makes using it larger hurdle (even if the performance is good enough). Given that, I reckon we're most likely looking at using the "multi table" implementation. Here's my dodgy sketch of how that could look: And just to clarify, I'm implying that
I think another thing to decide is where to actually store the Let me know if there are any thoughts on any of that! |
Blocked by #6011Blocked by #5623Blocked by #6245Entities that are created/locally should be deletable like other data in the app. Users should not be able to delete an instance that has created/updated an entity (to prevent data inconsistencies with the server) until it has been sent, but should be able to clear all saved forms/entities out at once from settings.
Acceptance
Given I've created an entity locally
When I reset "Saved forms and entities" (in "Project management" settings)
Then the entity no longer appears in follow-up forms
And the entity does not appear in "View local entities"
Given I've created an entity locally
When I navigate to "Delete saved form"
Then the instance that created the entity does not appear in the list
Given I've created an entity locally
And submitted the form that created it
When I delete the instance that created it via "Delete saved forms"
Then the entity still appears in follow-up forms
Given I've updated an entity locally
And a previous version of the entity was in an entity list
When I reset "Saved forms and entities" (in "Project management" settings)
Then the previous version is shown in follow-up forms
And the previous version appears in "View local entities"
Given I've updated an entity locally
When I navigate to "Delete saved form"
Then the instance that updated the entity does not appear in the list
Given I've updated an entity locally
And submitted the form that updated it
When I delete the instance that updated it via "Delete saved forms"
Then the entity still appears in follow-up forms
Questions
Where/how should we store entities? This feels like the right place to make that decision.SQLite
DB stored inmetadata
alongside the other databases.The text was updated successfully, but these errors were encountered: