feat: datatable migrate up/down default to all datatables, --datatable to target one

This commit is contained in:
Diego Imbert
2026-06-18 21:07:35 +02:00
parent 49a476fec7
commit d234001e63
+47 -10
View File
@@ -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<string[]> {
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 <datatable:string>",
"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 <datatable:string>",
"Target a specific datatable (default: all datatables in the workspace)",
)
.action(migrateDown as any);
async function serve(