Skip to content

Conversation

@justSmK
Copy link
Contributor

@justSmK justSmK commented Oct 1, 2025

…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.
@justSmK justSmK requested a review from Vailence October 1, 2025 17:03
@justSmK
Copy link
Contributor Author

justSmK commented Oct 1, 2025

По тестам может что-то ещё нужно где-то дописать.. Я не нашел. Может ты что-то увидишь.

…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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Мб тут не будем усложнять, и оставим eraseMetadata?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Думал об этом. А мы точно вспомним что там за метадата удаляется? Или по реализации метода поймем? Поэтому конкретики добавил в названии метода.

Copy link
Collaborator

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
@justSmK justSmK requested a review from Vailence October 6, 2025 16:30
@justSmK
Copy link
Contributor Author

justSmK commented Oct 7, 2025

По идее теперь можно убрать даже применения кэша метадаты из лоадера. Я проверю это сяду

@justSmK justSmK merged commit bc55cb3 into develop Oct 7, 2025
5 checks passed
@justSmK justSmK deleted the feature/WMSDK-543-migrate-metadata-from-mbdatabase-to-userdefaults branch October 7, 2025 10:06
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

Successfully merging this pull request may close these issues.

3 participants