chore(state-store): remove the one-time SQLite import and db_path
Every install serves from Postgres, so the legacyread/legacyimport packages, the archie-state-store import command, the boot gate that refused to serve over unimported SQLite files, and db_path (which only located those files) go. Migration 0010 drops the import_completion table.
This commit is contained in:
1 parent
d61e49b2c9
commit
8c55b5d4e4
65 files changed
+138
-3350
No files matched your search
@@ -38,7 +38,6 @@ var deletionGate = []bannedCategory{
|
||||
"modernc.org/sqlite",
|
||||
"github.com/jackc/pgx",
|
||||
modulePath + "internal/infrastructure/postgres",
|
||||
modulePath + "internal/infrastructure/legacyread",
|
||||
}},
|
||||
{"daemon runtime", []string{
|
||||
modulePath + "internal/daemon",
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/legacyimport/legacyfixture"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres"
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
|
||||
|
||||
// TestRecoveryImportMovesTheInstallOnce drives the import the way an operator
|
||||
// does: the configured db_path locates every legacy file, and a second run
|
||||
// against the same database is refused because the first one completed.
|
||||
func TestRecoveryImportMovesTheInstallOnce(t *testing.T) {
|
||||
dbPath := filepath.Join(t.TempDir(), "archie.db")
|
||||
legacyfixture.Install(t, dbPath)
|
||||
url := pgtest.URL(t)
|
||||
|
||||
code, stdout, stderr := runRecoveryCmd(t, "import", "-db-path", dbPath, "-database-url", url)
|
||||
if code != 0 {
|
||||
t.Fatalf("import exited %d; stderr = %q", code, stderr)
|
||||
}
|
||||
if !strings.Contains(stdout, "tasks=2") {
|
||||
t.Errorf("import summary %q does not report the imported task", stdout)
|
||||
}
|
||||
|
||||
pool, err := postgres.Open(t.Context(), url)
|
||||
if err != nil {
|
||||
t.Fatalf("postgres.Open: %v", err)
|
||||
}
|
||||
defer pool.Close()
|
||||
var issue int64
|
||||
if err := pool.QueryRow(t.Context(), "SELECT issue_number FROM tasks WHERE id = 1").Scan(&issue); err != nil || issue != 7 {
|
||||
t.Fatalf("imported task 1 issue = %d, %v; want 7", issue, err)
|
||||
}
|
||||
|
||||
code, _, stderr = runRecoveryCmd(t, "import", "-db-path", dbPath, "-database-url", url)
|
||||
if code != 1 || !strings.Contains(stderr, "already holds a completed import") {
|
||||
t.Fatalf("second import exited %d, stderr %q; want 1 naming the completed import", code, stderr)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/infrastructure/postgres/pgtest"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) { os.Exit(pgtest.Main(m)) }
|
||||
@@ -89,7 +89,7 @@ func buildBinary(t *testing.T, dir string) string {
|
||||
// while keeping the process minimal: the standalone binary takes its gRPC
|
||||
// listen address from -listen or [services.state].listen, never from the
|
||||
// target, so the config only needs the fields validation requires plus the
|
||||
// db_path and database_url it owns. The
|
||||
// database_url it owns. The
|
||||
// forge token resolves from an env var, so no real credential is needed.
|
||||
func writeMinimalConfig(t *testing.T, dir string) string {
|
||||
t.Helper()
|
||||
@@ -101,7 +101,6 @@ func writeConfigFor(t *testing.T, dir, url string) string {
|
||||
t.Helper()
|
||||
cfg := filepath.Join(dir, "config.toml")
|
||||
content := fmt.Sprintf(`bot_user = "archie-bot"
|
||||
db_path = %q
|
||||
database_url = %q
|
||||
[forge]
|
||||
type = "github"
|
||||
@@ -110,7 +109,7 @@ token = { engine = "env", key = "ARCHIE_GITHUB_TOKEN" }
|
||||
[[repos]]
|
||||
owner = "acme"
|
||||
name = "widget"
|
||||
`, filepath.Join(dir, "archie.db"), url)
|
||||
`, url)
|
||||
if err := os.WriteFile(cfg, []byte(content), 0o600); err != nil {
|
||||
t.Fatalf("write config: %v", err)
|
||||
}
|
||||
@@ -437,7 +436,7 @@ func TestStateStoreRealProcessSmoke(t *testing.T) {
|
||||
|
||||
t.Run("serves_from_postgres_only", func(t *testing.T) {
|
||||
// The binary serves every store from database_url: no SQLite file
|
||||
// appears beside the configured db_path.
|
||||
// appears in its directory.
|
||||
for _, name := range []string{"archie.db", "archie.db-tasks.sqlite", "archie.db-eda.sqlite"} {
|
||||
if _, err := os.Stat(filepath.Join(dir, name)); err == nil {
|
||||
t.Fatalf("state store created %s; it serves from Postgres only", name)
|
||||
@@ -472,7 +471,7 @@ func TestStateStoreRealProcessDeadline(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestStateStoreRealProcessRestartRecovery starts the process, writes a task,
|
||||
// stops it (SIGTERM), restarts it on the same config/db_path, and verifies the
|
||||
// stops it (SIGTERM), restarts it on the same config, and verifies the
|
||||
// task and its events were recovered from the on-disk SQLite -- the
|
||||
// restart/recovery path the runbook relies on when archie-state-store is
|
||||
// restarted as a service.
|
||||
|
||||
@@ -37,9 +37,6 @@ snapshot taken before it.
|
||||
the configuration the daemon would boot with
|
||||
rollback -kind KIND replay an earlier revision of a stored
|
||||
[-revision N] resource through the ordinary replace
|
||||
import [-db-path PATH] copy the legacy SQLite stores named from
|
||||
[-database-url URL] db_path into an empty Postgres database,
|
||||
once; refuses while any Archie service runs
|
||||
|
||||
Every command takes -config FILE and -config-overlay FILE: the configuration
|
||||
the daemon boots with, which names the database.
|
||||
@@ -56,8 +53,7 @@ func runRecovery(args []string, stdout, stderr io.Writer) int {
|
||||
command := args[0]
|
||||
options := archied.StateStoreRecoveryOptions{Operation: command}
|
||||
switch command {
|
||||
case archied.RecoveryBackup, archied.RecoveryRestore, archied.RecoveryValidate, archied.RecoveryRollback,
|
||||
archied.RecoveryImport:
|
||||
case archied.RecoveryBackup, archied.RecoveryRestore, archied.RecoveryValidate, archied.RecoveryRollback:
|
||||
default:
|
||||
fmt.Fprintf(stderr, "archie-state-store: unknown command %q\n\n", command)
|
||||
fmt.Fprint(stderr, recoveryUsage)
|
||||
@@ -71,10 +67,6 @@ func runRecovery(args []string, stdout, stderr io.Writer) int {
|
||||
flags.StringVar(&options.From, "from", "", "snapshot file restore reads")
|
||||
flags.StringVar(&options.Kind, "kind", "", "control-plane resource kind rollback replays")
|
||||
flags.Int64Var(&options.Revision, "revision", 0, "revision rollback replays (default: the newest one older than the current value)")
|
||||
if command == archied.RecoveryImport {
|
||||
flags.StringVar(&options.DBPath, "db-path", "", "configured db_path the legacy files are named from (default: the configuration's)")
|
||||
flags.StringVar(&options.DatabaseURL, "database-url", "", "Postgres URL to import into (default: the configuration's database_url)")
|
||||
}
|
||||
// The configuration names the PostgreSQL database, and validate also checks
|
||||
// the stored settings against it.
|
||||
flags.StringVar(&options.Config, "config", configuration.DefaultConfigPath(), "configuration file or directory the daemon boots with")
|
||||
|
||||
@@ -145,7 +145,7 @@ func TestRecoveryValidateAcceptsAnUnseededDatabase(t *testing.T) {
|
||||
// path in the same binary exits 0 for the same request, so a script probing the
|
||||
// recovery surface must not read a requested help as a failure.
|
||||
func TestRecoveryHelpExitsZero(t *testing.T) {
|
||||
commands := []string{archied.RecoveryBackup, archied.RecoveryRestore, archied.RecoveryValidate, archied.RecoveryRollback, archied.RecoveryImport}
|
||||
commands := []string{archied.RecoveryBackup, archied.RecoveryRestore, archied.RecoveryValidate, archied.RecoveryRollback}
|
||||
for _, command := range commands {
|
||||
code, _, stderr := runRecoveryCmd(t, command, "-h")
|
||||
if code != 0 {
|
||||
|
||||
@@ -30,7 +30,6 @@ var deletionGate = []bannedCategory{
|
||||
"modernc.org/sqlite",
|
||||
"github.com/jackc/pgx",
|
||||
modulePath + "internal/infrastructure/postgres",
|
||||
modulePath + "internal/infrastructure/legacyread",
|
||||
}},
|
||||
{"daemon runtime", []string{
|
||||
modulePath + "internal/daemon",
|
||||
|
||||
@@ -224,7 +224,6 @@ func writeUIConfig(t *testing.T, dir, stateTarget, gatewayTarget string) string
|
||||
t.Helper()
|
||||
path := filepath.Join(dir, "config.toml")
|
||||
content := fmt.Sprintf(`bot_user = "archie-bot"
|
||||
db_path = %q
|
||||
[forge]
|
||||
type = "github"
|
||||
host = "https://github.example.com"
|
||||
@@ -236,7 +235,7 @@ name = "widget"
|
||||
target = %q
|
||||
[services.gateway]
|
||||
target = %q
|
||||
`, filepath.Join(dir, "archie.db"), stateTarget, gatewayTarget)
|
||||
`, stateTarget, gatewayTarget)
|
||||
if err := os.WriteFile(path, []byte(content), 0o600); err != nil {
|
||||
t.Fatalf("write ui config: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user