appwrite-utils-cli 0.9.990 → 0.9.991
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/main.js +18 -7
- package/dist/migrations/transfer.js +7 -1
- package/package.json +1 -1
- package/src/main.ts +21 -10
- package/src/migrations/transfer.ts +8 -3
package/dist/main.js
CHANGED
@@ -171,19 +171,30 @@ async function main() {
|
|
171
171
|
options.wipeDocumentStorage ||
|
172
172
|
options.wipeUsers ||
|
173
173
|
options.wipeCollections) {
|
174
|
-
if (
|
175
|
-
|
176
|
-
|
174
|
+
if (parsedArgv.wipe === "all") {
|
175
|
+
if (options.databases) {
|
176
|
+
for (const db of options.databases) {
|
177
|
+
await controller.wipeDatabase(db, true); // true to wipe associated buckets
|
178
|
+
}
|
177
179
|
}
|
180
|
+
await controller.wipeUsers();
|
178
181
|
}
|
179
|
-
if (
|
180
|
-
|
181
|
-
|
182
|
+
else if (parsedArgv.wipe === "docs") {
|
183
|
+
if (options.databases) {
|
184
|
+
for (const db of options.databases) {
|
185
|
+
await controller.wipeBucketFromDatabase(db);
|
186
|
+
}
|
187
|
+
}
|
188
|
+
if (parsedArgv.bucketIds) {
|
189
|
+
for (const bucketId of parsedArgv.bucketIds.split(",")) {
|
190
|
+
await controller.wipeDocumentStorage(bucketId);
|
191
|
+
}
|
182
192
|
}
|
183
193
|
}
|
184
|
-
if (
|
194
|
+
else if (parsedArgv.wipe === "users") {
|
185
195
|
await controller.wipeUsers();
|
186
196
|
}
|
197
|
+
// Handle specific collection wipes
|
187
198
|
if (options.wipeCollections && options.databases) {
|
188
199
|
for (const db of options.databases) {
|
189
200
|
const dbCollections = await fetchAllCollections(db.$id, controller.database);
|
@@ -65,7 +65,13 @@ export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucke
|
|
65
65
|
continue;
|
66
66
|
}
|
67
67
|
const fileToCreate = InputFile.fromBuffer(new Uint8Array(fileData), file.name);
|
68
|
-
|
68
|
+
try {
|
69
|
+
await tryAwaitWithRetry(async () => await storage.createFile(toBucketId, file.$id, fileToCreate, file.$permissions));
|
70
|
+
}
|
71
|
+
catch (error) {
|
72
|
+
// File already exists, so we can skip it
|
73
|
+
continue;
|
74
|
+
}
|
69
75
|
numberOfFiles++;
|
70
76
|
}
|
71
77
|
}
|
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.9.
|
4
|
+
"version": "0.9.991",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
package/src/main.ts
CHANGED
@@ -181,7 +181,8 @@ async function main() {
|
|
181
181
|
collections: parsedArgv.collectionIds?.split(","),
|
182
182
|
doBackup: parsedArgv.backup,
|
183
183
|
wipeDatabase: parsedArgv.wipe === "all" || parsedArgv.wipe === "docs",
|
184
|
-
wipeDocumentStorage:
|
184
|
+
wipeDocumentStorage:
|
185
|
+
parsedArgv.wipe === "all" || parsedArgv.wipe === "storage",
|
185
186
|
wipeUsers: parsedArgv.wipe === "all" || parsedArgv.wipe === "users",
|
186
187
|
generateSchemas: parsedArgv.generate,
|
187
188
|
importData: parsedArgv.import,
|
@@ -218,19 +219,29 @@ async function main() {
|
|
218
219
|
options.wipeUsers ||
|
219
220
|
options.wipeCollections
|
220
221
|
) {
|
221
|
-
if (
|
222
|
-
|
223
|
-
|
222
|
+
if (parsedArgv.wipe === "all") {
|
223
|
+
if (options.databases) {
|
224
|
+
for (const db of options.databases) {
|
225
|
+
await controller.wipeDatabase(db, true); // true to wipe associated buckets
|
226
|
+
}
|
224
227
|
}
|
225
|
-
|
226
|
-
if (
|
227
|
-
|
228
|
-
|
228
|
+
await controller.wipeUsers();
|
229
|
+
} else if (parsedArgv.wipe === "docs") {
|
230
|
+
if (options.databases) {
|
231
|
+
for (const db of options.databases) {
|
232
|
+
await controller.wipeBucketFromDatabase(db);
|
233
|
+
}
|
229
234
|
}
|
230
|
-
|
231
|
-
|
235
|
+
if (parsedArgv.bucketIds) {
|
236
|
+
for (const bucketId of parsedArgv.bucketIds.split(",")) {
|
237
|
+
await controller.wipeDocumentStorage(bucketId);
|
238
|
+
}
|
239
|
+
}
|
240
|
+
} else if (parsedArgv.wipe === "users") {
|
232
241
|
await controller.wipeUsers();
|
233
242
|
}
|
243
|
+
|
244
|
+
// Handle specific collection wipes
|
234
245
|
if (options.wipeCollections && options.databases) {
|
235
246
|
for (const db of options.databases) {
|
236
247
|
const dbCollections = await fetchAllCollections(
|
@@ -109,15 +109,20 @@ export const transferStorageLocalToLocal = async (
|
|
109
109
|
new Uint8Array(fileData),
|
110
110
|
file.name
|
111
111
|
);
|
112
|
-
|
113
|
-
|
112
|
+
try {
|
113
|
+
await tryAwaitWithRetry(
|
114
|
+
async () =>
|
114
115
|
await storage.createFile(
|
115
116
|
toBucketId,
|
116
117
|
file.$id,
|
117
118
|
fileToCreate,
|
118
119
|
file.$permissions
|
119
120
|
)
|
120
|
-
|
121
|
+
);
|
122
|
+
} catch (error: any) {
|
123
|
+
// File already exists, so we can skip it
|
124
|
+
continue;
|
125
|
+
}
|
121
126
|
numberOfFiles++;
|
122
127
|
}
|
123
128
|
}
|