Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- CI validation migration: proves testcontainers applies new migrations correctly.
-- Remove this migration and its test before merging.

ALTER TABLE ciphertexts128 ADD COLUMN ci_test_column BOOLEAN DEFAULT NULL;

CREATE TABLE ci_test_table (
id SERIAL PRIMARY KEY,
name TEXT NOT NULL UNIQUE,
value BIGINT NOT NULL DEFAULT 0,
metadata JSONB,
created_at TIMESTAMP NOT NULL DEFAULT NOW()
);

CREATE INDEX idx_ci_test_table_name ON ci_test_table (name);

INSERT INTO ci_test_table (name, value, metadata) VALUES
('alpha', 100, '{"env": "ci"}'),
('beta', 200, '{"env": "ci"}'),
('gamma', 300, NULL);
71 changes: 71 additions & 0 deletions coprocessor/fhevm-engine/tfhe-worker/src/tests/migrations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,3 +517,74 @@ async fn test_remove_tenants_migration_empty_db() {
"key_id_gw default should be empty bytes on empty DB"
);
}

/// Verifies that testcontainers applies new migrations correctly.
/// This test can be removed once CI migration validation is confirmed.
#[tokio::test]
async fn test_ci_migration_applied() {
let db = setup_test_db(ImportMode::None)
.await
.expect("setup test db");
let pool = PgPool::connect(db.db_url()).await.unwrap();

// Verify ALTER TABLE added the column
let column_exists: bool = sqlx::query_scalar(
"SELECT EXISTS (
SELECT 1 FROM information_schema.columns
WHERE table_name = 'ciphertexts128' AND column_name = 'ci_test_column'
)",
)
.fetch_one(&pool)
.await
.unwrap();
assert!(
column_exists,
"ci_test_column should exist on ciphertexts128"
);

// Verify CREATE TABLE
let table_exists: bool = sqlx::query_scalar(
"SELECT EXISTS (
SELECT 1 FROM information_schema.tables
WHERE table_name = 'ci_test_table'
)",
)
.fetch_one(&pool)
.await
.unwrap();
assert!(table_exists, "ci_test_table should exist");

// Verify INDEX was created
let index_exists: bool = sqlx::query_scalar(
"SELECT EXISTS (
SELECT 1 FROM pg_indexes
WHERE indexname = 'idx_ci_test_table_name'
)",
)
.fetch_one(&pool)
.await
.unwrap();
assert!(index_exists, "idx_ci_test_table_name index should exist");

// Verify INSERT seeded data
let row_count: i64 = sqlx::query_scalar("SELECT COUNT(*) FROM ci_test_table")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(row_count, 3, "ci_test_table should have 3 seeded rows");

// Verify data integrity
let sum: bigdecimal::BigDecimal = sqlx::query_scalar("SELECT SUM(value) FROM ci_test_table")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(sum, 600.into(), "sum of values should be 600");

// Verify JSONB column
let ci_count: i64 =
sqlx::query_scalar("SELECT COUNT(*) FROM ci_test_table WHERE metadata->>'env' = 'ci'")
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(ci_count, 2, "two rows should have env=ci in metadata");
}
Loading