@@ -157,12 +157,14 @@ const ROWS: ReadonlyArray<Record<string, unknown>> = [
157157const quiet = { info : ( ) => { } , warn : ( ) => { } } ;
158158
159159async function boot ( driver : SqlDriver , object : unknown , options : { deferDdl ?: boolean } = { } ) : Promise < ObjectQL > {
160+ // `os migrate plan` / `apply` boot with the deferral armed, on the driver
161+ // before the engine holds it (the CLI's `DeferSchemaDdlPlugin` arms a driver
162+ // ahead of `registerDriver`): the sync registers the metadata and records
163+ // the physical work instead of doing it.
164+ if ( options . deferDdl ) driver . setDeferredDdl ( true ) ;
160165 const engine = new ObjectQL ( ) ;
161166 engine . registerDriver ( driver , true ) ;
162167 await engine . init ( ) ;
163- // `os migrate plan` / `apply` boot with the deferral armed: the sync
164- // registers the metadata and records the physical work instead of doing it.
165- if ( options . deferDdl ) driver . setDeferredDdl ( true ) ;
166168 engine . registerApp ( appWith ( object ) ) ;
167169 await engine . syncSchemas ( ) ;
168170 await installDefaultOrganization ( engine ) ;
@@ -203,21 +205,33 @@ for (const cell of CELLS) {
203205 } ;
204206 }
205207
206- it ( 'the declared home field migrates through the ordinary add-column path, and no stored row moves' , async ( ) => {
207- // ── The upgrade boot, as `os migrate apply` runs it. ──
208+ // ── The upgrade boot, as `os migrate apply` runs it: the plan is read,
209+ // then the confirmed apply performs it. Read here, once, so each test
210+ // below stands alone. ──
211+ let plan : Awaited < ReturnType < SqlDriver [ 'previewDeferredSchemaWork' ] > > = [ ] ;
212+ let drift : Awaited < ReturnType < SqlDriver [ 'detectManagedDrift' ] > > = [ ] ;
213+ let performed : Awaited < ReturnType < SqlDriver [ 'flushDeferredSchemaDdl' ] > > = [ ] ;
214+ let planAfter : Awaited < ReturnType < SqlDriver [ 'previewDeferredSchemaWork' ] > > = [ ] ;
215+
216+ beforeAll ( async ( ) => {
208217 driver = cell . open ( ) ;
209218 engine = await boot ( driver , AFTER , { deferDdl : true } ) ;
219+ plan = await driver . previewDeferredSchemaWork ( ) ;
220+ drift = await driver . detectManagedDrift ( ) ;
221+ performed = await driver . flushDeferredSchemaDdl ( ) ;
222+ planAfter = await driver . previewDeferredSchemaWork ( ) ;
223+ } ) ;
210224
225+ it ( 'the declared home field migrates through the ordinary add-column path, and no stored row moves' , async ( ) => {
211226 // The plan: the two declared columns, as additive work; nothing rewrites a row.
212- const table = ( await driver . previewDeferredSchemaWork ( ) ) . filter ( ( w ) => w . table === OBJECT ) ;
227+ const table = plan . filter ( ( w ) => w . table === OBJECT ) ;
213228 expect ( table ) . toEqual ( [ { table : OBJECT , kind : 'add_columns' , columns : [ 'amount_home' , 'amount_rate' ] } ] ) ;
214- expect ( ( await driver . previewDeferredSchemaWork ( ) ) . filter ( ( w ) => w . table !== OBJECT ) ) . toEqual ( [ ] ) ;
215- expect ( ( await driver . detectManagedDrift ( ) ) . filter ( ( d ) => d . table === OBJECT ) ) . toEqual ( [ ] ) ;
229+ expect ( plan . filter ( ( w ) => w . table !== OBJECT ) ) . toEqual ( [ ] ) ;
230+ expect ( drift . filter ( ( d ) => d . table === OBJECT ) ) . toEqual ( [ ] ) ;
216231
217- // The confirmed apply.
218- const performed = await driver . flushDeferredSchemaDdl ( ) ;
232+ // The confirmed apply performed exactly that, and left nothing pending.
219233 expect ( performed . filter ( ( w ) => w . table === OBJECT ) ) . toEqual ( table ) ;
220- expect ( await driver . previewDeferredSchemaWork ( ) ) . toEqual ( [ ] ) ;
234+ expect ( planAfter ) . toEqual ( [ ] ) ;
221235
222236 // Every stored row is still there, as it was, with an empty home field.
223237 expect ( ( await engine . find ( OBJECT , { context : SYS . context } as never ) ) . length ) . toBe ( ROWS . length ) ;
0 commit comments