appwrite-utils-cli 0.0.24 → 0.0.242
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.
@@ -164,5 +164,5 @@ export declare const findOrCreateOperation: (database: Databases, collectionId:
|
|
164
164
|
}>;
|
165
165
|
export declare const updateOperation: (database: Databases, operationId: string, updateFields: any) => Promise<void>;
|
166
166
|
export declare const maxDataLength = 1073741820;
|
167
|
-
export declare const maxBatchItems =
|
167
|
+
export declare const maxBatchItems = 25;
|
168
168
|
export declare const splitIntoBatches: (data: any[]) => any[][];
|
@@ -94,7 +94,7 @@ export const updateOperation = async (database, operationId, updateFields) => {
|
|
94
94
|
};
|
95
95
|
// Actual max 1073741824
|
96
96
|
export const maxDataLength = 1073741820;
|
97
|
-
export const maxBatchItems =
|
97
|
+
export const maxBatchItems = 25;
|
98
98
|
export const splitIntoBatches = (data) => {
|
99
99
|
let batches = [];
|
100
100
|
let currentBatch = [];
|
package/dist/migrations/users.js
CHANGED
@@ -22,30 +22,34 @@ export class UsersController {
|
|
22
22
|
this.users = new Users(this.config.appwriteClient);
|
23
23
|
}
|
24
24
|
async wipeUsers() {
|
25
|
-
const users = await this.users.list([Query.limit(
|
25
|
+
const users = await this.users.list([Query.limit(200)]);
|
26
26
|
const allUsers = users.users;
|
27
27
|
let lastDocumentId;
|
28
|
-
if (users.users.length >=
|
28
|
+
if (users.users.length >= 200) {
|
29
29
|
lastDocumentId = users.users[users.users.length - 1].$id;
|
30
30
|
}
|
31
31
|
while (lastDocumentId) {
|
32
32
|
const moreUsers = await this.users.list([
|
33
|
-
Query.limit(
|
33
|
+
Query.limit(200),
|
34
34
|
Query.cursorAfter(lastDocumentId),
|
35
35
|
]);
|
36
36
|
allUsers.push(...moreUsers.users);
|
37
|
-
if (moreUsers.users.length <
|
37
|
+
if (moreUsers.users.length < 200) {
|
38
38
|
break;
|
39
39
|
}
|
40
40
|
lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
|
41
41
|
}
|
42
|
-
console.log("Deleting all users");
|
42
|
+
console.log("Deleting all users...");
|
43
43
|
const userPromises = [];
|
44
|
-
|
45
|
-
|
44
|
+
const allUsersBatched = splitIntoBatches(allUsers);
|
45
|
+
for (const userBatch of allUsersBatched) {
|
46
|
+
for (const user of userBatch) {
|
47
|
+
userPromises.push(this.users.delete(user.$id));
|
48
|
+
}
|
46
49
|
}
|
47
50
|
const batchedUserPromises = splitIntoBatches(userPromises);
|
48
51
|
for (const batch of batchedUserPromises) {
|
52
|
+
console.log(`Deleting ${batch.length} users...`);
|
49
53
|
await Promise.all(batch);
|
50
54
|
}
|
51
55
|
}
|
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.242",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -158,7 +158,7 @@ export const updateOperation = async (
|
|
158
158
|
|
159
159
|
// Actual max 1073741824
|
160
160
|
export const maxDataLength = 1073741820;
|
161
|
-
export const maxBatchItems =
|
161
|
+
export const maxBatchItems = 25;
|
162
162
|
|
163
163
|
export const splitIntoBatches = (data: any[]): any[][] => {
|
164
164
|
let batches = [];
|
package/src/migrations/users.ts
CHANGED
@@ -30,30 +30,34 @@ export class UsersController {
|
|
30
30
|
}
|
31
31
|
|
32
32
|
async wipeUsers() {
|
33
|
-
const users = await this.users.list([Query.limit(
|
33
|
+
const users = await this.users.list([Query.limit(200)]);
|
34
34
|
const allUsers = users.users;
|
35
35
|
let lastDocumentId: string | undefined;
|
36
|
-
if (users.users.length >=
|
36
|
+
if (users.users.length >= 200) {
|
37
37
|
lastDocumentId = users.users[users.users.length - 1].$id;
|
38
38
|
}
|
39
39
|
while (lastDocumentId) {
|
40
40
|
const moreUsers = await this.users.list([
|
41
|
-
Query.limit(
|
41
|
+
Query.limit(200),
|
42
42
|
Query.cursorAfter(lastDocumentId),
|
43
43
|
]);
|
44
44
|
allUsers.push(...moreUsers.users);
|
45
|
-
if (moreUsers.users.length <
|
45
|
+
if (moreUsers.users.length < 200) {
|
46
46
|
break;
|
47
47
|
}
|
48
48
|
lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
|
49
49
|
}
|
50
|
-
console.log("Deleting all users");
|
50
|
+
console.log("Deleting all users...");
|
51
51
|
const userPromises: Promise<string>[] = [];
|
52
|
-
|
53
|
-
|
52
|
+
const allUsersBatched = splitIntoBatches(allUsers);
|
53
|
+
for (const userBatch of allUsersBatched) {
|
54
|
+
for (const user of userBatch) {
|
55
|
+
userPromises.push(this.users.delete(user.$id));
|
56
|
+
}
|
54
57
|
}
|
55
58
|
const batchedUserPromises = splitIntoBatches(userPromises);
|
56
59
|
for (const batch of batchedUserPromises) {
|
60
|
+
console.log(`Deleting ${batch.length} users...`);
|
57
61
|
await Promise.all(batch);
|
58
62
|
}
|
59
63
|
}
|