From f41e4e7f52125fc4b8dc47d638e6dae8ebdd3829 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Mon, 6 Jul 2026 09:58:13 +0200 Subject: [PATCH] fix(cli): datatable migrate up/down default to main datatable, not all Co-Authored-By: Claude Opus 4.8 (1M context) --- cli/src/commands/datatable/datatable.ts | 47 +++++-------------- cli/src/guidance/skills.gen.ts | 8 ++-- .../auto-generated/cli/cli-commands.md | 8 ++-- system_prompts/auto-generated/prompts.ts | 8 ++-- .../skills/cli-commands/SKILL.md | 8 ++-- 5 files changed, 28 insertions(+), 51 deletions(-) diff --git a/cli/src/commands/datatable/datatable.ts b/cli/src/commands/datatable/datatable.ts index 49a2cf57d9..6609d08c50 100644 --- a/cli/src/commands/datatable/datatable.ts +++ b/cli/src/commands/datatable/datatable.ts @@ -55,29 +55,14 @@ function migrateNew( createMigration(opts.datatable ?? DEFAULT_DATATABLE_NAME, name); } -// Resolve the datatables to operate on: the one passed via --datatable, or every -// datatable in the workspace when none is given. -async function resolveDatatables( - workspaceId: string, - datatable?: string, -): Promise { - if (datatable) return [datatable]; - const items = await wmill.listDataTables({ workspace: workspaceId }); - return items.map((x) => x.name); -} - async function migrateUp(opts: GlobalOptions & { datatable?: string }) { const workspace = await resolveWorkspace(opts); await requireLogin(opts); - const targets = await resolveDatatables(workspace.workspaceId, opts.datatable); - if (targets.length === 0) { - log.info("No datatables in the workspace"); - return; - } + const dt = opts.datatable ?? DEFAULT_DATATABLE_NAME; // Reject malformed local migrations (duplicate timestamps, orphan downs) before // pushing — the same check `wmill sync push` runs — so a duplicate timestamp // can't silently overwrite one migration on upsert. - const errors = validateLocalMigrations(new Set(targets)); + const errors = validateLocalMigrations(new Set([dt])); if (errors.length > 0) { log.error( "Invalid datatable migrations, aborting:\n" + @@ -85,25 +70,17 @@ async function migrateUp(opts: GlobalOptions & { datatable?: string }) { ); process.exit(1); } - for (const dt of targets) { - // Push any locally-created/edited migration files first (without running - // them), so `migrate up` works even before a `wmill sync push`. - await pushLocalMigrations(workspace.workspaceId, dt); - await runMigrations(workspace.workspaceId, dt); - } + // Push any locally-created/edited migration files first (without running + // them), so `migrate up` works even before a `wmill sync push`. + await pushLocalMigrations(workspace.workspaceId, dt); + await runMigrations(workspace.workspaceId, dt); } async function migrateDown(opts: GlobalOptions & { datatable?: string }) { const workspace = await resolveWorkspace(opts); await requireLogin(opts); - const targets = await resolveDatatables(workspace.workspaceId, opts.datatable); - if (targets.length === 0) { - log.info("No datatables in the workspace"); - return; - } - for (const dt of targets) { - await rollbackMigrations(workspace.workspaceId, dt); - } + const dt = opts.datatable ?? DEFAULT_DATATABLE_NAME; + await rollbackMigrations(workspace.workspaceId, dt); } const migrateCommand = new Command() @@ -117,20 +94,20 @@ const migrateCommand = new Command() .action(migrateNew as any) .command( "up", - "apply all pending migrations to every datatable (or one via --datatable)", + "apply all pending migrations to the main datatable (or one via --datatable)", ) .option( "-d --datatable ", - "Target a specific datatable (default: all datatables in the workspace)", + "Target datatable (default: main)", ) .action(migrateUp as any) .command( "down", - "roll back the most recent migration on every datatable (or one via --datatable)", + "roll back the most recent migration on the main datatable (or one via --datatable)", ) .option( "-d --datatable ", - "Target a specific datatable (default: all datatables in the workspace)", + "Target datatable (default: main)", ) .action(migrateDown as any); diff --git a/cli/src/guidance/skills.gen.ts b/cli/src/guidance/skills.gen.ts index 240755bce3..a0025d24ae 100644 --- a/cli/src/guidance/skills.gen.ts +++ b/cli/src/guidance/skills.gen.ts @@ -6594,10 +6594,10 @@ datatable related commands - \`datatable migrate\` - manage datatable migrations - \`datatable migrate new \` - scaffold a new migration (.up.sql / .down.sql files) - \`-d --datatable \` - Target datatable (default: main) - - \`datatable migrate up\` - apply all pending migrations to every datatable (or one via --datatable) - - \`-d --datatable \` - Target a specific datatable (default: all datatables in the workspace) - - \`datatable migrate down\` - roll back the most recent migration on every datatable (or one via --datatable) - - \`-d --datatable \` - Target a specific datatable (default: all datatables in the workspace) + - \`datatable migrate up\` - apply all pending migrations to the main datatable (or one via --datatable) + - \`-d --datatable \` - Target datatable (default: main) + - \`datatable migrate down\` - roll back the most recent migration on the main datatable (or one via --datatable) + - \`-d --datatable \` - Target datatable (default: main) - \`datatable create [name:string]\` - register a datatable database in the workspace (default: instance-backed 'main') so scripts can use datatable:// - \`--resource \` - Back the datatable with an existing postgresql resource path instead of the instance database - \`--force\` - Allow adding to a workspace that already has datatables (fork metadata on existing ones is not preserved) diff --git a/system_prompts/auto-generated/cli/cli-commands.md b/system_prompts/auto-generated/cli/cli-commands.md index 993dcac5cd..a74fdc6a17 100644 --- a/system_prompts/auto-generated/cli/cli-commands.md +++ b/system_prompts/auto-generated/cli/cli-commands.md @@ -80,10 +80,10 @@ datatable related commands - `datatable migrate` - manage datatable migrations - `datatable migrate new ` - scaffold a new migration (.up.sql / .down.sql files) - `-d --datatable ` - Target datatable (default: main) - - `datatable migrate up` - apply all pending migrations to every datatable (or one via --datatable) - - `-d --datatable ` - Target a specific datatable (default: all datatables in the workspace) - - `datatable migrate down` - roll back the most recent migration on every datatable (or one via --datatable) - - `-d --datatable ` - Target a specific datatable (default: all datatables in the workspace) + - `datatable migrate up` - apply all pending migrations to the main datatable (or one via --datatable) + - `-d --datatable ` - Target datatable (default: main) + - `datatable migrate down` - roll back the most recent migration on the main datatable (or one via --datatable) + - `-d --datatable ` - Target datatable (default: main) - `datatable create [name:string]` - register a datatable database in the workspace (default: instance-backed 'main') so scripts can use datatable:// - `--resource ` - Back the datatable with an existing postgresql resource path instead of the instance database - `--force` - Allow adding to a workspace that already has datatables (fork metadata on existing ones is not preserved) diff --git a/system_prompts/auto-generated/prompts.ts b/system_prompts/auto-generated/prompts.ts index b68c9ef55f..3842b4e2b0 100644 --- a/system_prompts/auto-generated/prompts.ts +++ b/system_prompts/auto-generated/prompts.ts @@ -2756,10 +2756,10 @@ datatable related commands - \`datatable migrate\` - manage datatable migrations - \`datatable migrate new \` - scaffold a new migration (.up.sql / .down.sql files) - \`-d --datatable \` - Target datatable (default: main) - - \`datatable migrate up\` - apply all pending migrations to every datatable (or one via --datatable) - - \`-d --datatable \` - Target a specific datatable (default: all datatables in the workspace) - - \`datatable migrate down\` - roll back the most recent migration on every datatable (or one via --datatable) - - \`-d --datatable \` - Target a specific datatable (default: all datatables in the workspace) + - \`datatable migrate up\` - apply all pending migrations to the main datatable (or one via --datatable) + - \`-d --datatable \` - Target datatable (default: main) + - \`datatable migrate down\` - roll back the most recent migration on the main datatable (or one via --datatable) + - \`-d --datatable \` - Target datatable (default: main) - \`datatable create [name:string]\` - register a datatable database in the workspace (default: instance-backed 'main') so scripts can use datatable:// - \`--resource \` - Back the datatable with an existing postgresql resource path instead of the instance database - \`--force\` - Allow adding to a workspace that already has datatables (fork metadata on existing ones is not preserved) diff --git a/system_prompts/auto-generated/skills/cli-commands/SKILL.md b/system_prompts/auto-generated/skills/cli-commands/SKILL.md index 1a4738ecf5..db04118c3f 100644 --- a/system_prompts/auto-generated/skills/cli-commands/SKILL.md +++ b/system_prompts/auto-generated/skills/cli-commands/SKILL.md @@ -85,10 +85,10 @@ datatable related commands - `datatable migrate` - manage datatable migrations - `datatable migrate new ` - scaffold a new migration (.up.sql / .down.sql files) - `-d --datatable ` - Target datatable (default: main) - - `datatable migrate up` - apply all pending migrations to every datatable (or one via --datatable) - - `-d --datatable ` - Target a specific datatable (default: all datatables in the workspace) - - `datatable migrate down` - roll back the most recent migration on every datatable (or one via --datatable) - - `-d --datatable ` - Target a specific datatable (default: all datatables in the workspace) + - `datatable migrate up` - apply all pending migrations to the main datatable (or one via --datatable) + - `-d --datatable ` - Target datatable (default: main) + - `datatable migrate down` - roll back the most recent migration on the main datatable (or one via --datatable) + - `-d --datatable ` - Target datatable (default: main) - `datatable create [name:string]` - register a datatable database in the workspace (default: instance-backed 'main') so scripts can use datatable:// - `--resource ` - Back the datatable with an existing postgresql resource path instead of the instance database - `--force` - Allow adding to a workspace that already has datatables (fork metadata on existing ones is not preserved)