appwrite-utils-cli 0.9.95 → 0.9.96

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 CHANGED
@@ -148,13 +148,27 @@ async function main() {
148
148
  shouldWriteFile: parsedArgv.writeData,
149
149
  wipeCollections: parsedArgv.wipeCollections,
150
150
  };
151
+ // Add default databases if not specified
152
+ if (!options.databases || options.databases.length === 0) {
153
+ const allDatabases = await fetchAllDatabases(controller.database);
154
+ options.databases = allDatabases.filter((db) => db.name.toLowerCase() !== "migrations");
155
+ }
156
+ // Add default collections if not specified
157
+ if (!options.collections || options.collections.length === 0) {
158
+ if (controller.config && controller.config.collections) {
159
+ options.collections = controller.config.collections.map((c) => c.name);
160
+ }
161
+ else {
162
+ options.collections = [];
163
+ }
164
+ }
151
165
  if (parsedArgv.push || parsedArgv.sync) {
152
- const databases = options.databases || await fetchAllDatabases(controller.database);
166
+ const databases = options.databases || (await fetchAllDatabases(controller.database));
153
167
  let collections = [];
154
168
  if (options.collections) {
155
169
  for (const db of databases) {
156
170
  const dbCollections = await fetchAllCollections(db.$id, controller.database);
157
- collections = collections.concat(dbCollections.filter(c => options.collections.includes(c.$id)));
171
+ collections = collections.concat(dbCollections.filter((c) => options.collections.includes(c.$id)));
158
172
  }
159
173
  }
160
174
  if (parsedArgv.push) {
@@ -184,7 +198,7 @@ async function main() {
184
198
  if (options.wipeCollections && options.databases) {
185
199
  for (const db of options.databases) {
186
200
  const dbCollections = await fetchAllCollections(db.$id, controller.database);
187
- const collectionsToWipe = dbCollections.filter(c => options.collections.includes(c.$id));
201
+ const collectionsToWipe = dbCollections.filter((c) => options.collections.includes(c.$id));
188
202
  for (const collection of collectionsToWipe) {
189
203
  await controller.wipeCollection(db, collection);
190
204
  }
@@ -84,7 +84,7 @@ export class ImportController {
84
84
  dataLoader.getCollectionKey(collection.name);
85
85
  const importOperationId = dataLoader.collectionImportOperations.get(dataLoader.getCollectionKey(collection.name));
86
86
  const createBatches = (finalData) => {
87
- let maxBatchLength = 100;
87
+ let maxBatchLength = 50;
88
88
  const finalBatches = [];
89
89
  for (let i = 0; i < finalData.length; i++) {
90
90
  if (i % maxBatchLength === 0) {
@@ -33,15 +33,20 @@ export class UsersController {
33
33
  return finalBatches;
34
34
  };
35
35
  let usersDeleted = 0;
36
- const batchedUserPromises = createBatches(allUsers, 50); // Batch size of 10
37
- for (const batch of batchedUserPromises) {
38
- console.log(`Deleting ${batch.length} users...`);
39
- await Promise.all(batch.map((user) => tryAwaitWithRetry(async () => await this.users.delete(user.$id))));
40
- usersDeleted += batch.length;
41
- if (usersDeleted % 100 === 0) {
42
- console.log(`Deleted ${usersDeleted} users...`);
36
+ if (allUsers.length > 0) {
37
+ const batchedUserPromises = createBatches(allUsers, 25); // Batch size of 25
38
+ for (const batch of batchedUserPromises) {
39
+ console.log(`Deleting ${batch.length} users...`);
40
+ await Promise.all(batch.map((user) => tryAwaitWithRetry(async () => await this.users.delete(user.$id))));
41
+ usersDeleted += batch.length;
42
+ if (usersDeleted % 100 === 0) {
43
+ console.log(`Deleted ${usersDeleted} users...`);
44
+ }
43
45
  }
44
46
  }
47
+ else {
48
+ console.log("No users to delete");
49
+ }
45
50
  }
46
51
  async getAllUsers() {
47
52
  const allUsers = [];
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.95",
4
+ "version": "0.9.96",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
package/src/main.ts CHANGED
@@ -68,7 +68,8 @@ const argv = yargs(hideBin(process.argv))
68
68
  })
69
69
  .option("wipeCollections", {
70
70
  type: "boolean",
71
- description: "Wipe collections, uses collectionIds option to get the collections to wipe",
71
+ description:
72
+ "Wipe collections, uses collectionIds option to get the collections to wipe",
72
73
  })
73
74
  .option("generate", {
74
75
  type: "boolean",
@@ -159,7 +160,6 @@ const argv = yargs(hideBin(process.argv))
159
160
  .parse() as ParsedArgv;
160
161
 
161
162
  async function main() {
162
-
163
163
  if (argv.it) {
164
164
  const cli = new InteractiveCLI(process.cwd());
165
165
  await cli.run();
@@ -189,14 +189,37 @@ async function main() {
189
189
  wipeCollections: parsedArgv.wipeCollections,
190
190
  };
191
191
 
192
+ // Add default databases if not specified
193
+ if (!options.databases || options.databases.length === 0) {
194
+ const allDatabases = await fetchAllDatabases(controller.database!);
195
+ options.databases = allDatabases.filter(
196
+ (db) => db.name.toLowerCase() !== "migrations"
197
+ );
198
+ }
199
+
200
+ // Add default collections if not specified
201
+ if (!options.collections || options.collections.length === 0) {
202
+ if (controller.config && controller.config.collections) {
203
+ options.collections = controller.config.collections.map((c) => c.name);
204
+ } else {
205
+ options.collections = [];
206
+ }
207
+ }
208
+
192
209
  if (parsedArgv.push || parsedArgv.sync) {
193
- const databases = options.databases || await fetchAllDatabases(controller.database!);
210
+ const databases =
211
+ options.databases || (await fetchAllDatabases(controller.database!));
194
212
  let collections: Models.Collection[] = [];
195
-
213
+
196
214
  if (options.collections) {
197
215
  for (const db of databases) {
198
- const dbCollections = await fetchAllCollections(db.$id, controller.database!);
199
- collections = collections.concat(dbCollections.filter(c => options.collections!.includes(c.$id)));
216
+ const dbCollections = await fetchAllCollections(
217
+ db.$id,
218
+ controller.database!
219
+ );
220
+ collections = collections.concat(
221
+ dbCollections.filter((c) => options.collections!.includes(c.$id))
222
+ );
200
223
  }
201
224
  }
202
225
 
@@ -228,8 +251,13 @@ async function main() {
228
251
  }
229
252
  if (options.wipeCollections && options.databases) {
230
253
  for (const db of options.databases) {
231
- const dbCollections = await fetchAllCollections(db.$id, controller.database!);
232
- const collectionsToWipe = dbCollections.filter(c => options.collections!.includes(c.$id));
254
+ const dbCollections = await fetchAllCollections(
255
+ db.$id,
256
+ controller.database!
257
+ );
258
+ const collectionsToWipe = dbCollections.filter((c) =>
259
+ options.collections!.includes(c.$id)
260
+ );
233
261
  for (const collection of collectionsToWipe) {
234
262
  await controller.wipeCollection(db, collection);
235
263
  }
@@ -318,4 +346,4 @@ async function main() {
318
346
  main().catch((error) => {
319
347
  console.error("An error occurred:", error);
320
348
  process.exit(1);
321
- });
349
+ });
@@ -154,7 +154,7 @@ export class ImportController {
154
154
  dataLoader.getCollectionKey(collection.name)
155
155
  );
156
156
  const createBatches = (finalData: CollectionImportData["data"]) => {
157
- let maxBatchLength = 100;
157
+ let maxBatchLength = 50;
158
158
  const finalBatches: CollectionImportData["data"][] = [];
159
159
  for (let i = 0; i < finalData.length; i++) {
160
160
  if (i % maxBatchLength === 0) {
@@ -53,19 +53,23 @@ export class UsersController {
53
53
  };
54
54
 
55
55
  let usersDeleted = 0;
56
- const batchedUserPromises = createBatches(allUsers, 50); // Batch size of 10
56
+ if (allUsers.length > 0) {
57
+ const batchedUserPromises = createBatches(allUsers, 25); // Batch size of 25
57
58
 
58
- for (const batch of batchedUserPromises) {
59
- console.log(`Deleting ${batch.length} users...`);
60
- await Promise.all(
61
- batch.map((user) =>
62
- tryAwaitWithRetry(async () => await this.users.delete(user.$id))
63
- )
64
- );
65
- usersDeleted += batch.length;
66
- if (usersDeleted % 100 === 0) {
67
- console.log(`Deleted ${usersDeleted} users...`);
59
+ for (const batch of batchedUserPromises) {
60
+ console.log(`Deleting ${batch.length} users...`);
61
+ await Promise.all(
62
+ batch.map((user) =>
63
+ tryAwaitWithRetry(async () => await this.users.delete(user.$id))
64
+ )
65
+ );
66
+ usersDeleted += batch.length;
67
+ if (usersDeleted % 100 === 0) {
68
+ console.log(`Deleted ${usersDeleted} users...`);
69
+ }
68
70
  }
71
+ } else {
72
+ console.log("No users to delete");
69
73
  }
70
74
  }
71
75
 
@@ -0,0 +1,4 @@
1
+ {
2
+ "collection": "album",
3
+ "data": []
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collection": "artist",
3
+ "data": []
4
+ }
@@ -0,0 +1,4 @@
1
+ {
2
+ "collection": "genre",
3
+ "data": []
4
+ }
@@ -1,56 +1 @@
1
- [
2
- [
3
- "6658d6be001df3bc11b5",
4
- [
5
- "6540"
6
- ]
7
- ],
8
- [
9
- "6658d6bf000497b9bc75",
10
- [
11
- "6755"
12
- ]
13
- ],
14
- [
15
- "6658d6bf0000ea9e02f1",
16
- [
17
- "6830"
18
- ]
19
- ],
20
- [
21
- "6658d6bf001ac437c7f5",
22
- [
23
- "6885"
24
- ]
25
- ],
26
- [
27
- "6658d6bf0022564fd7d9",
28
- [
29
- "6918"
30
- ]
31
- ],
32
- [
33
- "6658d6c0002898b5a5bb",
34
- [
35
- "7338"
36
- ]
37
- ],
38
- [
39
- "6658d6bf0033c8dd5630",
40
- [
41
- "7350"
42
- ]
43
- ],
44
- [
45
- "6658d6c1001a721332f7",
46
- [
47
- "7751"
48
- ]
49
- ],
50
- [
51
- "6658d6c2003bf5fa3b2e",
52
- [
53
- "8550"
54
- ]
55
- ]
56
- ]
1
+ []