@@ -37,6 +37,7 @@ import { PlatformObjectsPlugin } from '@objectstack/platform-objects/plugin';
3737import { AppPlugin } from './app-plugin.js' ;
3838import { DefaultDatasourcePlugin } from './default-datasource-plugin.js' ;
3939import { createDispatcherPlugin } from './dispatcher-plugin.js' ;
40+ import { relaxTenantColumns } from './pre-18-tenant-column.testkit.js' ;
4041
4142const BOOT_TIMEOUT = 180_000 ;
4243const ORIGIN = 'http://localhost:3000' ;
@@ -170,6 +171,10 @@ describe('[#24523] statements per warm request: an organization-owned admin gran
170171 } ) ;
171172
172173 it ( 'CONTROL — the organization-less grant: the same counts, on either slug' , async ( ) => {
174+ // An organization-less grant exists only on a store built before 18.x
175+ // (ADR-0131 D1 makes a fresh tenant column NOT NULL): this table is that
176+ // store's, relaxed through its driver's own drift apply door.
177+ await relaxTenantColumns ( ( engine as any ) . getDriver ( 'sys_user_permission_set' ) , [ 'sys_user_permission_set' ] ) ;
173178 const grant = await adminGrant ( ) ;
174179 const [ organization ] = await find ( 'sys_organization' ) ;
175180 await engine . update ( 'sys_user_permission_set' , { id : grant . id , organization_id : null } , { context : SYS } ) ;
@@ -188,6 +193,17 @@ describe('[#24523] statements per warm request: an organization-owned admin gran
188193
189194describe ( '[#24523 / #21868] a sys_organization write retires the memoised Default Organization' , ( ) => {
190195 it ( '⭐ the Default Organization deleted and recreated: the next request reads the new id' , async ( ) => {
196+ // Deleting an organization runs the engine's referential cascade, whose
197+ // `set_null` on every `organization_id` lookup a fresh, NOT NULL tenant
198+ // column refuses (ADR-0131 D1). This test's subject is the memo, not the
199+ // cascade, so the store is a pre-18 one: every tenant table it holds is
200+ // relaxed through its driver's own drift apply door.
201+ for ( const o of ( engine as any ) . registry . getAllObjects ( ) as Array < { name : string ; fields ?: Record < string , unknown > ; tenancy ?: { enabled ?: boolean } } > ) {
202+ if ( ! o . fields ?. organization_id || o . tenancy ?. enabled === false ) continue ;
203+ const driver = ( engine as any ) . getDriver ( o . name ) ;
204+ if ( ! ( await driver ?. knex ?. schema . hasTable ( o . name ) ) ) continue ;
205+ await relaxTenantColumns ( driver , [ o . name ] ) ;
206+ }
191207 const [ old ] = await find ( 'sys_organization' , { slug : 'default' } ) ;
192208 await standing ( ) ; // the control above wrote the organization: read it once
193209 expect ( await standing ( ) ) . toEqual ( { standing : true , organizationReads : 0 } ) ;
0 commit comments