appwrite-utils-cli 1.5.2 → 1.6.1

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.
Files changed (233) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/README.md +251 -29
  3. package/dist/adapters/AdapterFactory.d.ts +10 -3
  4. package/dist/adapters/AdapterFactory.js +213 -17
  5. package/dist/adapters/TablesDBAdapter.js +60 -17
  6. package/dist/backups/operations/bucketBackup.d.ts +19 -0
  7. package/dist/backups/operations/bucketBackup.js +197 -0
  8. package/dist/backups/operations/collectionBackup.d.ts +30 -0
  9. package/dist/backups/operations/collectionBackup.js +201 -0
  10. package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
  11. package/dist/backups/operations/comprehensiveBackup.js +238 -0
  12. package/dist/backups/schemas/bucketManifest.d.ts +93 -0
  13. package/dist/backups/schemas/bucketManifest.js +33 -0
  14. package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
  15. package/dist/backups/schemas/comprehensiveManifest.js +32 -0
  16. package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
  17. package/dist/backups/tracking/centralizedTracking.js +274 -0
  18. package/dist/cli/commands/configCommands.d.ts +8 -0
  19. package/dist/cli/commands/configCommands.js +160 -0
  20. package/dist/cli/commands/databaseCommands.d.ts +13 -0
  21. package/dist/cli/commands/databaseCommands.js +479 -0
  22. package/dist/cli/commands/functionCommands.d.ts +7 -0
  23. package/dist/cli/commands/functionCommands.js +289 -0
  24. package/dist/cli/commands/schemaCommands.d.ts +7 -0
  25. package/dist/cli/commands/schemaCommands.js +134 -0
  26. package/dist/cli/commands/transferCommands.d.ts +5 -0
  27. package/dist/cli/commands/transferCommands.js +384 -0
  28. package/dist/collections/attributes.d.ts +5 -4
  29. package/dist/collections/attributes.js +539 -246
  30. package/dist/collections/indexes.js +39 -37
  31. package/dist/collections/methods.d.ts +2 -16
  32. package/dist/collections/methods.js +90 -538
  33. package/dist/collections/transferOperations.d.ts +7 -0
  34. package/dist/collections/transferOperations.js +331 -0
  35. package/dist/collections/wipeOperations.d.ts +16 -0
  36. package/dist/collections/wipeOperations.js +328 -0
  37. package/dist/config/configMigration.d.ts +87 -0
  38. package/dist/config/configMigration.js +390 -0
  39. package/dist/config/configValidation.d.ts +66 -0
  40. package/dist/config/configValidation.js +358 -0
  41. package/dist/config/yamlConfig.d.ts +455 -1
  42. package/dist/config/yamlConfig.js +145 -52
  43. package/dist/databases/methods.js +3 -2
  44. package/dist/databases/setup.d.ts +1 -2
  45. package/dist/databases/setup.js +9 -87
  46. package/dist/examples/yamlTerminologyExample.d.ts +42 -0
  47. package/dist/examples/yamlTerminologyExample.js +269 -0
  48. package/dist/functions/deployments.js +11 -10
  49. package/dist/functions/methods.d.ts +1 -1
  50. package/dist/functions/methods.js +5 -4
  51. package/dist/init.js +9 -9
  52. package/dist/interactiveCLI.d.ts +8 -17
  53. package/dist/interactiveCLI.js +209 -1172
  54. package/dist/main.js +364 -21
  55. package/dist/migrations/afterImportActions.js +22 -30
  56. package/dist/migrations/appwriteToX.js +71 -25
  57. package/dist/migrations/dataLoader.js +35 -26
  58. package/dist/migrations/importController.js +29 -30
  59. package/dist/migrations/relationships.js +13 -12
  60. package/dist/migrations/services/ImportOrchestrator.js +16 -19
  61. package/dist/migrations/transfer.js +46 -46
  62. package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
  63. package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
  64. package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
  65. package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
  66. package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
  67. package/dist/migrations/yaml/generateImportSchemas.js +736 -7
  68. package/dist/schemas/authUser.d.ts +1 -1
  69. package/dist/setupController.js +3 -2
  70. package/dist/shared/backupMetadataSchema.d.ts +94 -0
  71. package/dist/shared/backupMetadataSchema.js +38 -0
  72. package/dist/shared/backupTracking.d.ts +18 -0
  73. package/dist/shared/backupTracking.js +176 -0
  74. package/dist/shared/confirmationDialogs.js +15 -15
  75. package/dist/shared/errorUtils.d.ts +54 -0
  76. package/dist/shared/errorUtils.js +95 -0
  77. package/dist/shared/functionManager.js +20 -19
  78. package/dist/shared/indexManager.js +12 -11
  79. package/dist/shared/jsonSchemaGenerator.js +10 -26
  80. package/dist/shared/logging.d.ts +51 -0
  81. package/dist/shared/logging.js +70 -0
  82. package/dist/shared/messageFormatter.d.ts +2 -0
  83. package/dist/shared/messageFormatter.js +10 -0
  84. package/dist/shared/migrationHelpers.d.ts +6 -16
  85. package/dist/shared/migrationHelpers.js +24 -21
  86. package/dist/shared/operationLogger.d.ts +8 -1
  87. package/dist/shared/operationLogger.js +11 -24
  88. package/dist/shared/operationQueue.d.ts +28 -1
  89. package/dist/shared/operationQueue.js +268 -66
  90. package/dist/shared/operationsTable.d.ts +26 -0
  91. package/dist/shared/operationsTable.js +286 -0
  92. package/dist/shared/operationsTableSchema.d.ts +48 -0
  93. package/dist/shared/operationsTableSchema.js +35 -0
  94. package/dist/shared/relationshipExtractor.d.ts +56 -0
  95. package/dist/shared/relationshipExtractor.js +138 -0
  96. package/dist/shared/schemaGenerator.d.ts +19 -1
  97. package/dist/shared/schemaGenerator.js +56 -75
  98. package/dist/storage/backupCompression.d.ts +20 -0
  99. package/dist/storage/backupCompression.js +67 -0
  100. package/dist/storage/methods.d.ts +16 -2
  101. package/dist/storage/methods.js +98 -14
  102. package/dist/users/methods.js +9 -8
  103. package/dist/utils/configDiscovery.d.ts +78 -0
  104. package/dist/utils/configDiscovery.js +430 -0
  105. package/dist/utils/directoryUtils.d.ts +22 -0
  106. package/dist/utils/directoryUtils.js +59 -0
  107. package/dist/utils/getClientFromConfig.d.ts +17 -8
  108. package/dist/utils/getClientFromConfig.js +162 -17
  109. package/dist/utils/helperFunctions.d.ts +16 -2
  110. package/dist/utils/helperFunctions.js +19 -5
  111. package/dist/utils/loadConfigs.d.ts +34 -9
  112. package/dist/utils/loadConfigs.js +236 -316
  113. package/dist/utils/pathResolvers.d.ts +53 -0
  114. package/dist/utils/pathResolvers.js +72 -0
  115. package/dist/utils/projectConfig.d.ts +119 -0
  116. package/dist/utils/projectConfig.js +171 -0
  117. package/dist/utils/retryFailedPromises.js +4 -2
  118. package/dist/utils/sessionAuth.d.ts +48 -0
  119. package/dist/utils/sessionAuth.js +164 -0
  120. package/dist/utils/sessionPreservationExample.d.ts +1666 -0
  121. package/dist/utils/sessionPreservationExample.js +101 -0
  122. package/dist/utils/setupFiles.js +301 -41
  123. package/dist/utils/typeGuards.d.ts +35 -0
  124. package/dist/utils/typeGuards.js +57 -0
  125. package/dist/utils/versionDetection.js +145 -9
  126. package/dist/utils/yamlConverter.d.ts +53 -3
  127. package/dist/utils/yamlConverter.js +232 -13
  128. package/dist/utils/yamlLoader.d.ts +70 -0
  129. package/dist/utils/yamlLoader.js +263 -0
  130. package/dist/utilsController.d.ts +36 -3
  131. package/dist/utilsController.js +186 -56
  132. package/package.json +12 -2
  133. package/src/adapters/AdapterFactory.ts +263 -35
  134. package/src/adapters/TablesDBAdapter.ts +225 -36
  135. package/src/backups/operations/bucketBackup.ts +277 -0
  136. package/src/backups/operations/collectionBackup.ts +310 -0
  137. package/src/backups/operations/comprehensiveBackup.ts +342 -0
  138. package/src/backups/schemas/bucketManifest.ts +78 -0
  139. package/src/backups/schemas/comprehensiveManifest.ts +76 -0
  140. package/src/backups/tracking/centralizedTracking.ts +352 -0
  141. package/src/cli/commands/configCommands.ts +194 -0
  142. package/src/cli/commands/databaseCommands.ts +635 -0
  143. package/src/cli/commands/functionCommands.ts +379 -0
  144. package/src/cli/commands/schemaCommands.ts +163 -0
  145. package/src/cli/commands/transferCommands.ts +457 -0
  146. package/src/collections/attributes.ts +900 -621
  147. package/src/collections/attributes.ts.backup +1555 -0
  148. package/src/collections/indexes.ts +116 -114
  149. package/src/collections/methods.ts +295 -968
  150. package/src/collections/transferOperations.ts +516 -0
  151. package/src/collections/wipeOperations.ts +501 -0
  152. package/src/config/README.md +274 -0
  153. package/src/config/configMigration.ts +575 -0
  154. package/src/config/configValidation.ts +445 -0
  155. package/src/config/yamlConfig.ts +168 -55
  156. package/src/databases/methods.ts +3 -2
  157. package/src/databases/setup.ts +11 -138
  158. package/src/examples/yamlTerminologyExample.ts +341 -0
  159. package/src/functions/deployments.ts +14 -12
  160. package/src/functions/methods.ts +11 -11
  161. package/src/functions/templates/hono-typescript/README.md +286 -0
  162. package/src/functions/templates/hono-typescript/package.json +26 -0
  163. package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
  164. package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
  165. package/src/functions/templates/hono-typescript/src/app.ts +180 -0
  166. package/src/functions/templates/hono-typescript/src/context.ts +103 -0
  167. package/src/functions/templates/hono-typescript/src/index.ts +54 -0
  168. package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
  169. package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
  170. package/src/functions/templates/typescript-node/package.json +2 -1
  171. package/src/functions/templates/typescript-node/src/context.ts +103 -0
  172. package/src/functions/templates/typescript-node/src/index.ts +18 -12
  173. package/src/functions/templates/uv/pyproject.toml +1 -0
  174. package/src/functions/templates/uv/src/context.py +125 -0
  175. package/src/functions/templates/uv/src/index.py +35 -5
  176. package/src/init.ts +9 -11
  177. package/src/interactiveCLI.ts +274 -1563
  178. package/src/main.ts +418 -24
  179. package/src/migrations/afterImportActions.ts +71 -44
  180. package/src/migrations/appwriteToX.ts +100 -34
  181. package/src/migrations/dataLoader.ts +48 -34
  182. package/src/migrations/importController.ts +44 -39
  183. package/src/migrations/relationships.ts +28 -18
  184. package/src/migrations/services/ImportOrchestrator.ts +24 -27
  185. package/src/migrations/transfer.ts +159 -121
  186. package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
  187. package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
  188. package/src/migrations/yaml/generateImportSchemas.ts +751 -12
  189. package/src/setupController.ts +3 -2
  190. package/src/shared/backupMetadataSchema.ts +93 -0
  191. package/src/shared/backupTracking.ts +211 -0
  192. package/src/shared/confirmationDialogs.ts +19 -19
  193. package/src/shared/errorUtils.ts +110 -0
  194. package/src/shared/functionManager.ts +21 -20
  195. package/src/shared/indexManager.ts +12 -11
  196. package/src/shared/jsonSchemaGenerator.ts +38 -52
  197. package/src/shared/logging.ts +75 -0
  198. package/src/shared/messageFormatter.ts +14 -1
  199. package/src/shared/migrationHelpers.ts +45 -38
  200. package/src/shared/operationLogger.ts +11 -36
  201. package/src/shared/operationQueue.ts +322 -93
  202. package/src/shared/operationsTable.ts +338 -0
  203. package/src/shared/operationsTableSchema.ts +60 -0
  204. package/src/shared/relationshipExtractor.ts +214 -0
  205. package/src/shared/schemaGenerator.ts +179 -219
  206. package/src/storage/backupCompression.ts +88 -0
  207. package/src/storage/methods.ts +131 -34
  208. package/src/users/methods.ts +11 -9
  209. package/src/utils/configDiscovery.ts +502 -0
  210. package/src/utils/directoryUtils.ts +61 -0
  211. package/src/utils/getClientFromConfig.ts +205 -22
  212. package/src/utils/helperFunctions.ts +23 -5
  213. package/src/utils/loadConfigs.ts +313 -345
  214. package/src/utils/pathResolvers.ts +81 -0
  215. package/src/utils/projectConfig.ts +299 -0
  216. package/src/utils/retryFailedPromises.ts +4 -2
  217. package/src/utils/sessionAuth.ts +230 -0
  218. package/src/utils/setupFiles.ts +322 -54
  219. package/src/utils/typeGuards.ts +65 -0
  220. package/src/utils/versionDetection.ts +218 -64
  221. package/src/utils/yamlConverter.ts +296 -13
  222. package/src/utils/yamlLoader.ts +364 -0
  223. package/src/utilsController.ts +314 -110
  224. package/tests/README.md +497 -0
  225. package/tests/adapters/AdapterFactory.test.ts +277 -0
  226. package/tests/integration/syncOperations.test.ts +463 -0
  227. package/tests/jest.config.js +25 -0
  228. package/tests/migration/configMigration.test.ts +546 -0
  229. package/tests/setup.ts +62 -0
  230. package/tests/testUtils.ts +340 -0
  231. package/tests/utils/loadConfigs.test.ts +350 -0
  232. package/tests/validation/configValidation.test.ts +412 -0
  233. package/src/utils/schemaStrings.ts +0 -517
@@ -19,6 +19,7 @@ import { resolveAndUpdateRelationships } from "./relationships.js";
19
19
  import { UsersController } from "../users/methods.js";
20
20
  import { logger } from "../shared/logging.js";
21
21
  import { updateOperation } from "../shared/migrationHelpers.js";
22
+ import { LegacyAdapter } from "../adapters/LegacyAdapter.js";
22
23
  import {
23
24
  BatchSchema,
24
25
  OperationCreateSchema,
@@ -84,10 +85,6 @@ export class ImportController {
84
85
  let databaseRan: Models.Database | undefined;
85
86
 
86
87
  for (let db of databasesToProcess) {
87
- if (!this.config.useMigrations && db.name.toLowerCase().trim().replace(" ", "") === "migrations") {
88
- continue;
89
- }
90
-
91
88
  MessageFormatter.banner(`Starting import data for database: ${db.name}`, "Database Import");
92
89
 
93
90
  if (!databaseRan) {
@@ -112,9 +109,9 @@ export class ImportController {
112
109
  await this.updateOthersToFinalData(databaseRan, db);
113
110
  }
114
111
 
115
- console.log(`---------------------------------`);
116
- console.log(`Finished import data for database: ${db.name}`);
117
- console.log(`---------------------------------`);
112
+ MessageFormatter.divider();
113
+ MessageFormatter.success(`Finished import data for database: ${db.name}`, { prefix: "Import" });
114
+ MessageFormatter.divider();
118
115
  }
119
116
  }
120
117
 
@@ -274,10 +271,10 @@ export class ImportController {
274
271
  );
275
272
  }
276
273
  }
277
- console.log("Finished importing users batch");
274
+ MessageFormatter.success("Finished importing users batch", { prefix: "Import" });
278
275
  }
279
276
  this.hasImportedUsers = true;
280
- console.log("Finished importing users");
277
+ MessageFormatter.success("Finished importing users", { prefix: "Import" });
281
278
  }
282
279
  }
283
280
 
@@ -287,23 +284,22 @@ export class ImportController {
287
284
  }
288
285
 
289
286
  let importOperation: any = null;
290
- if (this.config.useMigrations) {
291
- importOperation = await this.database.getDocument(
292
- "migrations",
293
- "currentOperations",
294
- importOperationId
295
- );
296
- await updateOperation(this.database, importOperation.$id, {
297
- status: "in_progress",
298
- }, this.config.useMigrations);
299
- }
287
+ importOperation = await this.database.getDocument(
288
+ "migrations",
289
+ "currentOperations",
290
+ importOperationId
291
+ );
292
+ const adapter = new LegacyAdapter(this.database);
293
+ await updateOperation(adapter, db.$id, importOperation.$id, {
294
+ status: "in_progress",
295
+ });
300
296
 
301
297
  const collectionData = dataLoader.importMap.get(
302
298
  dataLoader.getCollectionKey(collection.name)
303
299
  );
304
- console.log(`Processing collection: ${collection.name}...`);
300
+ MessageFormatter.processing(`Processing collection: ${collection.name}...`, { prefix: "Import" });
305
301
  if (!collectionData) {
306
- console.log("No collection data for ", collection.name);
302
+ MessageFormatter.warning(`No collection data for ${collection.name}`, { prefix: "Import" });
307
303
  continue;
308
304
  }
309
305
 
@@ -311,7 +307,7 @@ export class ImportController {
311
307
  let processedItems = 0;
312
308
  for (let i = 0; i < dataSplit.length; i++) {
313
309
  const batches = dataSplit[i];
314
- console.log(`Processing batch ${i + 1} of ${dataSplit.length}`);
310
+ MessageFormatter.progress(`Processing batch ${i + 1} of ${dataSplit.length}`, { prefix: "Import" });
315
311
 
316
312
  const batchPromises = batches.map((item, index) => {
317
313
  try {
@@ -340,25 +336,31 @@ export class ImportController {
340
336
  )
341
337
  );
342
338
  } catch (error) {
343
- console.error(error);
339
+ MessageFormatter.error(
340
+ "Error creating document",
341
+ error instanceof Error ? error : new Error(String(error)),
342
+ { prefix: "Import" }
343
+ );
344
344
  return Promise.resolve();
345
345
  }
346
346
  });
347
347
 
348
348
  // Wait for all promises in the current batch to resolve
349
349
  await Promise.all(batchPromises);
350
- console.log(`Completed batch ${i + 1} of ${dataSplit.length}`);
351
- if (this.config.useMigrations && importOperation) {
352
- await updateOperation(this.database, importOperation.$id, {
350
+ MessageFormatter.success(`Completed batch ${i + 1} of ${dataSplit.length}`, { prefix: "Import" });
351
+ if (importOperation) {
352
+ const adapter = new LegacyAdapter(this.database);
353
+ await updateOperation(adapter, db.$id, importOperation.$id, {
353
354
  progress: processedItems,
354
- }, this.config.useMigrations);
355
+ });
355
356
  }
356
357
  }
357
358
  // After all batches are processed, update the operation status to completed
358
- if (this.config.useMigrations && importOperation) {
359
- await updateOperation(this.database, importOperation.$id, {
359
+ if (importOperation) {
360
+ const adapter = new LegacyAdapter(this.database);
361
+ await updateOperation(adapter, db.$id, importOperation.$id, {
360
362
  status: "completed",
361
- }, this.config.useMigrations);
363
+ });
362
364
  }
363
365
  }
364
366
  }
@@ -369,14 +371,14 @@ export class ImportController {
369
371
  dataLoader: DataLoader,
370
372
  specificCollections?: string[]
371
373
  ) {
372
- console.log("Executing post-import actions...");
374
+ MessageFormatter.info("Executing post-import actions...", { prefix: "Import" });
373
375
  const collectionsToProcess =
374
376
  specificCollections && specificCollections.length > 0
375
377
  ? specificCollections
376
378
  : this.config.collections
377
379
  ? this.config.collections.map((c) => c.name)
378
380
  : Array.from(dataLoader.importMap.keys());
379
- console.log("Collections to process:", collectionsToProcess);
381
+ MessageFormatter.info(`Collections to process: ${collectionsToProcess.join(", ")}`, { prefix: "Import" });
380
382
  // Iterate over each collection in the importMap
381
383
  for (const [
382
384
  collectionKey,
@@ -386,8 +388,9 @@ export class ImportController {
386
388
  dataLoader.getCollectionKey(c)
387
389
  );
388
390
  if (allCollectionKeys.includes(collectionKey)) {
389
- console.log(
390
- `Processing post-import actions for collection: ${collectionKey}`
391
+ MessageFormatter.processing(
392
+ `Processing post-import actions for collection: ${collectionKey}`,
393
+ { prefix: "Import" }
391
394
  );
392
395
 
393
396
  // Iterate over each item in the collectionData.data
@@ -406,16 +409,18 @@ export class ImportController {
406
409
  context
407
410
  );
408
411
  } catch (error) {
409
- console.error(
410
- `Failed to execute post-import actions for item in collection ${collectionKey}:`,
411
- error
412
+ MessageFormatter.error(
413
+ `Failed to execute post-import actions for item in collection ${collectionKey}`,
414
+ error instanceof Error ? error : new Error(String(error)),
415
+ { prefix: "Import" }
412
416
  );
413
417
  }
414
418
  }
415
419
  }
416
420
  } else {
417
- console.log(
418
- `Skipping collection: ${collectionKey} because it's not valid for post-import actions`
421
+ MessageFormatter.info(
422
+ `Skipping collection: ${collectionKey} because it's not valid for post-import actions`,
423
+ { prefix: "Import" }
419
424
  );
420
425
  }
421
426
  }
@@ -6,6 +6,7 @@ import type {
6
6
  RelationshipAttribute,
7
7
  } from "appwrite-utils";
8
8
  import { logger } from "../shared/logging.js";
9
+ import { MessageFormatter } from "../shared/messageFormatter.js";
9
10
 
10
11
  /**
11
12
  * Finds collections that have defined relationship attributes.
@@ -44,24 +45,27 @@ export async function resolveAndUpdateRelationships(
44
45
 
45
46
  // Process each collection sequentially
46
47
  for (const collection of collections) {
47
- console.log(
48
- `Processing collection: ${collection.name} (${collection.$id})`
48
+ MessageFormatter.processing(
49
+ `Processing collection: ${collection.name} (${collection.$id})`,
50
+ { prefix: "Migration" }
49
51
  );
50
52
  const relAttributeMap = collectionsWithRelationships.get(
51
53
  collection.name
52
54
  ) as RelationshipAttribute[]; // Get the relationship attributes for the collections
53
55
 
54
56
  if (!relAttributeMap) {
55
- console.log(
56
- `No mapping found for collection: ${collection.name}, skipping...`
57
+ MessageFormatter.info(
58
+ `No mapping found for collection: ${collection.name}, skipping...`,
59
+ { prefix: "Migration" }
57
60
  );
58
61
  continue;
59
62
  }
60
63
 
61
64
  await processCollection(dbId, database, collection, relAttributeMap);
62
65
  }
63
- console.log(
64
- `Completed relationship resolution and update for database ID: ${dbId}`
66
+ MessageFormatter.success(
67
+ `Completed relationship resolution and update for database ID: ${dbId}`,
68
+ { prefix: "Migration" }
65
69
  );
66
70
  }
67
71
 
@@ -82,8 +86,9 @@ async function processCollection(
82
86
  ]);
83
87
 
84
88
  const documents = response.documents;
85
- console.log(
86
- `Fetched ${documents.length} documents from collection: ${collection.name}`
89
+ MessageFormatter.info(
90
+ `Fetched ${documents.length} documents from collection: ${collection.name}`,
91
+ { prefix: "Migration" }
87
92
  );
88
93
 
89
94
  if (documents.length > 0) {
@@ -119,7 +124,10 @@ async function findDocumentsByOriginalId(
119
124
  Query.equal("$id", relatedCollectionId),
120
125
  ]);
121
126
  if (collection.total === 0) {
122
- console.log(`Collection ${relatedCollectionId} doesn't exist, skipping...`);
127
+ MessageFormatter.warning(
128
+ `Collection ${relatedCollectionId} doesn't exist, skipping...`,
129
+ { prefix: "Migration" }
130
+ );
123
131
  return undefined;
124
132
  }
125
133
  const targetAttr = collection.collections[0].attributes.find(
@@ -127,8 +135,9 @@ async function findDocumentsByOriginalId(
127
135
  (attr) => attr.key === targetKey
128
136
  ) as any;
129
137
  if (!targetAttr) {
130
- console.log(
131
- `Attribute ${targetKey} not found in collection ${relatedCollectionId}, skipping...`
138
+ MessageFormatter.warning(
139
+ `Attribute ${targetKey} not found in collection ${relatedCollectionId}, skipping...`,
140
+ { prefix: "Migration" }
132
141
  );
133
142
  return undefined;
134
143
  }
@@ -160,7 +169,7 @@ async function prepareDocumentUpdates(
160
169
  documents: Models.Document[],
161
170
  relationships: RelationshipAttribute[]
162
171
  ): Promise<{ collectionId: string; documentId: string; updatePayload: any }[]> {
163
- console.log(`Preparing updates for collection: ${collectionName}`);
172
+ MessageFormatter.processing(`Preparing updates for collection: ${collectionName}`, { prefix: "Migration" });
164
173
  const updates: {
165
174
  collectionId: string;
166
175
  documentId: string;
@@ -173,7 +182,7 @@ async function prepareDocumentUpdates(
173
182
  const thisCollectionId = thisCollection?.$id;
174
183
 
175
184
  if (!thisCollectionId) {
176
- console.log(`No collection found with name: ${collectionName}`);
185
+ MessageFormatter.warning(`No collection found with name: ${collectionName}`, { prefix: "Migration" });
177
186
  return [];
178
187
  }
179
188
 
@@ -183,7 +192,7 @@ async function prepareDocumentUpdates(
183
192
  for (const rel of relationships) {
184
193
  // Skip if not dealing with the parent side of a two-way relationship
185
194
  if (rel.twoWay && rel.side !== "parent") {
186
- console.log("Skipping non-parent side of two-way relationship...");
195
+ MessageFormatter.info("Skipping non-parent side of two-way relationship...", { prefix: "Migration" });
187
196
  continue;
188
197
  }
189
198
 
@@ -192,7 +201,7 @@ async function prepareDocumentUpdates(
192
201
  const originalIdField = rel.importMapping?.originalIdField;
193
202
  const targetField = rel.importMapping?.targetField || originalIdField; // Use originalIdField if targetField is not specified
194
203
  if (!originalIdField) {
195
- console.log("Missing originalIdField in importMapping, skipping...");
204
+ MessageFormatter.warning("Missing originalIdField in importMapping, skipping...", { prefix: "Migration" });
196
205
  continue;
197
206
  }
198
207
  const originalId = doc[originalIdField as keyof typeof doc];
@@ -207,8 +216,9 @@ async function prepareDocumentUpdates(
207
216
  ).collections[0];
208
217
 
209
218
  if (!relatedCollection) {
210
- console.log(
211
- `Related collection ${rel.relatedCollection} not found, skipping...`
219
+ MessageFormatter.warning(
220
+ `Related collection ${rel.relatedCollection} not found, skipping...`,
221
+ { prefix: "Migration" }
212
222
  );
213
223
  continue;
214
224
  }
@@ -240,7 +250,7 @@ async function prepareDocumentUpdates(
240
250
  updatePayload[relationshipKey] = isSingleReference
241
251
  ? newRefs[0] || existingRefIds[0]
242
252
  : allRefs;
243
- console.log(`Updating ${relationshipKey} with ${allRefs.length} refs`);
253
+ MessageFormatter.info(`Updating ${relationshipKey} with ${allRefs.length} refs`, { prefix: "Migration" });
244
254
  }
245
255
  }
246
256
 
@@ -28,6 +28,7 @@ import { MessageFormatter } from "../../shared/messageFormatter.js";
28
28
  import { ProgressManager } from "../../shared/progressManager.js";
29
29
  import { tryAwaitWithRetry } from "../../utils/index.js";
30
30
  import { updateOperation, findOrCreateOperation } from "../../shared/migrationHelpers.js";
31
+ import { LegacyAdapter } from "../../adapters/LegacyAdapter.js";
31
32
  import { resolveAndUpdateRelationships } from "../relationships.js";
32
33
 
33
34
  // Enhanced rate limiting configuration - now managed by RateLimitManager
@@ -104,10 +105,6 @@ export class ImportOrchestrator {
104
105
  let processedDatabase: Models.Database | undefined;
105
106
 
106
107
  for (const db of databasesToProcess) {
107
- if (!this.config.useMigrations && db.name.toLowerCase().trim().replace(" ", "") === "migrations") {
108
- continue;
109
- }
110
-
111
108
  MessageFormatter.banner(`Starting import data for database: ${db.name}`, "Database Import");
112
109
 
113
110
  if (!processedDatabase) {
@@ -206,17 +203,17 @@ export class ImportOrchestrator {
206
203
  this.config.collections[index] = collectionConfig;
207
204
 
208
205
  // Find or create an import operation for the collection
209
- if (this.config.useMigrations) {
210
- const collectionImportOperation = await findOrCreateOperation(
211
- this.database,
212
- collection.$id!,
213
- "importData"
214
- );
215
- this.collectionImportOperations.set(
216
- this.getCollectionKey(collection.name),
217
- collectionImportOperation.$id
218
- );
219
- }
206
+ const adapter = new LegacyAdapter(this.database);
207
+ const collectionImportOperation = await findOrCreateOperation(
208
+ adapter,
209
+ dbId,
210
+ "importData",
211
+ collection.$id!
212
+ );
213
+ this.collectionImportOperations.set(
214
+ this.getCollectionKey(collection.name),
215
+ collectionImportOperation.$id
216
+ );
220
217
 
221
218
  // Initialize the collection in the import map
222
219
  this.importMap.set(this.getCollectionKey(collection.name), {
@@ -315,7 +312,7 @@ export class ImportOrchestrator {
315
312
  const rawData = this.loadDataFromFile(importDef);
316
313
  if (rawData.length === 0) return;
317
314
 
318
- await this.updateOperationStatus(collection, "ready", rawData.length);
315
+ await this.updateOperationStatus(db, collection, "ready", rawData.length);
319
316
 
320
317
  const collectionData = this.importMap.get(this.getCollectionKey(collection.name));
321
318
  if (!collectionData) {
@@ -395,7 +392,7 @@ export class ImportOrchestrator {
395
392
  const rawData = this.loadDataFromFile(importDef);
396
393
  if (rawData.length === 0) return;
397
394
 
398
- await this.updateOperationStatus(collection, "ready", rawData.length);
395
+ await this.updateOperationStatus(db, collection, "ready", rawData.length);
399
396
 
400
397
  const collectionData = this.importMap.get(this.getCollectionKey(collection.name));
401
398
  if (!collectionData) return;
@@ -504,8 +501,9 @@ export class ImportOrchestrator {
504
501
  logger.info(`Importing collection: ${collection.name} (${collectionData.data.length} items)`);
505
502
 
506
503
  const operationId = this.collectionImportOperations.get(this.getCollectionKey(collection.name));
507
- if (operationId && this.config.useMigrations) {
508
- await updateOperation(this.database, operationId, { status: "in_progress" }, this.config.useMigrations);
504
+ const adapter = new LegacyAdapter(this.database);
505
+ if (operationId) {
506
+ await updateOperation(adapter, db.$id, operationId, { status: "in_progress" });
509
507
  }
510
508
 
511
509
  // Create batches for processing
@@ -530,14 +528,14 @@ export class ImportOrchestrator {
530
528
  logger.info(`Batch ${i + 1} completed: ${successCount}/${batch.length} items imported`);
531
529
 
532
530
  // Update operation progress
533
- if (operationId && this.config.useMigrations) {
534
- await updateOperation(this.database, operationId, { progress: processedItems }, this.config.useMigrations);
531
+ if (operationId) {
532
+ await updateOperation(adapter, db.$id, operationId, { progress: processedItems });
535
533
  }
536
534
  }
537
535
 
538
536
  // Mark operation as completed
539
- if (operationId && this.config.useMigrations) {
540
- await updateOperation(this.database, operationId, { status: "completed" }, this.config.useMigrations);
537
+ if (operationId) {
538
+ await updateOperation(adapter, db.$id, operationId, { status: "completed" });
541
539
  }
542
540
 
543
541
  logger.info(`Completed importing collection: ${collection.name} (${processedItems} items)`);
@@ -636,13 +634,12 @@ export class ImportOrchestrator {
636
634
  }
637
635
  }
638
636
 
639
- private async updateOperationStatus(collection: CollectionCreate, status: string, total?: number): Promise<void> {
640
- if (!this.config.useMigrations) return;
641
-
637
+ private async updateOperationStatus(db: ConfigDatabase, collection: CollectionCreate, status: string, total?: number): Promise<void> {
642
638
  const operationId = this.collectionImportOperations.get(this.getCollectionKey(collection.name));
643
639
  if (operationId) {
644
640
  const updateData = total ? { status, total } : { status };
645
- await updateOperation(this.database, operationId, updateData, this.config.useMigrations);
641
+ const adapter = new LegacyAdapter(this.database);
642
+ await updateOperation(adapter, db.$id, operationId, updateData);
646
643
  }
647
644
  }
648
645