appwrite-utils-cli 0.0.259 → 0.0.261
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/dataLoader.js +15 -15
- package/package.json +1 -1
- package/src/migrations/dataLoader.ts +27 -16
@@ -436,16 +436,11 @@ export class DataLoader {
|
|
436
436
|
}
|
437
437
|
});
|
438
438
|
const usersMap = this.importMap.get(this.getCollectionKey("users"));
|
439
|
-
if (usersMap) {
|
440
|
-
usersMap.data.push({
|
441
|
-
rawData: item,
|
442
|
-
finalData: userData.data,
|
443
|
-
});
|
444
|
-
}
|
445
439
|
const userDataToAdd = {
|
446
440
|
rawData: item,
|
447
441
|
finalData: userData.data,
|
448
442
|
};
|
443
|
+
// Directly update the importMap with the new user data, without pushing to usersMap.data first
|
449
444
|
this.importMap.set(this.getCollectionKey("users"), {
|
450
445
|
data: [...(usersMap?.data || []), userDataToAdd],
|
451
446
|
});
|
@@ -517,7 +512,7 @@ export class DataLoader {
|
|
517
512
|
for (const data of currentData.data) {
|
518
513
|
if (data.finalData.docId === oldId ||
|
519
514
|
data.finalData.userId === oldId) {
|
520
|
-
|
515
|
+
transformedItem = this.mergeObjects(data.finalData, transformedItem);
|
521
516
|
}
|
522
517
|
}
|
523
518
|
}
|
@@ -533,8 +528,7 @@ export class DataLoader {
|
|
533
528
|
if ((currentUserData.data[i].finalData.docId === existingId ||
|
534
529
|
currentUserData.data[i].finalData.userId === existingId) &&
|
535
530
|
!_.isEqual(currentUserData.data[i], userData)) {
|
536
|
-
|
537
|
-
Object.assign(currentUserData.data[i].rawData, item);
|
531
|
+
this.mergeObjects(currentUserData.data[i].finalData, userData.finalData);
|
538
532
|
console.log("Merging user data", currentUserData.data[i].finalData);
|
539
533
|
this.importMap.set(this.getCollectionKey("users"), currentUserData);
|
540
534
|
}
|
@@ -550,10 +544,8 @@ export class DataLoader {
|
|
550
544
|
for (let i = 0; i < currentData.data.length; i++) {
|
551
545
|
if (currentData.data[i].finalData.docId === existingId ||
|
552
546
|
currentData.data[i].finalData.userId === existingId) {
|
553
|
-
currentData.data[i].finalData =
|
554
|
-
|
555
|
-
...transformedItem,
|
556
|
-
};
|
547
|
+
currentData.data[i].finalData = this.mergeObjects(currentData.data[i].finalData, transformedItem);
|
548
|
+
currentData.data[i].context = context;
|
557
549
|
currentData.data[i].importDef = newImportDef;
|
558
550
|
this.importMap.set(this.getCollectionKey(collection.name), currentData);
|
559
551
|
this.oldIdToNewIdPerCollectionMap.set(this.getCollectionKey(collection.name), collectionOldIdToNewIdMap);
|
@@ -736,15 +728,23 @@ export class DataLoader {
|
|
736
728
|
attributeMappings: mappingsWithActions,
|
737
729
|
};
|
738
730
|
// Add the item with its context and final data to the current collection data
|
739
|
-
if (
|
731
|
+
if (itemDataToUpdate) {
|
732
|
+
// Update the existing item's finalData and context in place
|
733
|
+
itemDataToUpdate.finalData = this.mergeObjects(itemDataToUpdate.finalData, transformedData);
|
734
|
+
itemDataToUpdate.context = context;
|
735
|
+
itemDataToUpdate.importDef = newImportDef;
|
736
|
+
}
|
737
|
+
else {
|
738
|
+
// If no existing item matches, then add the new item
|
740
739
|
currentData.data.push({
|
741
740
|
rawData: item,
|
742
741
|
context: context,
|
743
742
|
importDef: newImportDef,
|
744
743
|
finalData: transformedData,
|
745
744
|
});
|
746
|
-
this.importMap.set(this.getCollectionKey(collection.name), currentData);
|
747
745
|
}
|
746
|
+
// Since we're modifying currentData in place, we ensure no duplicates are added
|
747
|
+
this.importMap.set(this.getCollectionKey(collection.name), currentData);
|
748
748
|
}
|
749
749
|
}
|
750
750
|
updateReferencesBasedOnAttributeMappings() {
|
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.261",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -550,16 +550,11 @@ export class DataLoader {
|
|
550
550
|
}
|
551
551
|
});
|
552
552
|
const usersMap = this.importMap.get(this.getCollectionKey("users"));
|
553
|
-
if (usersMap) {
|
554
|
-
usersMap.data.push({
|
555
|
-
rawData: item,
|
556
|
-
finalData: userData.data,
|
557
|
-
});
|
558
|
-
}
|
559
553
|
const userDataToAdd = {
|
560
554
|
rawData: item,
|
561
555
|
finalData: userData.data,
|
562
556
|
};
|
557
|
+
// Directly update the importMap with the new user data, without pushing to usersMap.data first
|
563
558
|
this.importMap.set(this.getCollectionKey("users"), {
|
564
559
|
data: [...(usersMap?.data || []), userDataToAdd],
|
565
560
|
});
|
@@ -672,7 +667,10 @@ export class DataLoader {
|
|
672
667
|
data.finalData.docId === oldId ||
|
673
668
|
data.finalData.userId === oldId
|
674
669
|
) {
|
675
|
-
|
670
|
+
transformedItem = this.mergeObjects(
|
671
|
+
data.finalData,
|
672
|
+
transformedItem
|
673
|
+
);
|
676
674
|
}
|
677
675
|
}
|
678
676
|
} else {
|
@@ -690,8 +688,10 @@ export class DataLoader {
|
|
690
688
|
currentUserData.data[i].finalData.userId === existingId) &&
|
691
689
|
!_.isEqual(currentUserData.data[i], userData)
|
692
690
|
) {
|
693
|
-
|
694
|
-
|
691
|
+
this.mergeObjects(
|
692
|
+
currentUserData.data[i].finalData,
|
693
|
+
userData.finalData
|
694
|
+
);
|
695
695
|
console.log("Merging user data", currentUserData.data[i].finalData);
|
696
696
|
this.importMap.set(this.getCollectionKey("users"), currentUserData);
|
697
697
|
}
|
@@ -714,10 +714,11 @@ export class DataLoader {
|
|
714
714
|
currentData.data[i].finalData.docId === existingId ||
|
715
715
|
currentData.data[i].finalData.userId === existingId
|
716
716
|
) {
|
717
|
-
currentData.data[i].finalData =
|
718
|
-
|
719
|
-
|
720
|
-
|
717
|
+
currentData.data[i].finalData = this.mergeObjects(
|
718
|
+
currentData.data[i].finalData,
|
719
|
+
transformedItem
|
720
|
+
);
|
721
|
+
currentData.data[i].context = context;
|
721
722
|
currentData.data[i].importDef = newImportDef;
|
722
723
|
this.importMap.set(
|
723
724
|
this.getCollectionKey(collection.name),
|
@@ -998,15 +999,25 @@ export class DataLoader {
|
|
998
999
|
attributeMappings: mappingsWithActions,
|
999
1000
|
};
|
1000
1001
|
// Add the item with its context and final data to the current collection data
|
1001
|
-
if (
|
1002
|
-
|
1002
|
+
if (itemDataToUpdate) {
|
1003
|
+
// Update the existing item's finalData and context in place
|
1004
|
+
itemDataToUpdate.finalData = this.mergeObjects(
|
1005
|
+
itemDataToUpdate.finalData,
|
1006
|
+
transformedData
|
1007
|
+
);
|
1008
|
+
itemDataToUpdate.context = context;
|
1009
|
+
itemDataToUpdate.importDef = newImportDef;
|
1010
|
+
} else {
|
1011
|
+
// If no existing item matches, then add the new item
|
1012
|
+
currentData!.data.push({
|
1003
1013
|
rawData: item,
|
1004
1014
|
context: context,
|
1005
1015
|
importDef: newImportDef,
|
1006
1016
|
finalData: transformedData,
|
1007
1017
|
});
|
1008
|
-
this.importMap.set(this.getCollectionKey(collection.name), currentData);
|
1009
1018
|
}
|
1019
|
+
// Since we're modifying currentData in place, we ensure no duplicates are added
|
1020
|
+
this.importMap.set(this.getCollectionKey(collection.name), currentData!);
|
1010
1021
|
}
|
1011
1022
|
}
|
1012
1023
|
|