-
Notifications
You must be signed in to change notification settings - Fork 194
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
Rename db file #110
Open
djih
wants to merge
9
commits into
master
Choose a base branch
from
rename_db_file
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Rename db file #110
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… guarded db interactions with apikey check
NSError *error; | ||
if (![fileManager fileExistsAtPath:to] && | ||
[fileManager fileExistsAtPath:from]) { | ||
if ([fileManager copyItemAtPath:from toPath:to error:&error]) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you use moveItemAtPath
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
changed
LGTM, update readme |
RECAP of this PR's changes
PTAL @curtisliu |
@djih close this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This mirrors the db file renaming work done on Android: https://github.com/amplitude/Amplitude-Android/pull/112/files
Tested the renaming on demo app on both simulator and real test device. Also tested that subsequent re-opening of app skips the renaming. Tested that all the database data was still intact (previous sessionId, last event time, deviceId, event id, etc). Added two unit tests as well.
A lot of the test updates is just fixing the call to
getDatabaseHelper
. I added a new extra methodgetDatabaseHelperWithInstanceName
just for testing, explicitly with a new name so that any uncaught calls to the oldgetDatabaseHelper:instanceName
would not erroneously get mapped to the test method. The purpose of the test method is to re-generate the old database file, sidestepping the static _instances which I cannot access directly.We already have a helper method to move files around, so I just factored it out into AMPUtils.
Note: the new database filename is in the form
com.amplitude.database_instancename_apiKey
. I was a little worried that the filename might become too long. iOS limits the full file path to 1024 chars, and the actual filename to 255 chars. On the actual test device, the full path looks like this:/var/mobile/Containers/Data/Application/85A9D80F-FA07-456F-A1CB-BD4C54145649/Library/com.amplitude.database_app2_c6fa6b27f515fb3f0e5ece6caf86027b
, which is only 145 characters. So I think it's safe to use that format for the new name.This builds on top of #109. Comments from that PR:
We need to migrate any database interaction logic in the
init
method into theinitializeApiKey
method since we will need the apiKey to interact with the database. I also run theinit
logic on thebackgroundQueue
, removing the need for a separateinitializerQueue
.Few things to note:
_dbHelper
is initialized ininitializeApiKey
now. Any public methods that interact with the database such assetUserId
,setDeviceId
,identify
, etc need to be guarded with an apiKey check to ensure[self.dbHelper]
is available[self addObservers]
toinitializeApiKey
sinceenterBackground
interacts with the DB by saving the current timestamp.