Skip to content

Commit 3c1a6c4

Browse files
committed
add test migration
1 parent bd5e074 commit 3c1a6c4

File tree

2 files changed

+90
-0
lines changed

2 files changed

+90
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
-- CI validation migration: proves testcontainers applies new migrations correctly.
2+
-- Remove this migration and its test before merging.
3+
4+
ALTER TABLE ciphertexts128 ADD COLUMN ci_test_column BOOLEAN DEFAULT NULL;
5+
6+
CREATE TABLE ci_test_table (
7+
id SERIAL PRIMARY KEY,
8+
name TEXT NOT NULL UNIQUE,
9+
value BIGINT NOT NULL DEFAULT 0,
10+
metadata JSONB,
11+
created_at TIMESTAMP NOT NULL DEFAULT NOW()
12+
);
13+
14+
CREATE INDEX idx_ci_test_table_name ON ci_test_table (name);
15+
16+
INSERT INTO ci_test_table (name, value, metadata) VALUES
17+
('alpha', 100, '{"env": "ci"}'),
18+
('beta', 200, '{"env": "ci"}'),
19+
('gamma', 300, NULL);

coprocessor/fhevm-engine/tfhe-worker/src/tests/migrations.rs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)