appwrite-utils-cli 0.0.48 → 0.0.49
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/README.md +1 -0
- package/dist/migrations/dataLoader.js +11 -5
- package/package.json +1 -1
- package/src/migrations/dataLoader.ts +15 -4
package/README.md
CHANGED
|
@@ -132,6 +132,7 @@ This setup ensures that developers have robust tools at their fingertips to mana
|
|
|
132
132
|
|
|
133
133
|
### Changelog
|
|
134
134
|
|
|
135
|
+
- 0.0.49: Fixed a slight bug with `dataLoader` not mapping updates correctly with `updateMapping`
|
|
135
136
|
- 0.0.48: Added `--transfer`, `--fromdb <targetDatabaseId>`, `--targetdb <targetDatabaseId>`, `--transferendpoint <transferEndpoint>`, `--transferproject <transferProjectId>`, `--transferkey <transferApiKey>`. Additionally, I've added `--fromcoll <collectionId>` and `--targetcoll <collectionId>`. These allow you to do a few things. First, you can now transfer databases in the same project, and from local to a remote project. Second, you can now specify specific collections to transfer from one place to another, with all of their data. If `--fromcoll` and `--targetcoll` are ommitted, it will transfer the databases. During the database transfer, it will create any missing collections, attributes, and indices.
|
|
136
137
|
- 0.0.47: Minor bugfixes in many releases, too small to take note of
|
|
137
138
|
- 0.0.38: Lots of optimizations done to the code, added `tryAwaitWithRetry` for `fetch failed` and others like it errors (looking at you `server error`) -- this should prevent things from going sideways.
|
|
@@ -878,7 +878,10 @@ export class DataLoader {
|
|
|
878
878
|
let itemDataToUpdate;
|
|
879
879
|
// Try to find itemDataToUpdate using updateMapping
|
|
880
880
|
if (importDef.updateMapping) {
|
|
881
|
-
|
|
881
|
+
console.log(importDef.updateMapping);
|
|
882
|
+
oldId =
|
|
883
|
+
item[importDef.updateMapping.originalIdField] ||
|
|
884
|
+
transformedData[importDef.updateMapping.originalIdField];
|
|
882
885
|
if (oldId) {
|
|
883
886
|
itemDataToUpdate = currentData?.data.find(({ context, rawData, finalData }) => {
|
|
884
887
|
const targetField = importDef.updateMapping.targetField ??
|
|
@@ -896,7 +899,9 @@ export class DataLoader {
|
|
|
896
899
|
}
|
|
897
900
|
// If updateMapping is not defined or did not find the item, use primaryKeyField
|
|
898
901
|
if (!itemDataToUpdate && importDef.primaryKeyField) {
|
|
899
|
-
oldId =
|
|
902
|
+
oldId =
|
|
903
|
+
item[importDef.primaryKeyField] ||
|
|
904
|
+
transformedData[importDef.primaryKeyField];
|
|
900
905
|
if (oldId) {
|
|
901
906
|
newId = oldIdToNewIdMap?.get(`${oldId}`);
|
|
902
907
|
if (!newId &&
|
|
@@ -919,13 +924,14 @@ export class DataLoader {
|
|
|
919
924
|
continue;
|
|
920
925
|
}
|
|
921
926
|
if (!newId && !itemDataToUpdate) {
|
|
922
|
-
logger.error(`No new id found for collection ${collection.name} for updateDef ${JSON.stringify(item, null, 2)} but it says it's supposed to have one...`);
|
|
927
|
+
logger.error(`No new id && no data found for collection ${collection.name} for updateDef ${JSON.stringify(item, null, 2)} but it says it's supposed to have one...`);
|
|
923
928
|
continue;
|
|
924
929
|
}
|
|
925
930
|
else if (itemDataToUpdate) {
|
|
926
|
-
newId =
|
|
931
|
+
newId =
|
|
932
|
+
itemDataToUpdate.finalData.docId || itemDataToUpdate.context.docId;
|
|
927
933
|
if (!newId) {
|
|
928
|
-
logger.error(`No new id found for collection ${collection.name} for updateDef ${JSON.stringify(item, null, 2)} but it says it's supposed to have one...`);
|
|
934
|
+
logger.error(`No new id found for collection ${collection.name} for updateDef ${JSON.stringify(item, null, 2)} but has itemDataToUpdate ${JSON.stringify(itemDataToUpdate, null, 2)} but it says it's supposed to have one...`);
|
|
929
935
|
continue;
|
|
930
936
|
}
|
|
931
937
|
}
|
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.49",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -1207,13 +1207,17 @@ export class DataLoader {
|
|
|
1207
1207
|
|
|
1208
1208
|
// Try to find itemDataToUpdate using updateMapping
|
|
1209
1209
|
if (importDef.updateMapping) {
|
|
1210
|
-
|
|
1210
|
+
console.log(importDef.updateMapping);
|
|
1211
|
+
oldId =
|
|
1212
|
+
item[importDef.updateMapping.originalIdField] ||
|
|
1213
|
+
transformedData[importDef.updateMapping.originalIdField];
|
|
1211
1214
|
if (oldId) {
|
|
1212
1215
|
itemDataToUpdate = currentData?.data.find(
|
|
1213
1216
|
({ context, rawData, finalData }) => {
|
|
1214
1217
|
const targetField =
|
|
1215
1218
|
importDef.updateMapping!.targetField ??
|
|
1216
1219
|
importDef.updateMapping!.originalIdField;
|
|
1220
|
+
|
|
1217
1221
|
return (
|
|
1218
1222
|
`${context[targetField]}` === `${oldId}` ||
|
|
1219
1223
|
`${rawData[targetField]}` === `${oldId}` ||
|
|
@@ -1232,7 +1236,9 @@ export class DataLoader {
|
|
|
1232
1236
|
|
|
1233
1237
|
// If updateMapping is not defined or did not find the item, use primaryKeyField
|
|
1234
1238
|
if (!itemDataToUpdate && importDef.primaryKeyField) {
|
|
1235
|
-
oldId =
|
|
1239
|
+
oldId =
|
|
1240
|
+
item[importDef.primaryKeyField] ||
|
|
1241
|
+
transformedData[importDef.primaryKeyField];
|
|
1236
1242
|
if (oldId) {
|
|
1237
1243
|
newId = oldIdToNewIdMap?.get(`${oldId}`);
|
|
1238
1244
|
if (
|
|
@@ -1268,7 +1274,7 @@ export class DataLoader {
|
|
|
1268
1274
|
|
|
1269
1275
|
if (!newId && !itemDataToUpdate) {
|
|
1270
1276
|
logger.error(
|
|
1271
|
-
`No new id found for collection ${
|
|
1277
|
+
`No new id && no data found for collection ${
|
|
1272
1278
|
collection.name
|
|
1273
1279
|
} for updateDef ${JSON.stringify(
|
|
1274
1280
|
item,
|
|
@@ -1278,7 +1284,8 @@ export class DataLoader {
|
|
|
1278
1284
|
);
|
|
1279
1285
|
continue;
|
|
1280
1286
|
} else if (itemDataToUpdate) {
|
|
1281
|
-
newId =
|
|
1287
|
+
newId =
|
|
1288
|
+
itemDataToUpdate.finalData.docId || itemDataToUpdate.context.docId;
|
|
1282
1289
|
if (!newId) {
|
|
1283
1290
|
logger.error(
|
|
1284
1291
|
`No new id found for collection ${
|
|
@@ -1287,6 +1294,10 @@ export class DataLoader {
|
|
|
1287
1294
|
item,
|
|
1288
1295
|
null,
|
|
1289
1296
|
2
|
|
1297
|
+
)} but has itemDataToUpdate ${JSON.stringify(
|
|
1298
|
+
itemDataToUpdate,
|
|
1299
|
+
null,
|
|
1300
|
+
2
|
|
1290
1301
|
)} but it says it's supposed to have one...`
|
|
1291
1302
|
);
|
|
1292
1303
|
continue;
|