appwrite-utils-cli 0.0.54 → 0.0.55
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
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.55: Added `documentExists` check to batch creation functionality to try to prevent duplicates
|
|
135
136
|
- 0.0.54: Various fixes in here
|
|
136
137
|
- 0.0.50: Actually fixed the slight bug, it was really in the `mergeObjects`
|
|
137
138
|
- 0.0.49: Fixed a slight bug with `dataLoader` not mapping updates correctly with `updateMapping`
|
|
@@ -7,7 +7,7 @@ import { logger } from "./logging.js";
|
|
|
7
7
|
import { updateOperation } from "./migrationHelper.js";
|
|
8
8
|
import { BatchSchema, OperationCreateSchema, OperationSchema, } from "./backup.js";
|
|
9
9
|
import { DataLoader } from "./dataLoader.js";
|
|
10
|
-
import { transferDocumentsBetweenDbsLocalToLocal } from "./collections.js";
|
|
10
|
+
import { documentExists, transferDocumentsBetweenDbsLocalToLocal, } from "./collections.js";
|
|
11
11
|
import { transferDatabaseLocalToLocal } from "./databases.js";
|
|
12
12
|
import { transferStorageLocalToLocal } from "./storage.js";
|
|
13
13
|
export class ImportController {
|
|
@@ -166,7 +166,24 @@ export class ImportController {
|
|
|
166
166
|
for (let i = 0; i < dataSplit.length; i++) {
|
|
167
167
|
const batches = dataSplit[i];
|
|
168
168
|
console.log(`Processing batch ${i + 1} of ${dataSplit.length}`);
|
|
169
|
-
const
|
|
169
|
+
const documentExistsPromises = batches.map(async (item) => {
|
|
170
|
+
try {
|
|
171
|
+
const id = item.finalData.docId ||
|
|
172
|
+
item.finalData.userId ||
|
|
173
|
+
item.context.docId ||
|
|
174
|
+
item.context.userId;
|
|
175
|
+
if (!item.finalData) {
|
|
176
|
+
return Promise.resolve(null);
|
|
177
|
+
}
|
|
178
|
+
return tryAwaitWithRetry(async () => await documentExists(this.database, db.$id, collection.$id, item.finalData));
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
console.error(error);
|
|
182
|
+
return Promise.resolve(null);
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
const documentExistsResults = await Promise.all(documentExistsPromises);
|
|
186
|
+
const batchPromises = batches.map((item, index) => {
|
|
170
187
|
try {
|
|
171
188
|
const id = item.finalData.docId ||
|
|
172
189
|
item.finalData.userId ||
|
|
@@ -178,7 +195,7 @@ export class ImportController {
|
|
|
178
195
|
if (item.finalData.hasOwnProperty("docId")) {
|
|
179
196
|
delete item.finalData.docId;
|
|
180
197
|
}
|
|
181
|
-
if (!item.finalData) {
|
|
198
|
+
if (!item.finalData || documentExistsResults[index]) {
|
|
182
199
|
return Promise.resolve();
|
|
183
200
|
}
|
|
184
201
|
return tryAwaitWithRetry(async () => await this.database.createDocument(db.$id, collection.$id, id, item.finalData));
|
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.55",
|
|
5
5
|
"main": "src/main.ts",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"repository": {
|
|
@@ -26,7 +26,10 @@ import {
|
|
|
26
26
|
OperationSchema,
|
|
27
27
|
} from "./backup.js";
|
|
28
28
|
import { DataLoader, type CollectionImportData } from "./dataLoader.js";
|
|
29
|
-
import {
|
|
29
|
+
import {
|
|
30
|
+
documentExists,
|
|
31
|
+
transferDocumentsBetweenDbsLocalToLocal,
|
|
32
|
+
} from "./collections.js";
|
|
30
33
|
import { transferDatabaseLocalToLocal } from "./databases.js";
|
|
31
34
|
import { transferStorageLocalToLocal } from "./storage.js";
|
|
32
35
|
|
|
@@ -244,20 +247,50 @@ export class ImportController {
|
|
|
244
247
|
for (let i = 0; i < dataSplit.length; i++) {
|
|
245
248
|
const batches = dataSplit[i];
|
|
246
249
|
console.log(`Processing batch ${i + 1} of ${dataSplit.length}`);
|
|
247
|
-
|
|
250
|
+
|
|
251
|
+
const documentExistsPromises = batches.map(async (item) => {
|
|
248
252
|
try {
|
|
249
253
|
const id =
|
|
250
254
|
item.finalData.docId ||
|
|
251
255
|
item.finalData.userId ||
|
|
252
256
|
item.context.docId ||
|
|
253
257
|
item.context.userId;
|
|
258
|
+
|
|
259
|
+
if (!item.finalData) {
|
|
260
|
+
return Promise.resolve(null);
|
|
261
|
+
}
|
|
262
|
+
return tryAwaitWithRetry(
|
|
263
|
+
async () =>
|
|
264
|
+
await documentExists(
|
|
265
|
+
this.database,
|
|
266
|
+
db.$id,
|
|
267
|
+
collection.$id,
|
|
268
|
+
item.finalData
|
|
269
|
+
)
|
|
270
|
+
);
|
|
271
|
+
} catch (error) {
|
|
272
|
+
console.error(error);
|
|
273
|
+
return Promise.resolve(null);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
const documentExistsResults = await Promise.all(documentExistsPromises);
|
|
278
|
+
|
|
279
|
+
const batchPromises = batches.map((item, index) => {
|
|
280
|
+
try {
|
|
281
|
+
const id =
|
|
282
|
+
item.finalData.docId ||
|
|
283
|
+
item.finalData.userId ||
|
|
284
|
+
item.context.docId ||
|
|
285
|
+
item.context.userId;
|
|
286
|
+
|
|
254
287
|
if (item.finalData.hasOwnProperty("userId")) {
|
|
255
288
|
delete item.finalData.userId;
|
|
256
289
|
}
|
|
257
290
|
if (item.finalData.hasOwnProperty("docId")) {
|
|
258
291
|
delete item.finalData.docId;
|
|
259
292
|
}
|
|
260
|
-
if (!item.finalData) {
|
|
293
|
+
if (!item.finalData || documentExistsResults[index]) {
|
|
261
294
|
return Promise.resolve();
|
|
262
295
|
}
|
|
263
296
|
return tryAwaitWithRetry(
|
|
@@ -274,6 +307,7 @@ export class ImportController {
|
|
|
274
307
|
return Promise.resolve();
|
|
275
308
|
}
|
|
276
309
|
});
|
|
310
|
+
|
|
277
311
|
// Wait for all promises in the current batch to resolve
|
|
278
312
|
await Promise.all(batchPromises);
|
|
279
313
|
console.log(`Completed batch ${i + 1} of ${dataSplit.length}`);
|