appwrite-utils-cli 0.0.37 → 0.0.39
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/attributes.js +21 -20
- package/dist/migrations/collections.js +10 -13
- package/dist/migrations/converters.js +15 -1
- package/dist/migrations/dataLoader.d.ts +12 -21
- package/dist/migrations/dataLoader.js +168 -58
- package/dist/migrations/databases.js +2 -1
- package/dist/migrations/importController.js +6 -24
- package/dist/migrations/importDataActions.d.ts +9 -1
- package/dist/migrations/importDataActions.js +14 -2
- package/dist/migrations/indexes.js +2 -1
- package/dist/migrations/migrationHelper.js +2 -1
- package/dist/migrations/queue.js +3 -2
- package/dist/migrations/setupDatabase.js +10 -12
- package/dist/migrations/storage.js +14 -13
- package/dist/migrations/users.js +14 -36
- package/dist/utils/helperFunctions.d.ts +10 -1
- package/dist/utils/helperFunctions.js +27 -0
- package/dist/utilsController.js +2 -1
- package/package.json +2 -2
- package/src/migrations/attributes.ts +204 -143
- package/src/migrations/collections.ts +49 -33
- package/src/migrations/converters.ts +17 -1
- package/src/migrations/dataLoader.ts +232 -63
- package/src/migrations/databases.ts +4 -1
- package/src/migrations/importController.ts +13 -27
- package/src/migrations/importDataActions.ts +17 -3
- package/src/migrations/indexes.ts +4 -1
- package/src/migrations/migrationHelper.ts +9 -5
- package/src/migrations/queue.ts +5 -6
- package/src/migrations/setupDatabase.ts +35 -18
- package/src/migrations/storage.ts +50 -36
- package/src/migrations/users.ts +28 -38
- package/src/utils/helperFunctions.ts +33 -1
- package/src/utilsController.ts +3 -1
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from "appwrite-utils";
|
|
7
7
|
import { nameToIdMapping, enqueueOperation } from "./queue.js";
|
|
8
8
|
import _ from "lodash";
|
|
9
|
+
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
|
9
10
|
|
|
10
11
|
const attributesSame = (
|
|
11
12
|
databaseAttribute: Attribute,
|
|
@@ -149,23 +150,29 @@ export const createOrUpdateAttribute = async (
|
|
|
149
150
|
switch (finalAttribute.type) {
|
|
150
151
|
case "string":
|
|
151
152
|
if (action === "create") {
|
|
152
|
-
await
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
153
|
+
await tryAwaitWithRetry(
|
|
154
|
+
async () =>
|
|
155
|
+
await db.createStringAttribute(
|
|
156
|
+
dbId,
|
|
157
|
+
collection.$id,
|
|
158
|
+
finalAttribute.key,
|
|
159
|
+
finalAttribute.size,
|
|
160
|
+
finalAttribute.required || false,
|
|
161
|
+
(finalAttribute.xdefault as string) || undefined,
|
|
162
|
+
finalAttribute.array || false,
|
|
163
|
+
finalAttribute.encrypted
|
|
164
|
+
)
|
|
161
165
|
);
|
|
162
166
|
} else {
|
|
163
|
-
await
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
167
|
+
await tryAwaitWithRetry(
|
|
168
|
+
async () =>
|
|
169
|
+
await db.updateStringAttribute(
|
|
170
|
+
dbId,
|
|
171
|
+
collection.$id,
|
|
172
|
+
finalAttribute.key,
|
|
173
|
+
finalAttribute.required || false,
|
|
174
|
+
(finalAttribute.xdefault as string) || undefined
|
|
175
|
+
)
|
|
169
176
|
);
|
|
170
177
|
}
|
|
171
178
|
break;
|
|
@@ -183,15 +190,18 @@ export const createOrUpdateAttribute = async (
|
|
|
183
190
|
) {
|
|
184
191
|
delete finalAttribute.max;
|
|
185
192
|
}
|
|
186
|
-
await
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
193
|
+
await tryAwaitWithRetry(
|
|
194
|
+
async () =>
|
|
195
|
+
await db.createIntegerAttribute(
|
|
196
|
+
dbId,
|
|
197
|
+
collection.$id,
|
|
198
|
+
finalAttribute.key,
|
|
199
|
+
finalAttribute.required || false,
|
|
200
|
+
finalAttribute.min,
|
|
201
|
+
finalAttribute.max,
|
|
202
|
+
finalAttribute.xdefault || undefined,
|
|
203
|
+
finalAttribute.array
|
|
204
|
+
)
|
|
195
205
|
);
|
|
196
206
|
} else {
|
|
197
207
|
if (
|
|
@@ -206,181 +216,232 @@ export const createOrUpdateAttribute = async (
|
|
|
206
216
|
) {
|
|
207
217
|
delete finalAttribute.max;
|
|
208
218
|
}
|
|
209
|
-
await
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
219
|
+
await tryAwaitWithRetry(
|
|
220
|
+
async () =>
|
|
221
|
+
await db.updateIntegerAttribute(
|
|
222
|
+
dbId,
|
|
223
|
+
collection.$id,
|
|
224
|
+
finalAttribute.key,
|
|
225
|
+
finalAttribute.required || false,
|
|
226
|
+
finalAttribute.min || 0,
|
|
227
|
+
finalAttribute.max || 2147483647,
|
|
228
|
+
finalAttribute.xdefault || undefined
|
|
229
|
+
)
|
|
217
230
|
);
|
|
218
231
|
}
|
|
219
232
|
break;
|
|
220
233
|
case "float":
|
|
221
234
|
if (action === "create") {
|
|
222
|
-
await
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
235
|
+
await tryAwaitWithRetry(
|
|
236
|
+
async () =>
|
|
237
|
+
await db.createFloatAttribute(
|
|
238
|
+
dbId,
|
|
239
|
+
collection.$id,
|
|
240
|
+
finalAttribute.key,
|
|
241
|
+
finalAttribute.required || false,
|
|
242
|
+
finalAttribute.min,
|
|
243
|
+
finalAttribute.max,
|
|
244
|
+
finalAttribute.xdefault || undefined,
|
|
245
|
+
finalAttribute.array
|
|
246
|
+
)
|
|
231
247
|
);
|
|
232
248
|
} else {
|
|
233
|
-
await
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
249
|
+
await tryAwaitWithRetry(
|
|
250
|
+
async () =>
|
|
251
|
+
await db.updateFloatAttribute(
|
|
252
|
+
dbId,
|
|
253
|
+
collection.$id,
|
|
254
|
+
finalAttribute.key,
|
|
255
|
+
finalAttribute.required || false,
|
|
256
|
+
finalAttribute.min || 0,
|
|
257
|
+
finalAttribute.max || 2147483647,
|
|
258
|
+
finalAttribute.xdefault || undefined
|
|
259
|
+
)
|
|
241
260
|
);
|
|
242
261
|
}
|
|
243
262
|
break;
|
|
244
263
|
case "boolean":
|
|
245
264
|
if (action === "create") {
|
|
246
|
-
await
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
265
|
+
await tryAwaitWithRetry(
|
|
266
|
+
async () =>
|
|
267
|
+
await db.createBooleanAttribute(
|
|
268
|
+
dbId,
|
|
269
|
+
collection.$id,
|
|
270
|
+
finalAttribute.key,
|
|
271
|
+
finalAttribute.required || false,
|
|
272
|
+
finalAttribute.xdefault || undefined,
|
|
273
|
+
finalAttribute.array
|
|
274
|
+
)
|
|
253
275
|
);
|
|
254
276
|
} else {
|
|
255
|
-
await
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
277
|
+
await tryAwaitWithRetry(
|
|
278
|
+
async () =>
|
|
279
|
+
await db.updateBooleanAttribute(
|
|
280
|
+
dbId,
|
|
281
|
+
collection.$id,
|
|
282
|
+
finalAttribute.key,
|
|
283
|
+
finalAttribute.required || false,
|
|
284
|
+
finalAttribute.xdefault || null
|
|
285
|
+
)
|
|
261
286
|
);
|
|
262
287
|
}
|
|
263
288
|
break;
|
|
264
289
|
case "datetime":
|
|
265
290
|
if (action === "create") {
|
|
266
|
-
await
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
291
|
+
await tryAwaitWithRetry(
|
|
292
|
+
async () =>
|
|
293
|
+
await db.createDatetimeAttribute(
|
|
294
|
+
dbId,
|
|
295
|
+
collection.$id,
|
|
296
|
+
finalAttribute.key,
|
|
297
|
+
finalAttribute.required || false,
|
|
298
|
+
finalAttribute.xdefault || undefined,
|
|
299
|
+
finalAttribute.array
|
|
300
|
+
)
|
|
273
301
|
);
|
|
274
302
|
} else {
|
|
275
|
-
await
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
303
|
+
await tryAwaitWithRetry(
|
|
304
|
+
async () =>
|
|
305
|
+
await db.updateDatetimeAttribute(
|
|
306
|
+
dbId,
|
|
307
|
+
collection.$id,
|
|
308
|
+
finalAttribute.key,
|
|
309
|
+
finalAttribute.required || false,
|
|
310
|
+
finalAttribute.xdefault || undefined
|
|
311
|
+
)
|
|
281
312
|
);
|
|
282
313
|
}
|
|
283
314
|
break;
|
|
284
315
|
case "email":
|
|
285
316
|
if (action === "create") {
|
|
286
|
-
await
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
317
|
+
await tryAwaitWithRetry(
|
|
318
|
+
async () =>
|
|
319
|
+
await db.createEmailAttribute(
|
|
320
|
+
dbId,
|
|
321
|
+
collection.$id,
|
|
322
|
+
finalAttribute.key,
|
|
323
|
+
finalAttribute.required || false,
|
|
324
|
+
finalAttribute.xdefault || undefined,
|
|
325
|
+
finalAttribute.array
|
|
326
|
+
)
|
|
293
327
|
);
|
|
294
328
|
} else {
|
|
295
|
-
await
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
329
|
+
await tryAwaitWithRetry(
|
|
330
|
+
async () =>
|
|
331
|
+
await db.updateEmailAttribute(
|
|
332
|
+
dbId,
|
|
333
|
+
collection.$id,
|
|
334
|
+
finalAttribute.key,
|
|
335
|
+
finalAttribute.required || false,
|
|
336
|
+
finalAttribute.xdefault || undefined
|
|
337
|
+
)
|
|
301
338
|
);
|
|
302
339
|
}
|
|
303
340
|
break;
|
|
304
341
|
case "ip":
|
|
305
342
|
if (action === "create") {
|
|
306
|
-
await
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
343
|
+
await tryAwaitWithRetry(
|
|
344
|
+
async () =>
|
|
345
|
+
await db.createIpAttribute(
|
|
346
|
+
dbId,
|
|
347
|
+
collection.$id,
|
|
348
|
+
finalAttribute.key,
|
|
349
|
+
finalAttribute.required || false,
|
|
350
|
+
finalAttribute.xdefault || undefined,
|
|
351
|
+
finalAttribute.array
|
|
352
|
+
)
|
|
313
353
|
);
|
|
314
354
|
} else {
|
|
315
|
-
await
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
355
|
+
await tryAwaitWithRetry(
|
|
356
|
+
async () =>
|
|
357
|
+
await db.updateIpAttribute(
|
|
358
|
+
dbId,
|
|
359
|
+
collection.$id,
|
|
360
|
+
finalAttribute.key,
|
|
361
|
+
finalAttribute.required || false,
|
|
362
|
+
finalAttribute.xdefault || undefined
|
|
363
|
+
)
|
|
321
364
|
);
|
|
322
365
|
}
|
|
323
366
|
break;
|
|
324
367
|
case "url":
|
|
325
368
|
if (action === "create") {
|
|
326
|
-
await
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
369
|
+
await tryAwaitWithRetry(
|
|
370
|
+
async () =>
|
|
371
|
+
await db.createUrlAttribute(
|
|
372
|
+
dbId,
|
|
373
|
+
collection.$id,
|
|
374
|
+
finalAttribute.key,
|
|
375
|
+
finalAttribute.required || false,
|
|
376
|
+
finalAttribute.xdefault || undefined,
|
|
377
|
+
finalAttribute.array
|
|
378
|
+
)
|
|
333
379
|
);
|
|
334
380
|
} else {
|
|
335
|
-
await
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
381
|
+
await tryAwaitWithRetry(
|
|
382
|
+
async () =>
|
|
383
|
+
await db.updateUrlAttribute(
|
|
384
|
+
dbId,
|
|
385
|
+
collection.$id,
|
|
386
|
+
finalAttribute.key,
|
|
387
|
+
finalAttribute.required || false,
|
|
388
|
+
finalAttribute.xdefault || undefined
|
|
389
|
+
)
|
|
341
390
|
);
|
|
342
391
|
}
|
|
343
392
|
break;
|
|
344
393
|
case "enum":
|
|
345
394
|
if (action === "create") {
|
|
346
|
-
await
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
395
|
+
await tryAwaitWithRetry(
|
|
396
|
+
async () =>
|
|
397
|
+
await db.createEnumAttribute(
|
|
398
|
+
dbId,
|
|
399
|
+
collection.$id,
|
|
400
|
+
finalAttribute.key,
|
|
401
|
+
finalAttribute.elements,
|
|
402
|
+
finalAttribute.required || false,
|
|
403
|
+
finalAttribute.xdefault || undefined,
|
|
404
|
+
finalAttribute.array
|
|
405
|
+
)
|
|
354
406
|
);
|
|
355
407
|
} else {
|
|
356
|
-
await
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
408
|
+
await tryAwaitWithRetry(
|
|
409
|
+
async () =>
|
|
410
|
+
await db.updateEnumAttribute(
|
|
411
|
+
dbId,
|
|
412
|
+
collection.$id,
|
|
413
|
+
finalAttribute.key,
|
|
414
|
+
finalAttribute.elements,
|
|
415
|
+
finalAttribute.required || false,
|
|
416
|
+
finalAttribute.xdefault || undefined
|
|
417
|
+
)
|
|
363
418
|
);
|
|
364
419
|
}
|
|
365
420
|
break;
|
|
366
421
|
case "relationship":
|
|
367
422
|
if (action === "create") {
|
|
368
|
-
await
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
423
|
+
await tryAwaitWithRetry(
|
|
424
|
+
async () =>
|
|
425
|
+
await db.createRelationshipAttribute(
|
|
426
|
+
dbId,
|
|
427
|
+
collection.$id,
|
|
428
|
+
relatedCollectionId!,
|
|
429
|
+
finalAttribute.relationType,
|
|
430
|
+
finalAttribute.twoWay,
|
|
431
|
+
finalAttribute.key,
|
|
432
|
+
finalAttribute.twoWayKey,
|
|
433
|
+
finalAttribute.onDelete
|
|
434
|
+
)
|
|
377
435
|
);
|
|
378
436
|
} else {
|
|
379
|
-
await
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
437
|
+
await tryAwaitWithRetry(
|
|
438
|
+
async () =>
|
|
439
|
+
await db.updateRelationshipAttribute(
|
|
440
|
+
dbId,
|
|
441
|
+
collection.$id,
|
|
442
|
+
finalAttribute.key,
|
|
443
|
+
finalAttribute.onDelete
|
|
444
|
+
)
|
|
384
445
|
);
|
|
385
446
|
}
|
|
386
447
|
break;
|
|
@@ -5,6 +5,7 @@ import { createUpdateCollectionAttributes } from "./attributes.js";
|
|
|
5
5
|
import { createOrUpdateIndexes } from "./indexes.js";
|
|
6
6
|
import _ from "lodash";
|
|
7
7
|
import { SchemaGenerator } from "./schemaStrings.js";
|
|
8
|
+
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
|
8
9
|
|
|
9
10
|
export const documentExists = async (
|
|
10
11
|
db: Databases,
|
|
@@ -69,9 +70,10 @@ export const checkForCollection = async (
|
|
|
69
70
|
): Promise<Models.Collection | null> => {
|
|
70
71
|
try {
|
|
71
72
|
console.log(`Checking for collection with name: ${collection.name}`);
|
|
72
|
-
const response = await
|
|
73
|
-
|
|
74
|
-
|
|
73
|
+
const response = await tryAwaitWithRetry(
|
|
74
|
+
async () =>
|
|
75
|
+
await db.listCollections(dbId, [Query.equal("name", collection.name!)])
|
|
76
|
+
);
|
|
75
77
|
if (response.collections.length > 0) {
|
|
76
78
|
console.log(`Collection found: ${response.collections[0].$id}`);
|
|
77
79
|
return { ...collection, ...response.collections[0] };
|
|
@@ -94,12 +96,15 @@ export const fetchAndCacheCollectionByName = async (
|
|
|
94
96
|
if (nameToIdMapping.has(collectionName)) {
|
|
95
97
|
const collectionId = nameToIdMapping.get(collectionName);
|
|
96
98
|
console.log(`\tCollection found in cache: ${collectionId}`);
|
|
97
|
-
return await
|
|
99
|
+
return await tryAwaitWithRetry(
|
|
100
|
+
async () => await db.getCollection(dbId, collectionId!)
|
|
101
|
+
);
|
|
98
102
|
} else {
|
|
99
103
|
console.log(`\tFetching collection by name: ${collectionName}`);
|
|
100
|
-
const collectionsPulled = await
|
|
101
|
-
|
|
102
|
-
|
|
104
|
+
const collectionsPulled = await tryAwaitWithRetry(
|
|
105
|
+
async () =>
|
|
106
|
+
await db.listCollections(dbId, [Query.equal("name", collectionName)])
|
|
107
|
+
);
|
|
103
108
|
if (collectionsPulled.total > 0) {
|
|
104
109
|
const collection = collectionsPulled.collections[0];
|
|
105
110
|
console.log(`\tCollection found: ${collection.$id}`);
|
|
@@ -117,8 +122,8 @@ export const wipeDatabase = async (
|
|
|
117
122
|
databaseId: string
|
|
118
123
|
): Promise<{ collectionId: string; collectionName: string }[]> => {
|
|
119
124
|
console.log(`Wiping database: ${databaseId}`);
|
|
120
|
-
const { collections: existingCollections } = await
|
|
121
|
-
databaseId
|
|
125
|
+
const { collections: existingCollections } = await tryAwaitWithRetry(
|
|
126
|
+
async () => await database.listCollections(databaseId)
|
|
122
127
|
);
|
|
123
128
|
let collectionsDeleted: { collectionId: string; collectionName: string }[] =
|
|
124
129
|
[];
|
|
@@ -155,7 +160,7 @@ export const createOrUpdateCollections = async (
|
|
|
155
160
|
|
|
156
161
|
for (const { attributes, indexes, ...collection } of configCollections) {
|
|
157
162
|
// Prepare permissions for the collection
|
|
158
|
-
const permissions = [];
|
|
163
|
+
const permissions: string[] = [];
|
|
159
164
|
if (collection.$permissions && collection.$permissions.length > 0) {
|
|
160
165
|
for (const permission of collection.$permissions) {
|
|
161
166
|
switch (permission.permission) {
|
|
@@ -182,15 +187,18 @@ export const createOrUpdateCollections = async (
|
|
|
182
187
|
}
|
|
183
188
|
|
|
184
189
|
// Check if the collection already exists by name
|
|
185
|
-
let collectionsFound = await
|
|
186
|
-
|
|
187
|
-
|
|
190
|
+
let collectionsFound = await tryAwaitWithRetry(
|
|
191
|
+
async () =>
|
|
192
|
+
await database.listCollections(databaseId, [
|
|
193
|
+
Query.equal("name", collection.name),
|
|
194
|
+
])
|
|
195
|
+
);
|
|
188
196
|
|
|
189
197
|
let collectionToUse =
|
|
190
198
|
collectionsFound.total > 0 ? collectionsFound.collections[0] : null;
|
|
191
199
|
|
|
192
200
|
// Determine the correct ID for the collection
|
|
193
|
-
let collectionId;
|
|
201
|
+
let collectionId: string;
|
|
194
202
|
if (!collectionToUse) {
|
|
195
203
|
console.log(`Creating collection: ${collection.name}`);
|
|
196
204
|
const foundColl = deletedCollections?.find(
|
|
@@ -211,16 +219,19 @@ export const createOrUpdateCollections = async (
|
|
|
211
219
|
|
|
212
220
|
// Create the collection with the determined ID
|
|
213
221
|
try {
|
|
214
|
-
collectionToUse = await
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
222
|
+
collectionToUse = await tryAwaitWithRetry(
|
|
223
|
+
async () =>
|
|
224
|
+
await database.createCollection(
|
|
225
|
+
databaseId,
|
|
226
|
+
collectionId,
|
|
227
|
+
collection.name,
|
|
228
|
+
permissions,
|
|
229
|
+
collection.documentSecurity ?? false,
|
|
230
|
+
collection.enabled ?? true
|
|
231
|
+
)
|
|
221
232
|
);
|
|
222
|
-
collection.$id = collectionToUse
|
|
223
|
-
nameToIdMapping.set(collection.name, collectionToUse
|
|
233
|
+
collection.$id = collectionToUse!.$id;
|
|
234
|
+
nameToIdMapping.set(collection.name, collectionToUse!.$id);
|
|
224
235
|
} catch (error) {
|
|
225
236
|
console.error(
|
|
226
237
|
`Failed to create collection ${collection.name} with ID ${collectionId}: ${error}`
|
|
@@ -229,13 +240,16 @@ export const createOrUpdateCollections = async (
|
|
|
229
240
|
}
|
|
230
241
|
} else {
|
|
231
242
|
console.log(`Collection ${collection.name} exists, updating it`);
|
|
232
|
-
await
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
243
|
+
await tryAwaitWithRetry(
|
|
244
|
+
async () =>
|
|
245
|
+
await database.updateCollection(
|
|
246
|
+
databaseId,
|
|
247
|
+
collectionToUse!.$id,
|
|
248
|
+
collection.name,
|
|
249
|
+
permissions,
|
|
250
|
+
collection.documentSecurity ?? false,
|
|
251
|
+
collection.enabled ?? true
|
|
252
|
+
)
|
|
239
253
|
);
|
|
240
254
|
}
|
|
241
255
|
|
|
@@ -244,14 +258,14 @@ export const createOrUpdateCollections = async (
|
|
|
244
258
|
await createUpdateCollectionAttributes(
|
|
245
259
|
database,
|
|
246
260
|
databaseId,
|
|
247
|
-
collectionToUse
|
|
261
|
+
collectionToUse!,
|
|
248
262
|
attributes
|
|
249
263
|
);
|
|
250
264
|
console.log("Creating Indexes");
|
|
251
265
|
await createOrUpdateIndexes(
|
|
252
266
|
databaseId,
|
|
253
267
|
database,
|
|
254
|
-
collectionToUse
|
|
268
|
+
collectionToUse!.$id,
|
|
255
269
|
indexes ?? []
|
|
256
270
|
);
|
|
257
271
|
}
|
|
@@ -294,7 +308,9 @@ export const fetchAllCollections = async (
|
|
|
294
308
|
if (lastCollectionId) {
|
|
295
309
|
queries.push(Query.cursorAfter(lastCollectionId));
|
|
296
310
|
}
|
|
297
|
-
const response = await
|
|
311
|
+
const response = await tryAwaitWithRetry(
|
|
312
|
+
async () => await database.listCollections(dbId, queries)
|
|
313
|
+
);
|
|
298
314
|
collections = collections.concat(response.collections);
|
|
299
315
|
moreCollections = response.collections.length === 500;
|
|
300
316
|
if (moreCollections) {
|
|
@@ -108,7 +108,13 @@ export const convertObjectByAttributeMappings = (
|
|
|
108
108
|
const values = mapping.oldKeys
|
|
109
109
|
.map((oldKey) => resolveValue(obj, oldKey))
|
|
110
110
|
.flat(Infinity);
|
|
111
|
-
|
|
111
|
+
if (values.length > 0) {
|
|
112
|
+
result[mapping.targetKey] = values.filter(
|
|
113
|
+
(value) => value !== undefined
|
|
114
|
+
);
|
|
115
|
+
} else {
|
|
116
|
+
result[mapping.targetKey] = null;
|
|
117
|
+
}
|
|
112
118
|
} else if (mapping.oldKey) {
|
|
113
119
|
// Resolve single oldKey
|
|
114
120
|
const value = resolveValue(obj, mapping.oldKey);
|
|
@@ -116,9 +122,19 @@ export const convertObjectByAttributeMappings = (
|
|
|
116
122
|
result[mapping.targetKey] = Array.isArray(value)
|
|
117
123
|
? value.flat(Infinity)
|
|
118
124
|
: value;
|
|
125
|
+
} else {
|
|
126
|
+
result[mapping.targetKey] = null;
|
|
119
127
|
}
|
|
120
128
|
}
|
|
121
129
|
}
|
|
130
|
+
|
|
131
|
+
// Ensure any keys in the original object that are not mapped are copied over
|
|
132
|
+
for (const key of Object.keys(obj)) {
|
|
133
|
+
if (!Object.keys(result).includes(key)) {
|
|
134
|
+
result[key] = obj[key];
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
122
138
|
return result;
|
|
123
139
|
};
|
|
124
140
|
|