@nmakarov/cli-toolkit 0.43.0 → 0.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3790,22 +3790,46 @@ async function ensureTaskTables(context, options = {}) {
3790
3790
  }
3791
3791
  }
3792
3792
  const { actions } = await ensureSchema(db, spec, { dryRun, logger: context.logger });
3793
+ const legacyDrops = await dropLegacyTaskNameColumn(db, [tasksTable, historyTable], {
3794
+ dryRun,
3795
+ log,
3796
+ label
3797
+ });
3798
+ const allActions = [...actions, ...legacyDrops];
3793
3799
  if (dryRun) {
3794
- if (actions.length === 0) {
3800
+ if (allActions.length === 0) {
3795
3801
  log.info?.(`[tasks-schema] dryRun \u2014 ${label}: queue "${queueName}" already up to date; no DDL`);
3796
3802
  } else {
3797
3803
  log.info?.(
3798
- `[tasks-schema] dryRun \u2014 ${label}: would run ${actions.length} statement(s) for queue "${queueName}":`
3804
+ `[tasks-schema] dryRun \u2014 ${label}: would run ${allActions.length} statement(s) for queue "${queueName}":`
3799
3805
  );
3800
- for (const s of actions) log.info?.(` - ${s}`);
3806
+ for (const s of allActions) log.info?.(` - ${s}`);
3801
3807
  }
3802
- } else if (actions.length > 0) {
3808
+ } else if (allActions.length > 0) {
3803
3809
  log.info?.(
3804
- `[tasks-schema] ${label}: applied ${actions.length} DDL statement(s) for queue "${queueName}"`
3810
+ `[tasks-schema] ${label}: applied ${allActions.length} DDL statement(s) for queue "${queueName}"`
3805
3811
  );
3806
3812
  }
3807
3813
  }
3808
3814
  }
3815
+ async function dropLegacyTaskNameColumn(db, tableNames, { dryRun, log, label }) {
3816
+ const actions = [];
3817
+ for (const table of tableNames) {
3818
+ if (!await db.tableExists(table).catch(() => false)) continue;
3819
+ const hasTask = await db.schema.hasColumn(table, "task");
3820
+ const hasName = await db.schema.hasColumn(table, "name");
3821
+ if (!hasTask || !hasName) continue;
3822
+ const sql = `ALTER TABLE "${table}" DROP COLUMN IF EXISTS "task"`;
3823
+ actions.push(sql);
3824
+ if (dryRun) {
3825
+ log?.info?.(`[tasks-schema] dryRun \u2014 ${label}: ${sql}`);
3826
+ } else {
3827
+ await db.raw(sql);
3828
+ log?.info?.(`[tasks-schema] ${label}: dropped legacy column ${table}.task`);
3829
+ }
3830
+ }
3831
+ return actions;
3832
+ }
3809
3833
  async function updateTaskProgress(context, tasksTable, taskId, progress) {
3810
3834
  const db = getDb(context);
3811
3835
  await db(tasksTable).where({ id: taskId }).update({