appwrite-utils-cli 0.0.14 → 0.0.16
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/dist/migrations/converters.js +0 -1
- package/dist/migrations/importController.js +22 -12
- package/dist/migrations/importDataActions.js +1 -1
- package/package.json +1 -1
- package/src/migrations/converters.ts +0 -1
- package/src/migrations/importController.ts +33 -20
- package/src/migrations/importDataActions.ts +4 -5
|
@@ -233,19 +233,29 @@ export class ImportController {
|
|
|
233
233
|
async handleCreate(context, finalItem, updateDefs, id) {
|
|
234
234
|
const existing = await documentExists(this.database, context.dbId, context.collId, finalItem);
|
|
235
235
|
if (!existing) {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
updateDefs
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
236
|
+
try {
|
|
237
|
+
const createdDoc = await this.database.createDocument(context.dbId, context.collId, id || ID.unique(), finalItem);
|
|
238
|
+
context.docId = createdDoc.$id;
|
|
239
|
+
context.createdDoc = createdDoc;
|
|
240
|
+
context = { ...context, ...createdDoc };
|
|
241
|
+
// Populate document cache for updates
|
|
242
|
+
if (updateDefs) {
|
|
243
|
+
updateDefs.forEach((def) => {
|
|
244
|
+
if (def.updateMapping) {
|
|
245
|
+
this.documentCache.set(`${finalItem[def.updateMapping.targetField]}`, context);
|
|
246
|
+
}
|
|
247
|
+
});
|
|
248
|
+
}
|
|
249
|
+
return context;
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
logger.error(`An error occurred during creation -- ${context}, id: ${id}, ${finalItem}}`);
|
|
253
|
+
if (error.type === "document_already_exists") {
|
|
254
|
+
logger.warn(`Document already exists, retrying creation. -- ${context}, id: ${id}, ${finalItem}}`);
|
|
255
|
+
await this.handleCreate(context, finalItem, updateDefs, ID.unique());
|
|
256
|
+
}
|
|
257
|
+
return;
|
|
247
258
|
}
|
|
248
|
-
return context;
|
|
249
259
|
}
|
|
250
260
|
else {
|
|
251
261
|
console.log("Document already exists, skipping creation.");
|
|
@@ -109,7 +109,6 @@ export class ImportDataActions {
|
|
|
109
109
|
for (const actionDef of postImportActions) {
|
|
110
110
|
const { action, params } = actionDef;
|
|
111
111
|
console.log(`Executing post-import action '${action}' for attribute '${mapping.targetKey}' with params ${params.join(", ")}...`);
|
|
112
|
-
logger.info(`Executing post-import action '${action}' for attribute '${mapping.targetKey}' with params ${params.join(", ")}...`);
|
|
113
112
|
try {
|
|
114
113
|
await this.executeAction(action, params, context, item);
|
|
115
114
|
}
|
|
@@ -131,6 +130,7 @@ export class ImportDataActions {
|
|
|
131
130
|
});
|
|
132
131
|
// Execute the action with resolved parameters
|
|
133
132
|
// Parameters are passed as-is, with objects treated as single parameters
|
|
133
|
+
console.log(`Executing action '${actionName}' from context with params:`, resolvedParams);
|
|
134
134
|
logger.info(`Executing action '${actionName}' from context: ${JSON.stringify(context, null, 2)} with params:`, resolvedParams);
|
|
135
135
|
await actionMethod(this.config, ...resolvedParams);
|
|
136
136
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "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": "0.0.
|
|
4
|
+
"version": "0.0.16",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -393,28 +393,41 @@ export class ImportController {
|
|
|
393
393
|
finalItem
|
|
394
394
|
);
|
|
395
395
|
if (!existing) {
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
396
|
+
try {
|
|
397
|
+
const createdDoc = await this.database.createDocument(
|
|
398
|
+
context.dbId,
|
|
399
|
+
context.collId,
|
|
400
|
+
id || ID.unique(),
|
|
401
|
+
finalItem
|
|
402
|
+
);
|
|
403
|
+
context.docId = createdDoc.$id;
|
|
404
|
+
context.createdDoc = createdDoc;
|
|
405
|
+
context = { ...context, ...createdDoc };
|
|
405
406
|
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
407
|
+
// Populate document cache for updates
|
|
408
|
+
if (updateDefs) {
|
|
409
|
+
updateDefs.forEach((def) => {
|
|
410
|
+
if (def.updateMapping) {
|
|
411
|
+
this.documentCache.set(
|
|
412
|
+
`${finalItem[def.updateMapping.targetField]}`,
|
|
413
|
+
context
|
|
414
|
+
);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
return context;
|
|
419
|
+
} catch (error: any) {
|
|
420
|
+
logger.error(
|
|
421
|
+
`An error occurred during creation -- ${context}, id: ${id}, ${finalItem}}`
|
|
422
|
+
);
|
|
423
|
+
if (error.type === "document_already_exists") {
|
|
424
|
+
logger.warn(
|
|
425
|
+
`Document already exists, retrying creation. -- ${context}, id: ${id}, ${finalItem}}`
|
|
426
|
+
);
|
|
427
|
+
await this.handleCreate(context, finalItem, updateDefs, ID.unique());
|
|
428
|
+
}
|
|
429
|
+
return;
|
|
416
430
|
}
|
|
417
|
-
return context;
|
|
418
431
|
} else {
|
|
419
432
|
console.log("Document already exists, skipping creation.");
|
|
420
433
|
return existing;
|
|
@@ -174,11 +174,6 @@ export class ImportDataActions {
|
|
|
174
174
|
mapping.targetKey
|
|
175
175
|
}' with params ${params.join(", ")}...`
|
|
176
176
|
);
|
|
177
|
-
logger.info(
|
|
178
|
-
`Executing post-import action '${action}' for attribute '${
|
|
179
|
-
mapping.targetKey
|
|
180
|
-
}' with params ${params.join(", ")}...`
|
|
181
|
-
);
|
|
182
177
|
try {
|
|
183
178
|
await this.executeAction(action, params, context, item);
|
|
184
179
|
} catch (error) {
|
|
@@ -209,6 +204,10 @@ export class ImportDataActions {
|
|
|
209
204
|
|
|
210
205
|
// Execute the action with resolved parameters
|
|
211
206
|
// Parameters are passed as-is, with objects treated as single parameters
|
|
207
|
+
console.log(
|
|
208
|
+
`Executing action '${actionName}' from context with params:`,
|
|
209
|
+
resolvedParams
|
|
210
|
+
);
|
|
212
211
|
logger.info(
|
|
213
212
|
`Executing action '${actionName}' from context: ${JSON.stringify(
|
|
214
213
|
context,
|