-
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
Use relative paths to the storage #3444
Conversation
In the forms database, |
Ahhh I completly forgot that we use paths there and was thinking about creating databases only.... ok sorry I'll fix it. |
705e103
to
38e7185
Compare
38e7185
to
b2a492b
Compare
Hey, I migrated paths as we discussed but it's been bothering me and I wanted to talk with you. |
Agreed. We also have the option to hold this for the next release too since it's not urgent. I'd rather get it in now if possible but depending on the answers below we may consider waiting.
It seems to me that down migrations should be able to deal with the need to downgrade the app. We're not actually moving files with this step so it should be possible to add the absolute path prefix back again to the database contents on downgrade. Right?
This seems like it will be true when we actually move the files but not with this step. My sense is that we should delay actually moving the files until we have to. That way we can make sure to have communicated with users and received feedback about the impact. But I think that when it comes to forks this will largely be a positive change. I expect that the biggest disruption will be for folks who have companion apps and make assumptions about the locations of Collect files. They'll need to update their apps to go through the providers. |
I'm not removing absolute path prefixes in my approach, instead I add new rows with relative paths from now and make the code able to deal with both (new relative paths and those full saved before).
Yes I see, I'm just talking about shared db files. If someone has Collect v1.25 (let's assume with this pr) the saved paths will be relative what makes such rows unavailable from a fork which is based on an older version of collect. |
Ah, of course. For some reason my brain has trouble dealing with the idea that the down migration code is in the old version, not in the new one. So we could introduce a down migration in v1.25 but not actually change paths yet. Then we could change paths and increment the db version in v1.26 or later. That way it would always be possible to downgrade to any version going through a downgrade to v1.25. I'm thinking that for that downgrade, instead of using a db version, we could use a separate
This essentially splits the migration to relative paths in two parts, right? The one-time migration would involve creating a new column, copying in all the relative paths, deleting the original column and renaming the new column. You're suggesting doing half of that work now and the other half later so that the v1.25 db will have redundant columns but will always work with older versions, right? That seems like a reasonable approach to me as long as you also have the down migrations for each db. Clever.
Ah yes, I get you. Collect will write relative paths which will make the forms "invisible" to the fork. And the fork will write absolute paths which means the db will be in a weird hybrid state but your code will deal with both. It's annoying but your concept with the two columns mitigates that. Then when we do the full switch of the column we can start by recomputing the relative column. When you get a chance, can you please update the PR description with the intended behavior in various interesting cases? There are lots of great details you've thought about that are not immediately obvious. I haven't looked at the code in detail yet but I noticed that you have relative paths that start with |
You are talking about upgrading/downgrading databases and even adding a new column but that's not how I implemented it. Sorry I should have described it above (will do).
Now we use paths like: |
The existing down migration for
Thanks for walking me through all of it. I guess are you thinking that we don't really need a migration to make all paths relative because we can continue to look for What do you think about, for this release, not making any changes to the actual paths that are written and only including new down migrations for the dbs with content that can't be thrown away? I'm imagining it doing something like check the first path in the column to see if it's absolute. If it's absolute, do nothing. If it's relative, copy path columns over, make all paths absolute, copy the column back to the original name. I don't actually think that needs to be wrapped in any conditional. It would ensure that all versions between 1.25 and whenever we actually migrate to relative paths can be downgraded to.
Given that the docs for There's a lot going on here so if my proposal doesn't make sense or there are still subtleties to discuss, we should try to sync up on a quick call your Monday afternoon. |
Ok I think it's a reasonable solution. We can implement when it comes to relative paths should I use |
Ready #3460 |
Thanks. And so this will go back down to just the first commit and the rest will be saved for a future version, right? |
Based on this discussion and exploration we have refined the strategy and it is now described in #3360. |
What has been done to verify that this works as intended?
Why is this the best possible solution? Were any other approaches considered?
We will have to upgrade
targetSdkVersion
to 29 next year that means we will need to use scoped storage so that we won't be able to use sd card like we do now to store our files.This pr is a first step towards that goal. I refactored the code in order to refer to sd card just in one place so that we will be able to replace that code easily and use our app directory in the feature.
Now
Environment.getExternalStorageDirectory()
is used just in one place (to be honest there is one method which uses it as well but it will be removed/replaced anyway) and we will be able to replace it withContext#getExternalFilesDir()
easily.@lognaturel we were talking about paths in databases but in fact I can't see anything that should be refactored there. Please let me know if I missed something.
How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?
The changes are related to everything so it requires to be tested carefully. It's even difficult to tell what exactly should be tested because the risk is everywhere but the most important thing is to test databases:
Upgrading and downgrading is also very important here!
Do we need any specific form for testing your changes? If so, please attach one.
No.
Does this change require updates to documentation? If so, please file an issue here and include the link below.
No.
Before submitting this PR, please make sure you have:
./gradlew checkAll
and confirmed all checks still pass OR confirm CircleCI build passes and run./gradlew connectedDebugAndroidTest
locally.