Remove resource pools, leases and wait queues
Drop the resource allocation feature end to end: store tables and migration, runner scheduling and cleanup, protocol types and commands, CLI commands, TUI screens, tests and docs. Existing databases open cleanly and definitions carrying a retired resources block still validate.
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
package pipeline
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestOpenDropsRetiredResourceSchema proves an existing database that still
|
||||
// carries the removed pool/ownership/wait-queue tables and the run queue
|
||||
// snapshot column opens cleanly, losing only that retired state. A second open
|
||||
// proves the removal is idempotent.
|
||||
func TestOpenDropsRetiredResourceSchema(t *testing.T) {
|
||||
path := filepath.Join(t.TempDir(), "legacy-resources.db")
|
||||
store, err := Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := store.db.Exec(`ALTER TABLE pipeline_runs ADD COLUMN resource_wait TEXT NOT NULL DEFAULT '';
|
||||
CREATE TABLE resource_owners (
|
||||
resource_key TEXT PRIMARY KEY, run_id INTEGER NOT NULL REFERENCES pipeline_runs(id),
|
||||
stage_key TEXT NOT NULL, sequence INTEGER NOT NULL, token TEXT NOT NULL,
|
||||
cleanup_confirmed INTEGER NOT NULL DEFAULT 0, diagnostic TEXT NOT NULL DEFAULT '');
|
||||
CREATE TABLE resource_waiters (
|
||||
queue_order INTEGER PRIMARY KEY AUTOINCREMENT, resource_key TEXT NOT NULL,
|
||||
run_id INTEGER NOT NULL UNIQUE REFERENCES pipeline_runs(id), stage_key TEXT NOT NULL,
|
||||
sequence INTEGER NOT NULL, token TEXT NOT NULL, queued_at TEXT NOT NULL);
|
||||
CREATE TABLE resource_pools (
|
||||
name TEXT PRIMARY KEY, members_json TEXT NOT NULL, updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP);
|
||||
CREATE TABLE resource_recovery_audit (
|
||||
resource_key TEXT NOT NULL, run_id INTEGER NOT NULL, stage_key TEXT NOT NULL,
|
||||
sequence INTEGER NOT NULL, actor TEXT NOT NULL, source TEXT NOT NULL,
|
||||
evidence TEXT NOT NULL, result TEXT NOT NULL, created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP);`); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
for attempt := 0; attempt < 2; attempt++ {
|
||||
store, err = Open(path)
|
||||
if err != nil {
|
||||
t.Fatalf("open existing database (attempt %d): %v", attempt+1, err)
|
||||
}
|
||||
if runs, err := store.ListRuns(context.Background()); err != nil || len(runs) != 0 {
|
||||
t.Fatalf("list runs after migration (attempt %d): %+v %v", attempt+1, runs, err)
|
||||
}
|
||||
for _, table := range []string{"resource_owners", "resource_waiters", "resource_pools", "resource_recovery_audit"} {
|
||||
var name string
|
||||
err := store.db.QueryRow("SELECT name FROM sqlite_master WHERE type='table' AND name=?", table).Scan(&name)
|
||||
if err == nil {
|
||||
t.Fatalf("retired table %s survived migration", table)
|
||||
}
|
||||
}
|
||||
var count int
|
||||
if err := store.db.QueryRow("SELECT COUNT(*) FROM pragma_table_info('pipeline_runs') WHERE name='resource_wait'").Scan(&count); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if count != 0 {
|
||||
t.Fatal("retired resource_wait column survived migration")
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user