-
Notifications
You must be signed in to change notification settings - Fork 18
WMSDK-543: Migrate metadata from MBDatabase to PersistenceStorage (UserDefaults)
#603
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
WMSDK-543: Migrate metadata from MBDatabase to PersistenceStorage (UserDefaults)
#603
Conversation
…torage - Move metadata handling out of `DatabaseRepositoryProtocol` and into a dedicated `DatabaseMetadataMigration`. - Read/write metadata directly via `store.metadata` (through `MBDatabaseRepository persistentContainer`) inside the migration—no public getters/setters on the protocol. - Make the migration idempotent: - isNeeded checks that target PersistenceStorage fields are empty and source metadata keys exist. - Safely clears keys via metadata update (no-op if store is unavailable). - Document the repair & preservation flow with SwiftDoc: - `salvageMetadataFromOnDiskStore()`, `applyMetadata(_:to:)`. `loadPersistentContainer()`. `destroy()`. and `makeInMemoryContainer()`. - Naming: prefer suffix style for migrations; e.g. ShownInAppIDsMigration.
|
По тестам может что-то ещё нужно где-то дописать.. Я не нашел. Может ты что-то увидишь. |
Mindbox/Utilities/Migrations/ImplementationOfMigrations/DatabaseMetadataMigration.swift
Outdated
Show resolved
Hide resolved
…eded` for CoreData → UserDefaults metadata
- Add “cleanup-only” path to DatabaseMetadataMigration:
- If destination (PersistenceStorage) already has values but Core Data metadata
still contains keys, migration runs only to clear metadata on the store.
- Refine `isNeeded`:
- true if copy is needed (destination is nil and metadata exists), OR
- true if cleanup is needed (destination is set and metadata still exists).
- Make `run()` idempotent and safe:
- Write to PersistenceStorage only when destination fields are nil.
- Always clear both metadata keys to avoid future re-triggers.
- Keep version = 3 (no change in migration ordering).
- Tests:
- Added coverage for cleanup-only, copy-only, partial-copy, idempotence,
and no-op when nothing to migrate.
- Minor: avoid accidentally storing Optional<T> into metadata dictionary.
Why:
- On first launch the app may fall back to InMemory and migrate there; a later
on-disk launch could still carry stale metadata. Cleanup-only ensures the store
is sanitized without overwriting destination values.
| } | ||
|
|
||
| private func install(deviceUUID: String, configuration: MBConfiguration) { | ||
| persistenceStorage.eraseApplicationInfoUpdateVersionAndInstanceId() |
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.
Мб тут не будем усложнять, и оставим eraseMetadata?
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.
Думал об этом. А мы точно вспомним что там за метадата удаляется? Или по реализации метода поймем? Поэтому конкретики добавил в названии метода.
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.
имхо, почитаем и поймем
плюс тесты есть на это
Change `eraseApplicationInfoUpdateVersionAndInstanceId` to `eraseMetadata`, fix comments and add docs
|
|
Issue