@@ -705,9 +705,12 @@ mod postgres_tests {
705705 let mut migrations: Vec < _ > = MIGRATOR . iter ( ) . collect ( ) ;
706706 migrations. sort_by_key ( |migration| migration. version ) ;
707707
708- assert_eq ! ( migrations. len( ) , 52 ) ;
708+ assert_eq ! ( migrations. len( ) , 53 ) ;
709709 assert_eq ! ( migrations[ 48 ] . version, 49 ) ;
710+ assert_eq ! ( migrations[ 49 ] . version, 50 ) ;
710711 assert_eq ! ( migrations[ 50 ] . version, 51 ) ;
712+ assert_eq ! ( migrations[ 51 ] . version, 52 ) ;
713+ assert_eq ! ( migrations[ 52 ] . version, 53 ) ;
711714 assert ! ( migrations[ 48 ]
712715 . sql
713716 . as_str( )
@@ -716,6 +719,11 @@ mod postgres_tests {
716719 . sql
717720 . as_str( )
718721 . contains( "community_deletion_owner_provenance" ) ) ;
722+ assert ! ( migrations[ 52 ] . sql. as_str( ) . contains( "approval_origin" ) ) ;
723+ assert ! ( migrations[ 52 ]
724+ . sql
725+ . as_str( )
726+ . contains( "community_deletion_requests_owner_preparable" ) ) ;
719727 assert_eq ! ( migrations[ 0 ] . version, 1 ) ;
720728 assert_eq ! ( & * migrations[ 0 ] . description, "initial schema" ) ;
721729 assert ! ( migrations[ 0 ]
@@ -1722,6 +1730,34 @@ mod postgres_tests {
17221730 ) ;
17231731 }
17241732
1733+ #[ test]
1734+ fn owner_deletion_auto_approval_migration_matches_desired_schema ( ) {
1735+ let migration = MIGRATOR
1736+ . iter ( )
1737+ . find ( |migration| migration. version == 53 )
1738+ . expect ( "embedded migration 0053" )
1739+ . sql
1740+ . as_ref ( )
1741+ . to_ascii_lowercase ( ) ;
1742+ let workspace_root = std:: path:: Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
1743+ . parent ( )
1744+ . and_then ( std:: path:: Path :: parent)
1745+ . expect ( "workspace root" ) ;
1746+ let schema = std:: fs:: read_to_string ( workspace_root. join ( "schema/schema.sql" ) )
1747+ . expect ( "read schema/schema.sql" )
1748+ . to_ascii_lowercase ( ) ;
1749+
1750+ for sql in [ & migration, & schema] {
1751+ assert ! ( sql. contains( "approval_origin text not null default 'operator'" ) ) ;
1752+ assert ! ( sql. contains( "approval_origin in ('operator', 'owner_automatic')" ) ) ;
1753+ assert ! ( sql. contains( "'submitted', 'approved', 'fenced'" ) ) ;
1754+ assert ! ( sql. contains( "community_deletion_requests_owner_preparable" ) ) ;
1755+ assert ! ( sql. contains( "request_origin = 'owner'" ) ) ;
1756+ assert ! ( sql. contains( "stage = 'submitted'" ) ) ;
1757+ }
1758+ assert ! ( migration. contains( "set local lock_timeout = '5s'" ) ) ;
1759+ }
1760+
17251761 /// Structural parity between migration 0029's deletion surface and the
17261762 /// desired-state bootstrap schema (`schema/schema.sql`).
17271763 ///
@@ -1866,13 +1902,50 @@ mod postgres_tests {
18661902 . tables
18671903 . get ( table)
18681904 . unwrap_or_else ( || panic ! ( "schema.sql is missing deletion table {table}" ) ) ;
1869- if table != "community_deletion_requests" {
1905+ if table != "community_deletion_requests" && table != "community_deletion_approvals" {
18701906 assert_eq ! (
18711907 in_schema, definition,
18721908 "schema.sql definition of {table} drifted from migration 0029"
18731909 ) ;
18741910 }
18751911 }
1912+ let migration_approval_table = migration
1913+ . tables
1914+ . get ( "community_deletion_approvals" )
1915+ . expect ( "0029 approval table" ) ;
1916+ let schema_approval_table = schema
1917+ . tables
1918+ . get ( "community_deletion_approvals" )
1919+ . expect ( "schema.sql approval table" ) ;
1920+ for invariant in [
1921+ "inventory_digest bytea not null check (length(inventory_digest) = 32)" ,
1922+ "foreign key (request_id, community_id, inventory_digest) references community_deletion_requests(id, community_id, inventory_digest) on delete restrict" ,
1923+ ] {
1924+ assert ! (
1925+ migration_approval_table. contains( invariant) ,
1926+ "0029 deletion approvals are missing {invariant}"
1927+ ) ;
1928+ assert ! (
1929+ schema_approval_table. contains( invariant) ,
1930+ "schema.sql deletion approvals are missing {invariant}"
1931+ ) ;
1932+ }
1933+ let migration_request_table = migration
1934+ . tables
1935+ . get ( "community_deletion_requests" )
1936+ . expect ( "0029 deletion request table" ) ;
1937+ for request_table in [
1938+ migration_request_table,
1939+ schema
1940+ . tables
1941+ . get ( "community_deletion_requests" )
1942+ . expect ( "schema.sql deletion request table" ) ,
1943+ ] {
1944+ assert ! (
1945+ request_table. contains( "unique (id, community_id, inventory_digest)" ) ,
1946+ "deletion requests must expose the exact composite approval target"
1947+ ) ;
1948+ }
18761949 for ( function, definition) in & migration. functions {
18771950 let in_schema = schema
18781951 . functions
0 commit comments