From d234001e6360be5d7423f07f8adcc6335b362bb6 Mon Sep 17 00:00:00 2001 From: Diego Imbert Date: Thu, 18 Jun 2026 21:07:35 +0200 Subject: [PATCH] feat: datatable migrate up/down default to all datatables, --datatable to target one --- cli/src/commands/datatable/datatable.ts | 57 ++++++++++++++++++++----- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/cli/src/commands/datatable/datatable.ts b/cli/src/commands/datatable/datatable.ts index 35f8481bba..f790b2b58b 100644 --- a/cli/src/commands/datatable/datatable.ts +++ b/cli/src/commands/datatable/datatable.ts @@ -53,16 +53,41 @@ function migrateNew( createMigration(opts.datatable ?? DEFAULT_DATATABLE_NAME, name); } -async function migrateUp(opts: GlobalOptions, name?: string) { - const workspace = await resolveWorkspace(opts); - await requireLogin(opts); - await runMigrations(workspace.workspaceId, name ?? DEFAULT_DATATABLE_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 migrateDown(opts: GlobalOptions, name?: string) { +async function migrateUp(opts: GlobalOptions & { datatable?: string }) { const workspace = await resolveWorkspace(opts); await requireLogin(opts); - await rollbackMigrations(workspace.workspaceId, name ?? DEFAULT_DATATABLE_NAME); + 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 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 migrateCommand = new Command() @@ -74,11 +99,23 @@ const migrateCommand = new Command() "Target datatable (default: main)", ) .action(migrateNew as any) - .command("up", "apply all pending migrations to a datatable") - .arguments("[name:string]") + .command( + "up", + "apply all pending migrations to every datatable (or one via --datatable)", + ) + .option( + "-d --datatable ", + "Target a specific datatable (default: all datatables in the workspace)", + ) .action(migrateUp as any) - .command("down", "roll back the most recent migration on a datatable") - .arguments("[name:string]") + .command( + "down", + "roll back the most recent migration on every datatable (or one via --datatable)", + ) + .option( + "-d --datatable ", + "Target a specific datatable (default: all datatables in the workspace)", + ) .action(migrateDown as any); async function serve(