@@ -12010,13 +12010,6 @@ static bool adr_migrated(sqlite3 *adb) {
1201012010 return done ;
1201112011}
1201212012
12013- /* Copy any legacy ADR rows from the graph DB's project_summaries into the
12014- * sidecar (INSERT OR IGNORE, so a local row is never clobbered), then set the
12015- * one-time marker. The marker check, copy and marker insert run in ONE
12016- * BEGIN IMMEDIATE transaction on the sidecar, so two processes migrating at
12017- * once cannot re-copy a row the other just deleted. Returns CBM_STORE_ERR on
12018- * any failure (transaction rolled back) so callers can fail closed and preserve
12019- * the old generation. No-op once the marker is set. */
1202012013/* Copy every ADR row from the graph DB's project_summaries into the sidecar with
1202112014 * INSERT OR IGNORE (so a row already present locally is never overwritten). Must
1202212015 * run inside a transaction on the sidecar connection. Returns OK/ERR; does not
@@ -12070,6 +12063,13 @@ static int adr_copy_rows(cbm_store_t *s, sqlite3 *adb) {
1207012063 return (rc == SQLITE_DONE ) ? CBM_STORE_OK : CBM_STORE_ERR ;
1207112064}
1207212065
12066+ /* Copy any legacy ADR rows from the graph DB's project_summaries into the
12067+ * sidecar (INSERT OR IGNORE, so a local row is never clobbered), then set the
12068+ * one-time marker. The marker check, copy and marker insert run in ONE
12069+ * BEGIN IMMEDIATE transaction on the sidecar, so two processes migrating at
12070+ * once cannot re-copy a row the other just deleted. Returns CBM_STORE_ERR on
12071+ * any failure (transaction rolled back) so callers can fail closed and preserve
12072+ * the old generation. No-op once the marker is set. */
1207312073static int adr_copy_legacy_once (cbm_store_t * s , sqlite3 * adb ) {
1207412074 if (adr_migrated (adb )) {
1207512075 return CBM_STORE_OK ; /* fast path: already migrated, no lock needed */
@@ -12106,19 +12106,22 @@ static int adr_copy_legacy_once(cbm_store_t *s, sqlite3 *adb) {
1210612106 * DB's project_summaries, and a teammate who already indexed the project (so the
1210712107 * sidecar is marked, but has no ADR) must still receive it. INSERT OR IGNORE
1210812108 * guarantees a local ADR is never clobbered; running ungated by the marker is
12109- * what distinguishes this from the one-time legacy migration. */
12109+ * what distinguishes this from the one-time legacy migration. It never writes
12110+ * the marker: `adb` comes from adr_conn_write, which hands out a sidecar handle
12111+ * only after adr_copy_legacy_once committed it, and nothing deletes it. On
12112+ * failure the store error names the step (the import logs it). */
1211012113static int adr_restore_if_absent (cbm_store_t * s , sqlite3 * adb ) {
1211112114 if (sqlite3_exec (adb , "BEGIN IMMEDIATE;" , NULL , NULL , NULL ) != SQLITE_OK ) {
12115+ store_set_error_sqlite_on (s , adb , "adr restore begin" );
1211212116 return CBM_STORE_ERR ;
1211312117 }
1211412118 if (adr_copy_rows (s , adb ) != CBM_STORE_OK ) {
12119+ store_set_error (s , "adr restore copy failed" );
1211512120 (void )sqlite3_exec (adb , "ROLLBACK;" , NULL , NULL , NULL );
1211612121 return CBM_STORE_ERR ;
1211712122 }
12118- /* Mark migrated too, so a later reindex's before-delete migration is a no-op. */
12119- (void )sqlite3_exec (adb , "INSERT OR IGNORE INTO adr_meta (key, value) VALUES ('migrated','1');" ,
12120- NULL , NULL , NULL );
1212112123 if (sqlite3_exec (adb , "COMMIT;" , NULL , NULL , NULL ) != SQLITE_OK ) {
12124+ store_set_error_sqlite_on (s , adb , "adr restore commit" );
1212212125 (void )sqlite3_exec (adb , "ROLLBACK;" , NULL , NULL , NULL );
1212312126 return CBM_STORE_ERR ;
1212412127 }
0 commit comments