Skip to content

fix(android): replace destructive Room migration with real migration scaffold + safety export - #15

Merged
Hidden-Node merged 4 commits into
mainfrom
advisor/003-room-migration-scaffold
Jul 19, 2026
Merged

fix(android): replace destructive Room migration with real migration scaffold + safety export#15
Hidden-Node merged 4 commits into
mainfrom
advisor/003-room-migration-scaffold

Conversation

@Hidden-Node

@Hidden-Node Hidden-Node commented Jul 19, 2026

Copy link
Copy Markdown
Owner

Problem

AppDatabase (v3) is built with fallbackToDestructiveMigration(). Any
future schema change — adding a column, renaming a field — silently deletes
every profile on the user's device. Each profile carries the tunnel_key
(AES-256-GCM), script_keys, socks_pass, and remoteUrl. Losing them
requires re-import, and losing the tunnel_key source locks the user out
of their VPN permanently.

What changed

  • AppDatabase.kt — flip exportSchema = true, replace
    fallbackToDestructiveMigration() with addMigrations(*ProfileMigrations.ALL).
    Missing migration now crashes instead of silently wiping data.
  • ProfileMigrations.kt (new) — SafetyExportMigration scaffold: reads
    all profile rows and writes a JSON snapshot to cacheDir before any
    schema change. If the export fails, Room throws IllegalStateException
    instead of proceeding with data loss. ALL = arrayOf() is empty until
    the first real v3→v4 migration is authored.
  • ProfileDao.kt — added getAllOnce() for non-flowing snapshot access.
  • build.gradle.ktsksp { arg("room.schemaLocation", ...) } for
    schema export, androidTestImplementation deps for future migration
    tests.
  • ProfilesViewModelParseTest.kt — override getAllOnce() in
    NoopProfileDao test fake (required after interface expansion).

Verification

  • :app:assembleDebug — CI green on push ✓
  • :app:testDebugUnitTest — CI green on push ✓
  • fallbackToDestructiveMigration grep on src/main/ → 0 matches ✓
  • Step 6 (androidTest migration test) skipped — no emulator available;
    deferred until emulator-backed CI is set up.

@Hidden-Node Hidden-Node changed the title Advisor/003 room migration scaffold fix(android): replace destructive Room migration with real migration scaffold + safety export Jul 19, 2026
@Hidden-Node
Hidden-Node merged commit bc00926 into main Jul 19, 2026
1 check passed
@Hidden-Node
Hidden-Node deleted the advisor/003-room-migration-scaffold branch July 19, 2026 07: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