@njdamstra/appwrite-utils-cli 1.11.2 → 1.11.3

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.
@@ -1,5 +1,6 @@
1
1
  import inquirer from "inquirer";
2
2
  import path from "node:path";
3
+ import fs from "node:fs";
3
4
  import { MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
4
5
  import { analyzeStringAttributes, executeMigrationPlan, } from "../../migrations/migrateStrings.js";
5
6
  export const migrateCommands = {
@@ -94,6 +95,27 @@ export const migrateCommands = {
94
95
  default: path.join(process.cwd(), "migrate-strings-plan.yaml"),
95
96
  },
96
97
  ]);
98
+ // Check for existing checkpoint
99
+ let freshRun = false;
100
+ const checkpointPath = planPath.replace(/\.ya?ml$/, ".checkpoint.json");
101
+ if (fs.existsSync(checkpointPath)) {
102
+ const { cpAction } = await inquirer.prompt([
103
+ {
104
+ type: "list",
105
+ name: "cpAction",
106
+ message: "Found an existing checkpoint from a previous run. What would you like to do?",
107
+ choices: [
108
+ { name: "Resume — continue from where it left off", value: "resume" },
109
+ { name: "Start fresh — delete checkpoint and start over", value: "fresh" },
110
+ { name: "Cancel", value: "cancel" },
111
+ ],
112
+ },
113
+ ]);
114
+ if (cpAction === "cancel")
115
+ return;
116
+ if (cpAction === "fresh")
117
+ freshRun = true;
118
+ }
97
119
  const { keepBackups } = await inquirer.prompt([
98
120
  {
99
121
  type: "confirm",
@@ -114,6 +136,7 @@ export const migrateCommands = {
114
136
  planPath,
115
137
  keepBackups,
116
138
  dryRun,
139
+ freshRun,
117
140
  };
118
141
  try {
119
142
  const results = await executeMigrationPlan(controller.adapter, options);
package/dist/main.js CHANGED
@@ -485,6 +485,11 @@ const argv = yargs(hideBin(process.argv))
485
485
  alias: ["migrate-strings-dry-run"],
486
486
  type: "boolean",
487
487
  description: "Dry run — show what would happen without making changes",
488
+ })
489
+ .option("migrateStringsFresh", {
490
+ alias: ["migrate-strings-fresh"],
491
+ type: "boolean",
492
+ description: "Ignore existing checkpoint and start migration fresh",
488
493
  })
489
494
  .parse();
490
495
  async function main() {
@@ -674,6 +679,7 @@ async function main() {
674
679
  planPath: argv.migrateStringsExecute,
675
680
  keepBackups: argv.migrateStringsKeepBackups ?? true,
676
681
  dryRun: argv.migrateStringsDryRun ?? false,
682
+ freshRun: argv.migrateStringsFresh ?? false,
677
683
  });
678
684
  if (results.failed > 0) {
679
685
  process.exit(1);
@@ -193,6 +193,12 @@ export async function executeMigrationPlan(adapter, options) {
193
193
  // Load or create checkpoint
194
194
  const checkpointPath = options.checkpointPath ||
195
195
  options.planPath.replace(/\.ya?ml$/, ".checkpoint.json");
196
+ if (options.freshRun && fs.existsSync(checkpointPath)) {
197
+ fs.unlinkSync(checkpointPath);
198
+ MessageFormatter.info("Deleted old checkpoint — starting fresh.", {
199
+ prefix: "Checkpoint",
200
+ });
201
+ }
196
202
  const checkpoint = loadOrCreateCheckpoint(checkpointPath, options.planPath);
197
203
  const batchSize = options.batchSize || 100;
198
204
  const batchDelayMs = options.batchDelayMs || 50;
@@ -191,6 +191,7 @@ export interface ExecuteOptions {
191
191
  batchSize?: number;
192
192
  batchDelayMs?: number;
193
193
  checkpointPath?: string;
194
+ freshRun?: boolean;
194
195
  }
195
196
  export declare function suggestTargetType(size: number, hasIndex: boolean): MigrationTargetType;
196
197
  export declare function generateBackupKey(originalKey: string): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@njdamstra/appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "1.11.2",
4
+ "version": "1.11.3",
5
5
  "main": "dist/main.js",
6
6
  "type": "module",
7
7
  "repository": {
@@ -1,5 +1,6 @@
1
1
  import inquirer from "inquirer";
2
2
  import path from "node:path";
3
+ import fs from "node:fs";
3
4
  import { MessageFormatter } from "@njdamstra/appwrite-utils-helpers";
4
5
  import type { InteractiveCLI } from "../../interactiveCLI.js";
5
6
  import {
@@ -121,6 +122,26 @@ export const migrateCommands = {
121
122
  },
122
123
  ]);
123
124
 
125
+ // Check for existing checkpoint
126
+ let freshRun = false;
127
+ const checkpointPath = planPath.replace(/\.ya?ml$/, ".checkpoint.json");
128
+ if (fs.existsSync(checkpointPath)) {
129
+ const { cpAction } = await inquirer.prompt([
130
+ {
131
+ type: "list",
132
+ name: "cpAction",
133
+ message: "Found an existing checkpoint from a previous run. What would you like to do?",
134
+ choices: [
135
+ { name: "Resume — continue from where it left off", value: "resume" },
136
+ { name: "Start fresh — delete checkpoint and start over", value: "fresh" },
137
+ { name: "Cancel", value: "cancel" },
138
+ ],
139
+ },
140
+ ]);
141
+ if (cpAction === "cancel") return;
142
+ if (cpAction === "fresh") freshRun = true;
143
+ }
144
+
124
145
  const { keepBackups } = await inquirer.prompt([
125
146
  {
126
147
  type: "confirm",
@@ -143,6 +164,7 @@ export const migrateCommands = {
143
164
  planPath,
144
165
  keepBackups,
145
166
  dryRun,
167
+ freshRun,
146
168
  };
147
169
 
148
170
  try {
package/src/main.ts CHANGED
@@ -89,6 +89,7 @@ interface CliOptions {
89
89
  migrateStringsDbIds?: string;
90
90
  migrateStringsKeepBackups?: boolean;
91
91
  migrateStringsDryRun?: boolean;
92
+ migrateStringsFresh?: boolean;
92
93
  }
93
94
 
94
95
  type ParsedArgv = ArgumentsCamelCase<CliOptions>;
@@ -659,6 +660,11 @@ const argv = yargs(hideBin(process.argv))
659
660
  type: "boolean",
660
661
  description: "Dry run — show what would happen without making changes",
661
662
  })
663
+ .option("migrateStringsFresh", {
664
+ alias: ["migrate-strings-fresh"],
665
+ type: "boolean",
666
+ description: "Ignore existing checkpoint and start migration fresh",
667
+ })
662
668
  .parse() as ParsedArgv;
663
669
 
664
670
  async function main() {
@@ -915,6 +921,7 @@ async function main() {
915
921
  planPath: argv.migrateStringsExecute,
916
922
  keepBackups: argv.migrateStringsKeepBackups ?? true,
917
923
  dryRun: argv.migrateStringsDryRun ?? false,
924
+ freshRun: argv.migrateStringsFresh ?? false,
918
925
  });
919
926
  if (results.failed > 0) {
920
927
  process.exit(1);
@@ -264,6 +264,12 @@ export async function executeMigrationPlan(
264
264
  const checkpointPath =
265
265
  options.checkpointPath ||
266
266
  options.planPath.replace(/\.ya?ml$/, ".checkpoint.json");
267
+ if (options.freshRun && fs.existsSync(checkpointPath)) {
268
+ fs.unlinkSync(checkpointPath);
269
+ MessageFormatter.info("Deleted old checkpoint — starting fresh.", {
270
+ prefix: "Checkpoint",
271
+ });
272
+ }
267
273
  const checkpoint = loadOrCreateCheckpoint(checkpointPath, options.planPath);
268
274
 
269
275
  const batchSize = options.batchSize || 100;
@@ -118,6 +118,7 @@ export interface ExecuteOptions {
118
118
  batchSize?: number;
119
119
  batchDelayMs?: number;
120
120
  checkpointPath?: string;
121
+ freshRun?: boolean;
121
122
  }
122
123
 
123
124
  // ── Helper: suggest target type from size + index presence ──