@@ -42,6 +42,11 @@ const STATE_V5_ADDITIVE_TABLES = [
4242 "worker_transcript_commits" ,
4343 ...STATE_V6_ADDITIVE_TABLES ,
4444] as const ;
45+ const STATE_MIGRATION_ALLOWED_MISSING_TABLES = {
46+ 5 : STATE_V5_ADDITIVE_TABLES ,
47+ 6 : STATE_V6_ADDITIVE_TABLES ,
48+ } as const satisfies Record < number , readonly string [ ] > ;
49+ type OpenClawStateMigrationVersion = keyof typeof STATE_MIGRATION_ALLOWED_MISSING_TABLES ;
4550
4651/** Open shared SQLite database handle plus WAL maintenance lifecycle. */
4752
@@ -133,7 +138,7 @@ export function assertOpenClawStateDatabaseForMaintenance(
133138
134139function assertOpenClawStateDatabaseVersionForMigration (
135140 database : DatabaseSync ,
136- options : { pathname : string ; version : number ; allowedMissingTables : readonly string [ ] } ,
141+ options : { pathname : string ; version : OpenClawStateMigrationVersion } ,
137142) : void {
138143 const userVersion = readSqliteUserVersion ( database ) ;
139144 if ( userVersion !== options . version ) {
@@ -153,7 +158,7 @@ function assertOpenClawStateDatabaseVersionForMigration(
153158 ) ;
154159 }
155160 assertSqliteSchemaTablesPresent ( database , options . pathname , OPENCLAW_STATE_SCHEMA_SQL , {
156- allowedMissingTables : options . allowedMissingTables ,
161+ allowedMissingTables : STATE_MIGRATION_ALLOWED_MISSING_TABLES [ options . version ] ,
157162 } ) ;
158163}
159164
@@ -162,23 +167,15 @@ export function assertOpenClawStateDatabaseV5ForMigration(
162167 database : DatabaseSync ,
163168 options : { pathname : string } ,
164169) : void {
165- assertOpenClawStateDatabaseVersionForMigration ( database , {
166- ...options ,
167- version : 5 ,
168- allowedMissingTables : STATE_V5_ADDITIVE_TABLES ,
169- } ) ;
170+ assertOpenClawStateDatabaseVersionForMigration ( database , { ...options , version : 5 } ) ;
170171}
171172
172173/** Require every stable v6 table before the v7 retirement migration can run. */
173174export function assertOpenClawStateDatabaseV6ForMigration (
174175 database : DatabaseSync ,
175176 options : { pathname : string } ,
176177) : void {
177- assertOpenClawStateDatabaseVersionForMigration ( database , {
178- ...options ,
179- version : 6 ,
180- allowedMissingTables : STATE_V6_ADDITIVE_TABLES ,
181- } ) ;
178+ assertOpenClawStateDatabaseVersionForMigration ( database , { ...options , version : 6 } ) ;
182179}
183180
184181export function resolveDatabasePath ( options : OpenClawStateDatabaseOptions = { } ) : string {
0 commit comments