26 lines
726 B
Go
26 lines
726 B
Go
package db
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestAuditMigrationSafety(t *testing.T) {
|
|
b, err := os.ReadFile("/opt/ai-operator/migrations/003_audit_tables.sql")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
s := strings.ToUpper(string(b))
|
|
for _, bad := range []string{"DROP TABLE", "DROP DATABASE", "TRUNCATE", "DELETE FROM"} {
|
|
if strings.Contains(s, bad) {
|
|
t.Fatalf("migration contains destructive SQL: %s", bad)
|
|
}
|
|
}
|
|
for _, table := range []string{"ai_calls", "ai_call_events", "ai_transcript_events", "ai_tool_audit", "ai_kb_audit", "ai_handoff_audit", "ai_provider_audit", "ai_media_audit", "ai_audit_retention_runs"} {
|
|
if !strings.Contains(string(b), table) {
|
|
t.Fatalf("missing table %s", table)
|
|
}
|
|
}
|
|
}
|