Skip to content

Conversation

@SajeeTechi
Copy link
Contributor

No description provided.

Implements a robust version 5 migration for the accounts table to handle different upgrade paths and fix data corruption caused by a previous migration.

Key changes:
- Robust Column Addition: Replaces the direct 'ALTER TABLE' with `AddAccountFactoryAddressIfNotExists`. This uses a PRAGMA check to prevent crashes on builds where the column might already exist (e.g., AppKevin path).
- ID Cleanup Logic: Introduces `CleanDirtyV4Accounts` to identify and fix accounts using the "bad" ID format (`address@factory@alias`). It reverts these IDs back to the standard format (`address@alias`).
- Conflict Handling: During cleanup, ensures that if a correct ID already exists, the dirty duplicate is removed without overwriting existing valid data.
- Migration Orchestration: Updates the version 5 migration map to execute these steps in the correct order: verify column -> populate data -> clean IDs.
Updates the `_cleanDirtyV4Accounts` migration logic to handle and repair accounts that do not match either the standard format or the known "bad" V4 format.

Key changes:
- Active Correction: Replaces the warning log for "unexpected formats" with an active migration to the standard `oldFormatId`.
- Integrity Protection: Before migrating an unexpected ID, the code checks for existing standard format IDs to prevent primary key conflicts.
- Data Preservation: If no conflict exists, it creates a corrected record with the standard ID while preserving all associated account data.
- Cleanup: Automatically deletes the record with the malformed/unexpected ID after the migration or conflict check is complete.
… formats

Implements a unified migration strategy (v7) for both iOS and Android platforms
to handle two divergent migration histories:

- AppKevin users (v6->v7): Had bad migrations in v5-v6 that created credentials
  with incorrect accountFactoryAddress values in the key format. Migration #7
  detects and cleans these dirty keys by reconstructing them with the correct
  accountFactoryAddress from getAccountFactoryAddressByAlias().

- AppOthers users (v4->v7): Skip empty migrations v5-v6 and migrate directly
  from old format (address@alias) to new format
  (address@accountFactoryAddress@alias) using the correct accountFactoryAddress.

Changes:
- Refactored key detection to categorize credentials into oldFormatKeys (2 parts)
  and dirtyNewFormatKeys (3 parts) for targeted handling
- Added AppKevin path: validates existing 3-part keys and recreates them with
  correct accountFactoryAddress if needed (case-insensitive comparison)
- Enhanced AppOthers path: migrates 2-part keys to 3-part format with proper
  accountFactoryAddress lookup
- Enabled deletion of old/dirty keys (removed TODO comments)
- Added comprehensive debug logging for migration tracking
- Implemented idempotent logic: keys already in correct format are skipped

Both user groups converge to the same final state at version 7 with credentials
in format: address@accountFactoryAddress@alias where accountFactoryAddress is
correctly determined by community alias.

Platforms: iOS (apple.dart), Android (android.dart)
@SajeeTechi SajeeTechi self-assigned this Dec 22, 2025
@SajeeTechi SajeeTechi merged commit 00b0258 into feat/account-factory-selection Dec 22, 2025
1 check failed
@SajeeTechi SajeeTechi deleted the fix/acc-factory-bad-migration branch December 22, 2025 11:25
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.

1 participant