MCPcopy Create free account
hub / github.com/Facets-cloud/flow / TestOpenDBOnPreMigrationDB

Function TestOpenDBOnPreMigrationDB

internal/flowdb/db_test.go:275–341  ·  view source on GitHub ↗

TestOpenDBOnPreMigrationDB simulates an existing user upgrading from a pre-feat/playbooks flow.db: tasks table exists but lacks the kind and playbook_slug columns. OpenDB must apply migrations cleanly without CREATE INDEX failing on the missing columns. Regression test: see commit fixing "no such c

(t *testing.T)

Source from the content-addressed store, hash-verified

273// used to include `CREATE INDEX ... ON tasks(kind)` which fails before
274// runMigrations gets a chance to ALTER TABLE.
275func TestOpenDBOnPreMigrationDB(t *testing.T) {
276 dir := t.TempDir()
277 dbPath := filepath.Join(dir, "flow.db")
278
279 // Create a "pre-migration" DB by hand: just the original tasks schema,
280 // no kind/playbook_slug columns, no playbooks table.
281 pre, err := sql.Open("sqlite", dbPath)
282 if err != nil {
283 t.Fatal(err)
284 }
285 if _, err := pre.Exec(`
286 CREATE TABLE projects (
287 slug TEXT PRIMARY KEY, name TEXT NOT NULL,
288 status TEXT NOT NULL DEFAULT 'active', priority TEXT NOT NULL DEFAULT 'medium',
289 work_dir TEXT NOT NULL, created_at TEXT NOT NULL, updated_at TEXT NOT NULL,
290 archived_at TEXT
291 );
292 CREATE TABLE tasks (
293 slug TEXT PRIMARY KEY, name TEXT NOT NULL,
294 project_slug TEXT, status TEXT NOT NULL DEFAULT 'backlog',
295 priority TEXT NOT NULL DEFAULT 'medium', work_dir TEXT NOT NULL,
296 waiting_on TEXT, session_id TEXT, session_started TEXT,
297 session_last_resumed TEXT, created_at TEXT NOT NULL,
298 updated_at TEXT NOT NULL, archived_at TEXT
299 );
300 CREATE TABLE workdirs (
301 path TEXT PRIMARY KEY, name TEXT, git_remote TEXT,
302 last_used_at TEXT, created_at TEXT NOT NULL
303 );
304 INSERT INTO tasks (slug, name, status, priority, work_dir, created_at, updated_at)
305 VALUES ('legacy', 'Legacy task', 'in-progress', 'high', '/tmp', '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z');
306 `); err != nil {
307 pre.Close()
308 t.Fatalf("seed pre-migration DB: %v", err)
309 }
310 pre.Close()
311
312 // Now reopen via OpenDB — must not error.
313 db, err := OpenDB(dbPath)
314 if err != nil {
315 t.Fatalf("OpenDB on pre-migration DB: %v", err)
316 }
317 defer db.Close()
318
319 // Verify the legacy row is still readable and has kind='regular' default.
320 var kind string
321 if err := db.QueryRow(`SELECT kind FROM tasks WHERE slug='legacy'`).Scan(&kind); err != nil {
322 t.Fatalf("read legacy row after migration: %v", err)
323 }
324 if kind != "regular" {
325 t.Errorf("legacy row kind: got %q, want regular", kind)
326 }
327
328 // Verify the new playbooks table is queryable.
329 if _, err := db.Exec(`SELECT slug FROM playbooks LIMIT 1`); err != nil {
330 t.Errorf("playbooks table not created: %v", err)
331 }
332

Callers

nothing calls this directly

Calls 1

OpenDBFunction · 0.85

Tested by

no test coverage detected