@@ -517,3 +517,74 @@ async fn test_remove_tenants_migration_empty_db() {
517517 "key_id_gw default should be empty bytes on empty DB"
518518 ) ;
519519}
520+
521+ /// Verifies that testcontainers applies new migrations correctly.
522+ /// This test can be removed once CI migration validation is confirmed.
523+ #[ tokio:: test]
524+ async fn test_ci_migration_applied ( ) {
525+ let db = setup_test_db ( ImportMode :: None )
526+ . await
527+ . expect ( "setup test db" ) ;
528+ let pool = PgPool :: connect ( db. db_url ( ) ) . await . unwrap ( ) ;
529+
530+ // Verify ALTER TABLE added the column
531+ let column_exists: bool = sqlx:: query_scalar (
532+ "SELECT EXISTS (
533+ SELECT 1 FROM information_schema.columns
534+ WHERE table_name = 'ciphertexts128' AND column_name = 'ci_test_column'
535+ )" ,
536+ )
537+ . fetch_one ( & pool)
538+ . await
539+ . unwrap ( ) ;
540+ assert ! (
541+ column_exists,
542+ "ci_test_column should exist on ciphertexts128"
543+ ) ;
544+
545+ // Verify CREATE TABLE
546+ let table_exists: bool = sqlx:: query_scalar (
547+ "SELECT EXISTS (
548+ SELECT 1 FROM information_schema.tables
549+ WHERE table_name = 'ci_test_table'
550+ )" ,
551+ )
552+ . fetch_one ( & pool)
553+ . await
554+ . unwrap ( ) ;
555+ assert ! ( table_exists, "ci_test_table should exist" ) ;
556+
557+ // Verify INDEX was created
558+ let index_exists: bool = sqlx:: query_scalar (
559+ "SELECT EXISTS (
560+ SELECT 1 FROM pg_indexes
561+ WHERE indexname = 'idx_ci_test_table_name'
562+ )" ,
563+ )
564+ . fetch_one ( & pool)
565+ . await
566+ . unwrap ( ) ;
567+ assert ! ( index_exists, "idx_ci_test_table_name index should exist" ) ;
568+
569+ // Verify INSERT seeded data
570+ let row_count: i64 = sqlx:: query_scalar ( "SELECT COUNT(*) FROM ci_test_table" )
571+ . fetch_one ( & pool)
572+ . await
573+ . unwrap ( ) ;
574+ assert_eq ! ( row_count, 3 , "ci_test_table should have 3 seeded rows" ) ;
575+
576+ // Verify data integrity
577+ let sum: bigdecimal:: BigDecimal = sqlx:: query_scalar ( "SELECT SUM(value) FROM ci_test_table" )
578+ . fetch_one ( & pool)
579+ . await
580+ . unwrap ( ) ;
581+ assert_eq ! ( sum, 600 . into( ) , "sum of values should be 600" ) ;
582+
583+ // Verify JSONB column
584+ let ci_count: i64 =
585+ sqlx:: query_scalar ( "SELECT COUNT(*) FROM ci_test_table WHERE metadata->>'env' = 'ci'" )
586+ . fetch_one ( & pool)
587+ . await
588+ . unwrap ( ) ;
589+ assert_eq ! ( ci_count, 2 , "two rows should have env=ci in metadata" ) ;
590+ }
0 commit comments