-
Notifications
You must be signed in to change notification settings - Fork 199
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
feat(DataStore): database recreation based on new schema #551
Conversation
…ed two integration tests
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/AWSDataStorePlugin.swift
Outdated
Show resolved
Hide resolved
@@ -16,12 +16,11 @@ final class SQLiteStorageEngineAdapter: StorageEngineAdapter { | |||
|
|||
internal var connection: Connection! | |||
private var dbFilePath: URL? | |||
static let dbVersionKey = "com.awsamazon.dataStore.dbVersion" |
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.
a search for "com." shows a few examples like com.amazonaws.DataStore.AWSIncomingEventReconciliationQueue
so let's keep it the same like com.amazonaws.DataStore.dbVersion
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, but in PictureThis the bundle identifier is "com.awsamazon.PictureThis" instead of "com.amazonaws.PictureThis". I guess "awsamazon" or "amazonaws" doesn't matter?
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.
oh good point, not sure which is the right one, more important for the codebase to be consistent regardless of PictureThis's bundle since it's external sample app
...lugins/DataStore/AWSDataStoreCategoryPlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift
Outdated
Show resolved
Hide resolved
...lugins/DataStore/AWSDataStoreCategoryPlugin/Storage/SQLite/StorageEngineAdapter+SQLite.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPlugin/Storage/StorageEngine.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/DataStoreModelsVersionTests.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/DataStoreModelsVersionTests.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/DataStoreModelsVersionTests.swift
Outdated
Show resolved
Hide resolved
AmplifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/Core/DataStoreModelsVersionTests.swift
Outdated
Show resolved
Hide resolved
...ifyPlugins/DataStore/AWSDataStoreCategoryPluginTests/TestSupport/Mocks/MockFileManager.swift
Outdated
Show resolved
Hide resolved
...ugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreConfigurationTests.swift
Show resolved
Hide resolved
...ugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreConfigurationTests.swift
Outdated
Show resolved
Hide resolved
...ugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreConfigurationTests.swift
Outdated
Show resolved
Hide resolved
...ugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreConfigurationTests.swift
Outdated
Show resolved
Hide resolved
...ugins/DataStore/AWSDataStoreCategoryPluginIntegrationTests/DataStoreConfigurationTests.swift
Outdated
Show resolved
Hide resolved
_ = UserDefaults.removeObject(userDefaults) | ||
} | ||
|
||
func testVersionInUserDefaultsRemainsSameAndFileExists() { |
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.
test name like testClearIfNewVersionWithVersionSameAsPrevious
let previousVersion = "previousVersion"
userDefaults.set(previousVersion ..
try SQLiteStorageEngineAdaapter.clearIfNewVersion(previousVersion,
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.
Actually, here is having an additional var necessary?
userDefaults.set("previousVersion", forKey: SQLiteStorageEngineAdapter.dbVersionKey)
is OK? Because "previousVersion" is used only once.
...Plugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLiteStorageEngineAdapterTests.swift
Show resolved
Hide resolved
...Plugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLiteStorageEngineAdapterTests.swift
Outdated
Show resolved
Hide resolved
...Plugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLiteStorageEngineAdapterTests.swift
Outdated
Show resolved
Hide resolved
...Plugins/DataStore/AWSDataStoreCategoryPluginTests/Core/SQLiteStorageEngineAdapterTests.swift
Outdated
Show resolved
Hide resolved
userDefaults: userDefaults, | ||
fileManager: mockFileManager) | ||
} catch { | ||
XCTAssertEqual(error as? MockFileManagerError, MockFileManagerError.removeItemError) |
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.
assert is DataStoreError.invalidDatabase
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.
Done
try fileManager.removeItem(at: dbFilePath) | ||
} catch { | ||
log.error("\(#function) Failed to delete database file located at: \(dbFilePath), error: \(error)") | ||
throw 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.
wrap in DataStoreError.invalidDatabase(path: dbFilePath.absoluteString, 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.
Done
Description of changes:
UserDefaults
databaseModelRegistration.version
to verify the right one is being used when starting theStorageAdapter
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.