appwrite-utils-cli 0.0.69 → 0.0.71
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 +2 -0
- package/dist/migrations/afterImportActions.js +4 -3
- package/dist/migrations/databases.js +1 -1
- package/dist/migrations/importDataActions.js +1 -1
- package/dist/migrations/indexes.js +1 -1
- package/dist/migrations/storage.js +29 -4
- package/package.json +3 -3
- package/src/migrations/afterImportActions.ts +4 -3
- package/src/migrations/databases.ts +9 -3
- package/src/migrations/importDataActions.ts +1 -7
- package/src/migrations/indexes.ts +2 -2
- package/src/migrations/storage.ts +30 -4
package/README.md
CHANGED
@@ -132,6 +132,8 @@ This setup ensures that developers have robust tools at their fingertips to mana
|
|
132
132
|
|
133
133
|
### Changelog
|
134
134
|
|
135
|
+
- 0.0.71: Slight change to file download logic after errors
|
136
|
+
- 0.0.70: Bump to `node-appwrite` version
|
135
137
|
- 0.0.69: Fixed single ID not getting replaced due to the below change =D also, `nice`
|
136
138
|
- 0.0.68: Fixed the occasional case where, when mapping ID's from old data to new, there would be an array of ID's to match against. `idMappings` now supports arrays.
|
137
139
|
- 0.0.67: Fixed `updates` in `importDef`'s update mappings overwriting postImportActions from the original
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Databases, Storage,
|
1
|
+
import { Databases, Storage, Query, ID, Client, Compression, } from "node-appwrite";
|
2
|
+
import { InputFile } from "node-appwrite/file";
|
2
3
|
import path from "path";
|
3
4
|
import fs from "fs";
|
4
5
|
import os from "os";
|
@@ -208,11 +209,11 @@ export const afterImportActions = {
|
|
208
209
|
return await tryAwaitWithRetry(async () => await storage.getBucket(bucketId));
|
209
210
|
}
|
210
211
|
catch (error) {
|
211
|
-
return await tryAwaitWithRetry(async () => await storage.createBucket(bucketId, bucketName, permissions, fileSecurity, enabled, maxFileSize, allowedExtensions, compression, encryption, antivirus));
|
212
|
+
return await tryAwaitWithRetry(async () => await storage.createBucket(bucketId, bucketName, permissions, fileSecurity, enabled, maxFileSize, allowedExtensions, compression ? Compression.Gzip : undefined, encryption, antivirus));
|
212
213
|
}
|
213
214
|
}
|
214
215
|
else {
|
215
|
-
return await tryAwaitWithRetry(async () => await storage.createBucket(bucketId || ID.unique(), bucketName, permissions, fileSecurity, enabled, maxFileSize, allowedExtensions, compression, encryption, antivirus));
|
216
|
+
return await tryAwaitWithRetry(async () => await storage.createBucket(bucketId || ID.unique(), bucketName, permissions, fileSecurity, enabled, maxFileSize, allowedExtensions, compression ? Compression.Gzip : undefined, encryption, antivirus));
|
216
217
|
}
|
217
218
|
}
|
218
219
|
catch (error) {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import { Client, Databases, Query } from "node-appwrite";
|
1
|
+
import { Client, Databases, IndexType, Query, } from "node-appwrite";
|
2
2
|
import { getAppwriteClient, tryAwaitWithRetry, } from "../utils/helperFunctions.js";
|
3
3
|
import { transferDocumentsBetweenDbsLocalToLocal, transferDocumentsBetweenDbsLocalToRemote, } from "./collections.js";
|
4
4
|
import { createOrUpdateAttribute } from "./attributes.js";
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { indexSchema } from "appwrite-utils";
|
2
|
-
import { Databases, Query } from "node-appwrite";
|
2
|
+
import { Databases, IndexType, Query } from "node-appwrite";
|
3
3
|
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
4
4
|
// import {}
|
5
5
|
export const createOrUpdateIndex = async (dbId, db, collectionId, index) => {
|
@@ -1,4 +1,5 @@
|
|
1
|
-
import { Storage, Databases, Query,
|
1
|
+
import { Storage, Databases, Query, ID, Permission, } from "node-appwrite";
|
2
|
+
import { InputFile } from "node-appwrite/file";
|
2
3
|
import {} from "./backup.js";
|
3
4
|
import { splitIntoBatches } from "./migrationHelper.js";
|
4
5
|
import { getAppwriteClient, tryAwaitWithRetry, } from "../utils/helperFunctions.js";
|
@@ -251,9 +252,27 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
251
252
|
let fromFiles = await tryAwaitWithRetry(async () => await storage.listFiles(fromBucketId, [Query.limit(100)]));
|
252
253
|
const allFromFiles = fromFiles.files;
|
253
254
|
let numberOfFiles = 0;
|
255
|
+
const downloadFileWithRetry = async (bucketId, fileId) => {
|
256
|
+
let attempts = 3;
|
257
|
+
while (attempts > 0) {
|
258
|
+
try {
|
259
|
+
return await storage.getFileDownload(bucketId, fileId);
|
260
|
+
}
|
261
|
+
catch (error) {
|
262
|
+
console.error(`Error downloading file ${fileId}: ${error}`);
|
263
|
+
attempts--;
|
264
|
+
if (attempts === 0)
|
265
|
+
throw error;
|
266
|
+
}
|
267
|
+
}
|
268
|
+
};
|
254
269
|
if (fromFiles.files.length < 100) {
|
255
270
|
for (const file of allFromFiles) {
|
256
|
-
const fileData = await tryAwaitWithRetry(async () => await
|
271
|
+
const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
|
272
|
+
if (!fileData) {
|
273
|
+
console.error(`Error downloading file ${file.$id}`);
|
274
|
+
continue;
|
275
|
+
}
|
257
276
|
const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
|
258
277
|
console.log(`Creating file: ${file.name}`);
|
259
278
|
tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
|
@@ -276,7 +295,11 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
276
295
|
}
|
277
296
|
}
|
278
297
|
for (const file of allFromFiles) {
|
279
|
-
const fileData = await tryAwaitWithRetry(async () => await
|
298
|
+
const fileData = await tryAwaitWithRetry(async () => await downloadFileWithRetry(file.bucketId, file.$id));
|
299
|
+
if (!fileData) {
|
300
|
+
console.error(`Error downloading file ${file.$id}`);
|
301
|
+
continue;
|
302
|
+
}
|
280
303
|
const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
|
281
304
|
await tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
|
282
305
|
numberOfFiles++;
|
@@ -307,7 +330,9 @@ export const transferStorageLocalToRemote = async (localStorage, endpoint, proje
|
|
307
330
|
}
|
308
331
|
}
|
309
332
|
for (const file of allFromFiles) {
|
310
|
-
await tryAwaitWithRetry(async () => await
|
333
|
+
const fileData = await tryAwaitWithRetry(async () => await localStorage.getFileDownload(file.bucketId, file.$id));
|
334
|
+
const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
|
335
|
+
await tryAwaitWithRetry(async () => await remoteStorage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
|
311
336
|
numberOfFiles++;
|
312
337
|
}
|
313
338
|
console.log(`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`);
|
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.71",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -33,14 +33,14 @@
|
|
33
33
|
},
|
34
34
|
"dependencies": {
|
35
35
|
"@types/inquirer": "^9.0.7",
|
36
|
-
"appwrite-utils": "^0.3.
|
36
|
+
"appwrite-utils": "^0.3.6",
|
37
37
|
"commander": "^12.0.0",
|
38
38
|
"inquirer": "^9.2.20",
|
39
39
|
"js-yaml": "^4.1.0",
|
40
40
|
"lodash": "^4.17.21",
|
41
41
|
"luxon": "^3.4.4",
|
42
42
|
"nanostores": "^0.10.3",
|
43
|
-
"node-appwrite": "^
|
43
|
+
"node-appwrite": "^13.0.0",
|
44
44
|
"tsx": "^4.9.3",
|
45
45
|
"ulid": "^2.3.0",
|
46
46
|
"winston": "^3.13.0",
|
@@ -1,12 +1,13 @@
|
|
1
1
|
import {
|
2
2
|
Databases,
|
3
3
|
Storage,
|
4
|
-
InputFile,
|
5
4
|
Query,
|
6
5
|
ID,
|
7
6
|
type Models,
|
8
7
|
Client,
|
8
|
+
Compression,
|
9
9
|
} from "node-appwrite";
|
10
|
+
import { InputFile } from "node-appwrite/file";
|
10
11
|
import path from "path";
|
11
12
|
import fs from "fs";
|
12
13
|
import os from "os";
|
@@ -385,7 +386,7 @@ export const afterImportActions = {
|
|
385
386
|
enabled,
|
386
387
|
maxFileSize,
|
387
388
|
allowedExtensions,
|
388
|
-
compression,
|
389
|
+
compression ? Compression.Gzip : undefined,
|
389
390
|
encryption,
|
390
391
|
antivirus
|
391
392
|
)
|
@@ -402,7 +403,7 @@ export const afterImportActions = {
|
|
402
403
|
enabled,
|
403
404
|
maxFileSize,
|
404
405
|
allowedExtensions,
|
405
|
-
compression,
|
406
|
+
compression ? Compression.Gzip : undefined,
|
406
407
|
encryption,
|
407
408
|
antivirus
|
408
409
|
)
|
@@ -1,4 +1,10 @@
|
|
1
|
-
import {
|
1
|
+
import {
|
2
|
+
Client,
|
3
|
+
Databases,
|
4
|
+
IndexType,
|
5
|
+
Query,
|
6
|
+
type Models,
|
7
|
+
} from "node-appwrite";
|
2
8
|
import {
|
3
9
|
getAppwriteClient,
|
4
10
|
tryAwaitWithRetry,
|
@@ -139,7 +145,7 @@ export const transferDatabaseLocalToLocal = async (
|
|
139
145
|
targetDbId,
|
140
146
|
newCollection.$id,
|
141
147
|
index.key,
|
142
|
-
index.type,
|
148
|
+
index.type as IndexType,
|
143
149
|
index.attributes,
|
144
150
|
index.orders
|
145
151
|
)
|
@@ -226,7 +232,7 @@ export const transferDatabaseLocalToRemote = async (
|
|
226
232
|
toDbId,
|
227
233
|
toCollection.$id,
|
228
234
|
index.key,
|
229
|
-
index.type,
|
235
|
+
index.type as IndexType,
|
230
236
|
index.attributes,
|
231
237
|
index.orders
|
232
238
|
)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { indexSchema, type Index } from "appwrite-utils";
|
2
|
-
import { Databases, Query, type Models } from "node-appwrite";
|
2
|
+
import { Databases, IndexType, Query, type Models } from "node-appwrite";
|
3
3
|
import { tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
4
4
|
// import {}
|
5
5
|
|
@@ -19,7 +19,7 @@ export const createOrUpdateIndex = async (
|
|
19
19
|
dbId,
|
20
20
|
collectionId,
|
21
21
|
index.key,
|
22
|
-
index.type,
|
22
|
+
index.type as IndexType,
|
23
23
|
index.attributes,
|
24
24
|
index.orders
|
25
25
|
);
|
@@ -2,11 +2,11 @@ import {
|
|
2
2
|
Storage,
|
3
3
|
Databases,
|
4
4
|
Query,
|
5
|
-
InputFile,
|
6
5
|
type Models,
|
7
6
|
ID,
|
8
7
|
Permission,
|
9
8
|
} from "node-appwrite";
|
9
|
+
import { InputFile } from "node-appwrite/file";
|
10
10
|
import { type OperationCreate, type BackupCreate } from "./backup.js";
|
11
11
|
import { splitIntoBatches } from "./migrationHelper.js";
|
12
12
|
import type { AppwriteConfig } from "appwrite-utils";
|
@@ -388,11 +388,29 @@ export const transferStorageLocalToLocal = async (
|
|
388
388
|
);
|
389
389
|
const allFromFiles = fromFiles.files;
|
390
390
|
let numberOfFiles = 0;
|
391
|
+
|
392
|
+
const downloadFileWithRetry = async (bucketId: string, fileId: string) => {
|
393
|
+
let attempts = 3;
|
394
|
+
while (attempts > 0) {
|
395
|
+
try {
|
396
|
+
return await storage.getFileDownload(bucketId, fileId);
|
397
|
+
} catch (error) {
|
398
|
+
console.error(`Error downloading file ${fileId}: ${error}`);
|
399
|
+
attempts--;
|
400
|
+
if (attempts === 0) throw error;
|
401
|
+
}
|
402
|
+
}
|
403
|
+
};
|
404
|
+
|
391
405
|
if (fromFiles.files.length < 100) {
|
392
406
|
for (const file of allFromFiles) {
|
393
407
|
const fileData = await tryAwaitWithRetry(
|
394
|
-
async () => await
|
408
|
+
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
395
409
|
);
|
410
|
+
if (!fileData) {
|
411
|
+
console.error(`Error downloading file ${file.$id}`);
|
412
|
+
continue;
|
413
|
+
}
|
396
414
|
const fileToCreate = InputFile.fromBuffer(
|
397
415
|
Buffer.from(fileData),
|
398
416
|
file.name
|
@@ -428,8 +446,12 @@ export const transferStorageLocalToLocal = async (
|
|
428
446
|
}
|
429
447
|
for (const file of allFromFiles) {
|
430
448
|
const fileData = await tryAwaitWithRetry(
|
431
|
-
async () => await
|
449
|
+
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
432
450
|
);
|
451
|
+
if (!fileData) {
|
452
|
+
console.error(`Error downloading file ${file.$id}`);
|
453
|
+
continue;
|
454
|
+
}
|
433
455
|
const fileToCreate = InputFile.fromBuffer(
|
434
456
|
Buffer.from(fileData),
|
435
457
|
file.name
|
@@ -490,12 +512,16 @@ export const transferStorageLocalToRemote = async (
|
|
490
512
|
}
|
491
513
|
|
492
514
|
for (const file of allFromFiles) {
|
515
|
+
const fileData = await tryAwaitWithRetry(
|
516
|
+
async () => await localStorage.getFileDownload(file.bucketId, file.$id)
|
517
|
+
);
|
518
|
+
const fileToCreate = InputFile.fromBuffer(Buffer.from(fileData), file.name);
|
493
519
|
await tryAwaitWithRetry(
|
494
520
|
async () =>
|
495
521
|
await remoteStorage.createFile(
|
496
522
|
toBucketId,
|
497
523
|
file.$id,
|
498
|
-
|
524
|
+
fileToCreate,
|
499
525
|
file.$permissions
|
500
526
|
)
|
501
527
|
);
|