@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.
@@ -3774,22 +3774,46 @@ async function ensureTaskTables(context, options = {}) {
3774
3774
  }
3775
3775
  }
3776
3776
  const { actions } = await ensureSchema(db, spec, { dryRun, logger: context.logger });
3777
+ const legacyDrops = await dropLegacyTaskNameColumn(db, [tasksTable, historyTable], {
3778
+ dryRun,
3779
+ log,
3780
+ label
3781
+ });
3782
+ const allActions = [...actions, ...legacyDrops];
3777
3783
  if (dryRun) {
3778
- if (actions.length === 0) {
3784
+ if (allActions.length === 0) {
3779
3785
  log.info?.(`[tasks-schema] dryRun \u2014 ${label}: queue "${queueName}" already up to date; no DDL`);
3780
3786
  } else {
3781
3787
  log.info?.(
3782
- `[tasks-schema] dryRun \u2014 ${label}: would run ${actions.length} statement(s) for queue "${queueName}":`
3788
+ `[tasks-schema] dryRun \u2014 ${label}: would run ${allActions.length} statement(s) for queue "${queueName}":`
3783
3789
  );
3784
- for (const s of actions) log.info?.(` - ${s}`);
3790
+ for (const s of allActions) log.info?.(` - ${s}`);
3785
3791
  }
3786
- } else if (actions.length > 0) {
3792
+ } else if (allActions.length > 0) {
3787
3793
  log.info?.(
3788
- `[tasks-schema] ${label}: applied ${actions.length} DDL statement(s) for queue "${queueName}"`
3794
+ `[tasks-schema] ${label}: applied ${allActions.length} DDL statement(s) for queue "${queueName}"`
3789
3795
  );
3790
3796
  }
3791
3797
  }
3792
3798
  }
3799
+ async function dropLegacyTaskNameColumn(db, tableNames, { dryRun, log, label }) {
3800
+ const actions = [];
3801
+ for (const table of tableNames) {
3802
+ if (!await db.tableExists(table).catch(() => false)) continue;
3803
+ const hasTask = await db.schema.hasColumn(table, "task");
3804
+ const hasName = await db.schema.hasColumn(table, "name");
3805
+ if (!hasTask || !hasName) continue;
3806
+ const sql = `ALTER TABLE "${table}" DROP COLUMN IF EXISTS "task"`;
3807
+ actions.push(sql);
3808
+ if (dryRun) {
3809
+ log?.info?.(`[tasks-schema] dryRun \u2014 ${label}: ${sql}`);
3810
+ } else {
3811
+ await db.raw(sql);
3812
+ log?.info?.(`[tasks-schema] ${label}: dropped legacy column ${table}.task`);
3813
+ }
3814
+ }
3815
+ return actions;
3816
+ }
3793
3817
  async function updateTaskProgress(context, tasksTable, taskId, progress) {
3794
3818
  const db = getDb(context);
3795
3819
  await db(tasksTable).where({ id: taskId }).update({