History

Remove double-probe from v1-v2 migration

Griffin Evans committed 4 months ago

Commit c26fb421 parent a7f69391 file · +6 −18Browse files

Unified · Split

apps/local/src/db/v1-v2-migration.ts+6−18
@@ -1343,16 +1343,16 @@ export const migrateLocalV1ToV2IfNeeded = async ( · 1342 unmodified lines
13431343
13441344 if (!fs.existsSync(options.sqlitePath)) return { migrated: false, warnings: [] };
13451345
1346− // Fast steady-state probe: migrated v2 databases short-circuit on their ledger
1347− // stamp without copying the whole DB. The caller holds the data-dir ownership
1348− // lock, so this process is the sole writer; any ambiguous shape decision
1349− // happens below.
1350− let probe: Client | null = await openLocalLibsql(options.sqlitePath);
1346+ // The caller holds the data-dir ownership lock, so this process is the sole
1347+ // writer and recovery already ran above. A single probe decides the outcome:
1348+ // already-migrated databases short-circuit on their ledger stamp, and only an
1349+ // actual v1 database falls through to the heavy copy/stage/flip path below.
1350+ const probe: Client = await openLocalLibsql(options.sqlitePath);
13511351 try {
13521352 if (await hasV1GateStamp(probe)) return { migrated: false, warnings: [] };
1353+ if (!(await isLocalV1Database(probe))) return { migrated: false, warnings: [] };
13531354 } finally {
13541355 probe.close();
1355− probe = null;
13561356 }
13571357
13581358 let normalizedSourcePath: string | null = null;
@@ -1364,18 +1364,6 @@ export const migrateLocalV1ToV2IfNeeded = async ( · 5 unmodified lines
13641364 let flipStarted = false;
13651365
13661366 try {
1367− await recoverV1V2Migration(options.sqlitePath);
1368− if (!fs.existsSync(options.sqlitePath)) return { migrated: false, warnings: [] };
1369−
1370− probe = await openLocalLibsql(options.sqlitePath);
1371− try {
1372− if (await hasV1GateStamp(probe)) return { migrated: false, warnings: [] };
1373− if (!(await isLocalV1Database(probe))) return { migrated: false, warnings: [] };
1374− } finally {
1375− probe.close();
1376− probe = null;
1377− }
1378−
13791367 const nonce = randomBytes(4).toString("hex");
13801368 normalizedSourcePath = normalizedSourcePathFor(options.sqlitePath, nonce);
13811369 stagingPath = stagingPathFor(options.sqlitePath, nonce);