Skip to content
Merged
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
22 changes: 15 additions & 7 deletions framework/configstore/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ import (
// functions directly.
var testMigrationLogger = bifrost.NewDefaultLogger(schemas.LogLevelInfo)

// pgTestSchema is this package's dedicated Postgres schema. Test packages
// (configstore, configstore/tables, logstore) run in parallel against the same
// database, so each one works in its own schema to avoid clobbering the
// others' tables and rows.
const pgTestSchema = "configstore_test"

// postgresDSN matches the postgres service in tests/docker-compose.yml and
// framework/docker-compose.yml.
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable"
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable search_path=" + pgTestSchema

// namedDB pairs a backend name with its GORM connection for use in subtests.
type namedDB struct {
Expand Down Expand Up @@ -622,14 +628,17 @@ func trySetupPostgresDBWithoutStoreRawColumn(t *testing.T, testSuffix string) *g
return nil
}

// All objects live in this package's dedicated schema (via search_path in
// the DSN), isolated from other test packages sharing the same database.
Comment on lines 630 to +632

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Schema Failure Silently Skips Coverage

When PostgreSQL is reachable but the test role cannot create configstore_test, this new branch returns nil, and callers treat that as an unavailable database and skip the PostgreSQL cases. CI can therefore pass without running the affected migration tests instead of reporting the schema-permission error.

if err := db.Exec("CREATE SCHEMA IF NOT EXISTS " + pgTestSchema).Error; err != nil {
return nil
}

// Drop config_providers to start fresh (for this specific test).
// Use CASCADE to drop dependent objects (composite types, sequences, etc.).
db.Exec("DROP TABLE IF EXISTS config_providers CASCADE")

// Clear migration tracking without dropping the table — other test packages
// (e.g. logstore) may share this Postgres instance and use the same table
// concurrently. CREATE IF NOT EXISTS is safe even if the table already
// exists from a previous test or a concurrent package.
// Clear migration tracking so the migration under test always runs.
db.Exec(`CREATE TABLE IF NOT EXISTS migrations (
id VARCHAR(255) PRIMARY KEY
)`)
Expand Down Expand Up @@ -662,8 +671,7 @@ func trySetupPostgresDBWithoutStoreRawColumn(t *testing.T, testSuffix string) *g
return nil
}

// Clean up after the test — drop config_providers but leave migrations
// intact for concurrent test packages.
// Clean up after the test so later tests in this package start fresh.
t.Cleanup(func() {
db.Exec("DELETE FROM migrations")
db.Exec("DROP TABLE IF EXISTS config_providers CASCADE")
Expand Down
6 changes: 4 additions & 2 deletions framework/configstore/rdb_deadlock_postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,10 @@ func setupPostgresDeadlockStore(t *testing.T) *RDBConfigStore {
t.Skipf("postgres not available: %v", err)
}

require.NoError(t, db.Exec("DROP SCHEMA public CASCADE").Error)
require.NoError(t, db.Exec("CREATE SCHEMA public").Error)
// Reset only this package's schema — other test packages share the same
// database and must not lose their tables.
require.NoError(t, db.Exec("DROP SCHEMA IF EXISTS "+pgTestSchema+" CASCADE").Error)
require.NoError(t, db.Exec("CREATE SCHEMA "+pgTestSchema).Error)
require.NoError(t, triggerMigrations(context.Background(), db, testMigrationLogger))

store := &RDBConfigStore{logger: bifrost.NewDefaultLogger(schemas.LogLevelInfo)}
Expand Down
14 changes: 13 additions & 1 deletion framework/configstore/tables/encryption_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1546,9 +1546,15 @@ func TestTableVectorStoreConfig_EncryptionDisabled_StoresPlaintext(t *testing.T)
// Multi-backend helpers — run the same tests on SQLite and Postgres
// ============================================================================

// pgTestSchema is this package's dedicated Postgres schema. Test packages
// (configstore, configstore/tables, logstore) run in parallel against the same
// database, so each one works in its own schema to avoid clobbering the
// others' tables and rows.
const pgTestSchema = "configstore_tables_test"

// postgresDSN matches the postgres service in tests/docker-compose.yml and
// framework/docker-compose.yml.
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable"
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable search_path=" + pgTestSchema

// namedDB pairs a backend name with its GORM connection for use in subtests.
type namedDB struct {
Expand Down Expand Up @@ -1587,6 +1593,12 @@ func trySetupPostgresDB(t *testing.T) *gorm.DB {
return nil
}

// All objects live in this package's dedicated schema (via search_path in
// the DSN), isolated from other test packages sharing the same database.
if err := db.Exec("CREATE SCHEMA IF NOT EXISTS " + pgTestSchema).Error; err != nil {
return nil
}

// Order matters on Postgres: referenced tables must be created before
// tables that FK-reference them (SQLite defers FK checks; Postgres does not).
// TableProvider must precede TableKey (config_keys.provider_id → config_providers).
Expand Down
14 changes: 13 additions & 1 deletion framework/logstore/migrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,15 @@ import (
"gorm.io/gorm/logger"
)

// pgTestSchema is this package's dedicated Postgres schema. Test packages
// (configstore, configstore/tables, logstore) run in parallel against the same
// database, so each one works in its own schema to avoid clobbering the
// others' tables and rows.
const pgTestSchema = "logstore_test"

// postgresDSN matches the postgres service in tests/docker-compose.yml and
// framework/docker-compose.yml.
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable"
const postgresDSN = "host=localhost user=bifrost password=bifrost_password dbname=bifrost port=5432 sslmode=disable search_path=" + pgTestSchema

// trySetupPostgresDB attempts to connect to Postgres and returns the connection.
// Returns nil if Postgres is unavailable.
Expand All @@ -37,6 +43,12 @@ func trySetupPostgresDB(t *testing.T) *gorm.DB {
return nil
}

// All objects live in this package's dedicated schema (via search_path in
// the DSN), isolated from other test packages sharing the same database.
if err := db.Exec("CREATE SCHEMA IF NOT EXISTS " + pgTestSchema).Error; err != nil {
return nil
}

return db
}

Expand Down
Loading