- Fix migration 024 self-insert and bad column reference (F-B1-1, F-B1-2) Uses existing enabled/auto_run columns instead of non-existent deprecated - Abort server on migration failure instead of warning (F-B1-11) main.go now calls log.Fatalf, prints [INFO] only on success - Fix migration 018 scanner_config filename suffix (F-B1-3) Renumbered to 027 with .up.sql suffix - Remove GRANT to non-existent role in scanner_config (F-B1-4) - Resolve duplicate migration numbers 009 and 012 (F-B1-13) Renamed to 009b and 012b for unique lexical sorting - Add IF NOT EXISTS to all non-idempotent migrations (F-B1-15) Fixed: 011, 012, 017, 023, 023a - Replace N+1 dashboard stats loop with GetAllUpdateStats (F-B1-6) Single aggregate query replaces per-agent loop - Add composite index on agent_commands(status, sent_at) (F-B1-5) New migration 028 with partial index for timeout service - Add background refresh token cleanup goroutine (F-B1-10) 24-hour ticker calls CleanupExpiredTokens - ETHOS log format in migration runner (no emojis) All 55 tests pass (41 server + 14 agent). No regressions. See docs/B1_Fix_Implementation.md and DEV-025 through DEV-028. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
68 lines
2.1 KiB
Go
68 lines
2.1 KiB
Go
package migrations_test
|
|
|
|
// migration018_test.go — Tests for scanner_config migration fixes.
|
|
//
|
|
// F-B1-3 FIXED: Renamed from 018_create_scanner_config_table.sql (no .up.sql suffix)
|
|
// to 027_create_scanner_config_table.up.sql (correct suffix, unique number).
|
|
//
|
|
// F-B1-4 FIXED: GRANT to non-existent role `redflag_user` removed.
|
|
|
|
import (
|
|
"os"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestMigration018ScannerConfigHasWrongSuffix(t *testing.T) {
|
|
// POST-FIX: old .sql file must be gone, new .up.sql must exist
|
|
files, err := os.ReadDir(".")
|
|
if err != nil {
|
|
t.Fatalf("failed to read migrations directory: %v", err)
|
|
}
|
|
|
|
for _, f := range files {
|
|
if f.Name() == "018_create_scanner_config_table.sql" {
|
|
t.Error("[ERROR] [server] [database] F-B1-3 NOT FIXED: old .sql file still exists")
|
|
return
|
|
}
|
|
}
|
|
t.Log("[INFO] [server] [database] F-B1-3 FIXED: old 018_create_scanner_config_table.sql removed")
|
|
}
|
|
|
|
func TestMigration018ScannerConfigHasCorrectSuffix(t *testing.T) {
|
|
// POST-FIX: scanner_config migration must exist with .up.sql suffix
|
|
// (renumbered to 027)
|
|
files, err := os.ReadDir(".")
|
|
if err != nil {
|
|
t.Fatalf("failed to read migrations directory: %v", err)
|
|
}
|
|
|
|
found := false
|
|
for _, f := range files {
|
|
if f.Name() == "027_create_scanner_config_table.up.sql" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
|
|
if !found {
|
|
t.Errorf("[ERROR] [server] [database] 027_create_scanner_config_table.up.sql not found.\n" +
|
|
"F-B1-3: scanner_config migration must have .up.sql suffix.")
|
|
}
|
|
t.Log("[INFO] [server] [database] F-B1-3 FIXED: scanner_config migration has correct suffix (027)")
|
|
}
|
|
|
|
func TestMigration018ScannerConfigHasNoGrantToWrongRole(t *testing.T) {
|
|
// POST-FIX: no GRANT to redflag_user in the scanner_config migration
|
|
content, err := os.ReadFile("027_create_scanner_config_table.up.sql")
|
|
if err != nil {
|
|
t.Fatalf("failed to read scanner_config migration: %v", err)
|
|
}
|
|
|
|
if strings.Contains(string(content), "redflag_user") {
|
|
t.Errorf("[ERROR] [server] [database] scanner_config migration GRANTs to non-existent role.\n" +
|
|
"F-B1-4: GRANT to redflag_user must be removed.")
|
|
}
|
|
t.Log("[INFO] [server] [database] F-B1-4 FIXED: no GRANT to wrong role")
|
|
}
|