package migrations import ( "os" "path/filepath" "strings" "testing" ) func TestDirectoryProfilesMigration(t *testing.T) { up, err := os.ReadFile(filepath.Join("000009_directory_profiles.up.sql")) if err != nil { t.Fatalf("read up migration: %v", err) } down, err := os.ReadFile(filepath.Join("000009_directory_profiles.down.sql")) if err != nil { t.Fatalf("read down migration: %v", err) } upper := strings.ToUpper(string(up)) for _, required := range []string{ "CREATE TABLE IF NOT EXISTS DIRECTORY_PROFILES", "PRIMARY KEY (TENANT_KEY, STAFF_ID)", "DEPARTMENT_IDS JSONB", "REGION TEXT", "SOURCE TEXT", "ADD COLUMN IF NOT EXISTS DEPARTMENT_SNAPSHOT", "ADD COLUMN IF NOT EXISTS REGION_SNAPSHOT", } { if !strings.Contains(upper, required) { t.Errorf("up migration missing %q", required) } } for _, forbidden := range []string{"MOBILE", "EMAIL", "CLIENT_SECRET", "ACCESS_TOKEN", "RAW_PAYLOAD"} { if strings.Contains(upper, forbidden) { t.Errorf("up migration contains forbidden sensitive field %q", forbidden) } } downUpper := strings.ToUpper(string(down)) if !strings.Contains(downUpper, "DROP TABLE IF EXISTS DIRECTORY_PROFILES") || !strings.Contains(downUpper, "DROP COLUMN IF EXISTS REGION_SNAPSHOT") { t.Error("down migration must remove directory table and snapshot columns") } }