Skip to content
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

Migrating trip and cache databases to the App Group #70

Closed
EdwardHinkle opened this issue Sep 15, 2018 · 4 comments
Closed

Migrating trip and cache databases to the App Group #70

EdwardHinkle opened this issue Sep 15, 2018 · 4 comments

Comments

@EdwardHinkle
Copy link
Contributor

EdwardHinkle commented Sep 15, 2018

So #64 is pretty much complete. The only remaining issue is the databases are currently located within the App's Document and Caches directories. These are inaccessible to the Siri Intent extension.
This is obviously complicated and potentially semi-dangerous because it deals with data so I wanted to brainstorm the solution here.

This is just a quick brain dump, feel free to clear up any misconceptions from your own knowledge, @aaronpk.

Migration

The migration code will be written in Swift and be called from the App Delegate on launch.

On first app launch, it should check for a configuration value to see if migration has occurred. If migration has NOT occurred, it will present a "migrating database" screen so the user knows something is going on.

Migration needs to take a look for any existing trips and save info about what is currently happening.

Migration sets sendingInterval to -1 so that it doesn't try to send data and then sets runs stopAllUpdates().

Migration then should safely be able to safely move the trip and cache databases to the new location

Once file is moved, the Migration can restart any trips, updates and restore the sendingInterval to the previous value.

Update Paths

The GLManager will remain in Objective-C and will just need the path to the databases updated to reflect the correct App Group database location that we are going to relocate the files to.

The functions here will need to be updated to point to the new App Group locations.

+ (NSString *)tripDatabasePath {
NSString *docsPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
return [docsPath stringByAppendingPathComponent:@"trips.sqlite"];
}

+ (NSString *)cacheDatabasePath
{
NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
return [caches stringByAppendingPathComponent:@"GLLoggerCache.sqlite"];
}

Additional concerns:

An additional question is if someone has active tracking turned on, and the app downloads. If it is running periodically in the background, I wonder if any background code would run before the app was opened in the foreground causing an error if the migration script hasn’t run.

This might mean that instead of the GLManager having a static path, it might need to actually check for the migration setting and if migration is false, return the old path and if migration is true, return the new path.

This leads the question about what we call the migration setting. databaseVersion and then set it to 2 after migration and if databaseVersion setting doesn’t exist, it returns the old path?

Some tech notes:

@EdwardHinkle
Copy link
Contributor Author

Actually upon looking at the code this evening, I’m wondering if we actually have to move the databases themselves. Technically I only have to call “startTrip” and “endTrip” from the intent Extension. Currently those functions do happen to call the open and close calls on the database, but if we could move those calls to the next location update and just have “startTrip” and “endTrip” set NSUserDefaults, then the databases could remain where they are, the intent would just set the NSUserDefaults to inform the app that a trip should begin and then the next location update it could open or close the databases based on the NSUserDefaults settings.

That might be a preferable method but it means changing the GLManager around a little so I’m not sure which one you are more comfortable with.

@aaronpk
Copy link
Owner

aaronpk commented Sep 17, 2018

Interesting idea. I think I'd prefer less structural changes, so having startTrip just write to defaults makes sense. Let's go with that approach for now, the database migration aspect makes me nervous.

@EdwardHinkle
Copy link
Contributor Author

Makes sense. The more I looked at it, the more nervous it made me too! I’ll put all of that as a single commit so that I can paste a link to the commit here for review since it’ll require some minor Objective-C work but I haven’t done much ObjC before.

@EdwardHinkle
Copy link
Contributor Author

Actually I take that back, I’ll close this issue, and continue the defaults changes back in #64 since this issue was specifically about migration as a big issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants