appwrite-utils-cli 1.5.1 → 1.6.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.
- package/CHANGELOG.md +199 -0
- package/README.md +251 -29
- package/dist/adapters/AdapterFactory.d.ts +10 -3
- package/dist/adapters/AdapterFactory.js +213 -17
- package/dist/adapters/TablesDBAdapter.js +60 -17
- package/dist/backups/operations/bucketBackup.d.ts +19 -0
- package/dist/backups/operations/bucketBackup.js +197 -0
- package/dist/backups/operations/collectionBackup.d.ts +30 -0
- package/dist/backups/operations/collectionBackup.js +201 -0
- package/dist/backups/operations/comprehensiveBackup.d.ts +25 -0
- package/dist/backups/operations/comprehensiveBackup.js +238 -0
- package/dist/backups/schemas/bucketManifest.d.ts +93 -0
- package/dist/backups/schemas/bucketManifest.js +33 -0
- package/dist/backups/schemas/comprehensiveManifest.d.ts +108 -0
- package/dist/backups/schemas/comprehensiveManifest.js +32 -0
- package/dist/backups/tracking/centralizedTracking.d.ts +34 -0
- package/dist/backups/tracking/centralizedTracking.js +274 -0
- package/dist/cli/commands/configCommands.d.ts +8 -0
- package/dist/cli/commands/configCommands.js +160 -0
- package/dist/cli/commands/databaseCommands.d.ts +13 -0
- package/dist/cli/commands/databaseCommands.js +478 -0
- package/dist/cli/commands/functionCommands.d.ts +7 -0
- package/dist/cli/commands/functionCommands.js +289 -0
- package/dist/cli/commands/schemaCommands.d.ts +7 -0
- package/dist/cli/commands/schemaCommands.js +134 -0
- package/dist/cli/commands/transferCommands.d.ts +5 -0
- package/dist/cli/commands/transferCommands.js +384 -0
- package/dist/collections/attributes.d.ts +5 -4
- package/dist/collections/attributes.js +539 -246
- package/dist/collections/indexes.js +39 -37
- package/dist/collections/methods.d.ts +2 -16
- package/dist/collections/methods.js +90 -538
- package/dist/collections/transferOperations.d.ts +7 -0
- package/dist/collections/transferOperations.js +331 -0
- package/dist/collections/wipeOperations.d.ts +16 -0
- package/dist/collections/wipeOperations.js +328 -0
- package/dist/config/configMigration.d.ts +87 -0
- package/dist/config/configMigration.js +390 -0
- package/dist/config/configValidation.d.ts +66 -0
- package/dist/config/configValidation.js +358 -0
- package/dist/config/yamlConfig.d.ts +455 -1
- package/dist/config/yamlConfig.js +145 -52
- package/dist/databases/methods.js +3 -2
- package/dist/databases/setup.d.ts +1 -2
- package/dist/databases/setup.js +9 -87
- package/dist/examples/yamlTerminologyExample.d.ts +42 -0
- package/dist/examples/yamlTerminologyExample.js +269 -0
- package/dist/functions/deployments.js +11 -10
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -4
- package/dist/init.js +9 -9
- package/dist/interactiveCLI.d.ts +8 -17
- package/dist/interactiveCLI.js +186 -1171
- package/dist/main.js +364 -21
- package/dist/migrations/afterImportActions.js +22 -30
- package/dist/migrations/appwriteToX.js +71 -25
- package/dist/migrations/dataLoader.js +35 -26
- package/dist/migrations/importController.js +29 -30
- package/dist/migrations/relationships.js +13 -12
- package/dist/migrations/services/ImportOrchestrator.js +16 -19
- package/dist/migrations/transfer.js +46 -46
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +3 -1
- package/dist/migrations/yaml/YamlImportConfigLoader.js +6 -3
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +9 -3
- package/dist/migrations/yaml/YamlImportIntegration.js +22 -11
- package/dist/migrations/yaml/generateImportSchemas.d.ts +14 -1
- package/dist/migrations/yaml/generateImportSchemas.js +736 -7
- package/dist/schemas/authUser.d.ts +1 -1
- package/dist/setupController.js +3 -2
- package/dist/shared/backupMetadataSchema.d.ts +94 -0
- package/dist/shared/backupMetadataSchema.js +38 -0
- package/dist/shared/backupTracking.d.ts +18 -0
- package/dist/shared/backupTracking.js +176 -0
- package/dist/shared/confirmationDialogs.js +15 -15
- package/dist/shared/errorUtils.d.ts +54 -0
- package/dist/shared/errorUtils.js +95 -0
- package/dist/shared/functionManager.js +20 -19
- package/dist/shared/indexManager.js +12 -11
- package/dist/shared/jsonSchemaGenerator.js +10 -26
- package/dist/shared/logging.d.ts +51 -0
- package/dist/shared/logging.js +70 -0
- package/dist/shared/messageFormatter.d.ts +2 -0
- package/dist/shared/messageFormatter.js +10 -0
- package/dist/shared/migrationHelpers.d.ts +6 -16
- package/dist/shared/migrationHelpers.js +24 -21
- package/dist/shared/operationLogger.d.ts +8 -1
- package/dist/shared/operationLogger.js +11 -24
- package/dist/shared/operationQueue.d.ts +28 -1
- package/dist/shared/operationQueue.js +268 -66
- package/dist/shared/operationsTable.d.ts +26 -0
- package/dist/shared/operationsTable.js +286 -0
- package/dist/shared/operationsTableSchema.d.ts +48 -0
- package/dist/shared/operationsTableSchema.js +35 -0
- package/dist/shared/relationshipExtractor.d.ts +56 -0
- package/dist/shared/relationshipExtractor.js +138 -0
- package/dist/shared/schemaGenerator.d.ts +19 -1
- package/dist/shared/schemaGenerator.js +56 -75
- package/dist/storage/backupCompression.d.ts +20 -0
- package/dist/storage/backupCompression.js +67 -0
- package/dist/storage/methods.d.ts +16 -2
- package/dist/storage/methods.js +98 -14
- package/dist/users/methods.js +9 -8
- package/dist/utils/configDiscovery.d.ts +78 -0
- package/dist/utils/configDiscovery.js +430 -0
- package/dist/utils/directoryUtils.d.ts +22 -0
- package/dist/utils/directoryUtils.js +59 -0
- package/dist/utils/getClientFromConfig.d.ts +17 -8
- package/dist/utils/getClientFromConfig.js +162 -17
- package/dist/utils/helperFunctions.d.ts +16 -2
- package/dist/utils/helperFunctions.js +19 -5
- package/dist/utils/loadConfigs.d.ts +34 -9
- package/dist/utils/loadConfigs.js +236 -316
- package/dist/utils/pathResolvers.d.ts +53 -0
- package/dist/utils/pathResolvers.js +72 -0
- package/dist/utils/projectConfig.d.ts +119 -0
- package/dist/utils/projectConfig.js +171 -0
- package/dist/utils/retryFailedPromises.js +4 -2
- package/dist/utils/sessionAuth.d.ts +48 -0
- package/dist/utils/sessionAuth.js +164 -0
- package/dist/utils/sessionPreservationExample.d.ts +1666 -0
- package/dist/utils/sessionPreservationExample.js +101 -0
- package/dist/utils/setupFiles.js +301 -41
- package/dist/utils/typeGuards.d.ts +35 -0
- package/dist/utils/typeGuards.js +57 -0
- package/dist/utils/versionDetection.js +145 -9
- package/dist/utils/yamlConverter.d.ts +53 -3
- package/dist/utils/yamlConverter.js +232 -13
- package/dist/utils/yamlLoader.d.ts +70 -0
- package/dist/utils/yamlLoader.js +263 -0
- package/dist/utilsController.d.ts +36 -3
- package/dist/utilsController.js +186 -56
- package/package.json +12 -2
- package/src/adapters/AdapterFactory.ts +263 -35
- package/src/adapters/TablesDBAdapter.ts +225 -36
- package/src/backups/operations/bucketBackup.ts +277 -0
- package/src/backups/operations/collectionBackup.ts +310 -0
- package/src/backups/operations/comprehensiveBackup.ts +342 -0
- package/src/backups/schemas/bucketManifest.ts +78 -0
- package/src/backups/schemas/comprehensiveManifest.ts +76 -0
- package/src/backups/tracking/centralizedTracking.ts +352 -0
- package/src/cli/commands/configCommands.ts +194 -0
- package/src/cli/commands/databaseCommands.ts +635 -0
- package/src/cli/commands/functionCommands.ts +379 -0
- package/src/cli/commands/schemaCommands.ts +163 -0
- package/src/cli/commands/transferCommands.ts +457 -0
- package/src/collections/attributes.ts +900 -621
- package/src/collections/attributes.ts.backup +1555 -0
- package/src/collections/indexes.ts +116 -114
- package/src/collections/methods.ts +295 -968
- package/src/collections/transferOperations.ts +516 -0
- package/src/collections/wipeOperations.ts +501 -0
- package/src/config/README.md +274 -0
- package/src/config/configMigration.ts +575 -0
- package/src/config/configValidation.ts +445 -0
- package/src/config/yamlConfig.ts +168 -55
- package/src/databases/methods.ts +3 -2
- package/src/databases/setup.ts +11 -138
- package/src/examples/yamlTerminologyExample.ts +341 -0
- package/src/functions/deployments.ts +14 -12
- package/src/functions/methods.ts +11 -11
- package/src/functions/templates/hono-typescript/README.md +286 -0
- package/src/functions/templates/hono-typescript/package.json +26 -0
- package/src/functions/templates/hono-typescript/src/adapters/request.ts +74 -0
- package/src/functions/templates/hono-typescript/src/adapters/response.ts +106 -0
- package/src/functions/templates/hono-typescript/src/app.ts +180 -0
- package/src/functions/templates/hono-typescript/src/context.ts +103 -0
- package/src/functions/templates/hono-typescript/src/index.ts +54 -0
- package/src/functions/templates/hono-typescript/src/middleware/appwrite.ts +119 -0
- package/src/functions/templates/hono-typescript/tsconfig.json +20 -0
- package/src/functions/templates/typescript-node/package.json +2 -1
- package/src/functions/templates/typescript-node/src/context.ts +103 -0
- package/src/functions/templates/typescript-node/src/index.ts +18 -12
- package/src/functions/templates/uv/pyproject.toml +1 -0
- package/src/functions/templates/uv/src/context.py +125 -0
- package/src/functions/templates/uv/src/index.py +35 -5
- package/src/init.ts +9 -11
- package/src/interactiveCLI.ts +276 -1591
- package/src/main.ts +418 -24
- package/src/migrations/afterImportActions.ts +71 -44
- package/src/migrations/appwriteToX.ts +100 -34
- package/src/migrations/dataLoader.ts +48 -34
- package/src/migrations/importController.ts +44 -39
- package/src/migrations/relationships.ts +28 -18
- package/src/migrations/services/ImportOrchestrator.ts +24 -27
- package/src/migrations/transfer.ts +159 -121
- package/src/migrations/yaml/YamlImportConfigLoader.ts +11 -4
- package/src/migrations/yaml/YamlImportIntegration.ts +47 -20
- package/src/migrations/yaml/generateImportSchemas.ts +751 -12
- package/src/setupController.ts +3 -2
- package/src/shared/backupMetadataSchema.ts +93 -0
- package/src/shared/backupTracking.ts +211 -0
- package/src/shared/confirmationDialogs.ts +19 -19
- package/src/shared/errorUtils.ts +110 -0
- package/src/shared/functionManager.ts +21 -20
- package/src/shared/indexManager.ts +12 -11
- package/src/shared/jsonSchemaGenerator.ts +38 -52
- package/src/shared/logging.ts +75 -0
- package/src/shared/messageFormatter.ts +14 -1
- package/src/shared/migrationHelpers.ts +45 -38
- package/src/shared/operationLogger.ts +11 -36
- package/src/shared/operationQueue.ts +322 -93
- package/src/shared/operationsTable.ts +338 -0
- package/src/shared/operationsTableSchema.ts +60 -0
- package/src/shared/relationshipExtractor.ts +214 -0
- package/src/shared/schemaGenerator.ts +179 -219
- package/src/storage/backupCompression.ts +88 -0
- package/src/storage/methods.ts +131 -34
- package/src/users/methods.ts +11 -9
- package/src/utils/configDiscovery.ts +502 -0
- package/src/utils/directoryUtils.ts +61 -0
- package/src/utils/getClientFromConfig.ts +205 -22
- package/src/utils/helperFunctions.ts +23 -5
- package/src/utils/loadConfigs.ts +313 -345
- package/src/utils/pathResolvers.ts +81 -0
- package/src/utils/projectConfig.ts +299 -0
- package/src/utils/retryFailedPromises.ts +4 -2
- package/src/utils/sessionAuth.ts +230 -0
- package/src/utils/setupFiles.ts +322 -54
- package/src/utils/typeGuards.ts +65 -0
- package/src/utils/versionDetection.ts +218 -64
- package/src/utils/yamlConverter.ts +296 -13
- package/src/utils/yamlLoader.ts +364 -0
- package/src/utilsController.ts +314 -110
- package/tests/README.md +497 -0
- package/tests/adapters/AdapterFactory.test.ts +277 -0
- package/tests/integration/syncOperations.test.ts +463 -0
- package/tests/jest.config.js +25 -0
- package/tests/migration/configMigration.test.ts +546 -0
- package/tests/setup.ts +62 -0
- package/tests/testUtils.ts +340 -0
- package/tests/utils/loadConfigs.test.ts +350 -0
- package/tests/validation/configValidation.test.ts +412 -0
- 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
|
-
|
116
|
-
|
117
|
-
|
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
|
-
|
274
|
+
MessageFormatter.success("Finished importing users batch", { prefix: "Import" });
|
278
275
|
}
|
279
276
|
this.hasImportedUsers = true;
|
280
|
-
|
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
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
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
|
-
|
300
|
+
MessageFormatter.processing(`Processing collection: ${collection.name}...`, { prefix: "Import" });
|
305
301
|
if (!collectionData) {
|
306
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
351
|
-
if (
|
352
|
-
|
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
|
-
}
|
355
|
+
});
|
355
356
|
}
|
356
357
|
}
|
357
358
|
// After all batches are processed, update the operation status to completed
|
358
|
-
if (
|
359
|
-
|
359
|
+
if (importOperation) {
|
360
|
+
const adapter = new LegacyAdapter(this.database);
|
361
|
+
await updateOperation(adapter, db.$id, importOperation.$id, {
|
360
362
|
status: "completed",
|
361
|
-
}
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
508
|
-
|
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
|
534
|
-
await updateOperation(
|
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
|
540
|
-
await updateOperation(
|
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
|
-
|
641
|
+
const adapter = new LegacyAdapter(this.database);
|
642
|
+
await updateOperation(adapter, db.$id, operationId, updateData);
|
646
643
|
}
|
647
644
|
}
|
648
645
|
|