appwrite-utils-cli 0.10.86 → 1.0.1
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/.appwrite/.yaml_schemas/appwrite-config.schema.json +380 -0
- package/.appwrite/.yaml_schemas/collection.schema.json +255 -0
- package/.appwrite/collections/Categories.yaml +182 -0
- package/.appwrite/collections/ExampleCollection.yaml +36 -0
- package/.appwrite/collections/Posts.yaml +227 -0
- package/.appwrite/collections/Users.yaml +149 -0
- package/.appwrite/config.yaml +109 -0
- package/.appwrite/import/README.md +148 -0
- package/.appwrite/import/categories-import.yaml +129 -0
- package/.appwrite/import/posts-import.yaml +208 -0
- package/.appwrite/import/users-import.yaml +130 -0
- package/.appwrite/importData/categories.json +194 -0
- package/.appwrite/importData/posts.json +270 -0
- package/.appwrite/importData/users.json +220 -0
- package/.appwrite/schemas/categories.json +128 -0
- package/.appwrite/schemas/exampleCollection.json +52 -0
- package/.appwrite/schemas/posts.json +173 -0
- package/.appwrite/schemas/users.json +125 -0
- package/README.md +260 -33
- package/dist/collections/attributes.js +3 -2
- package/dist/collections/methods.js +56 -38
- package/dist/config/yamlConfig.d.ts +501 -0
- package/dist/config/yamlConfig.js +452 -0
- package/dist/databases/setup.d.ts +6 -0
- package/dist/databases/setup.js +119 -0
- package/dist/functions/methods.d.ts +1 -1
- package/dist/functions/methods.js +5 -2
- package/dist/functions/openapi.d.ts +4 -0
- package/dist/functions/openapi.js +60 -0
- package/dist/interactiveCLI.d.ts +5 -0
- package/dist/interactiveCLI.js +194 -49
- package/dist/main.js +91 -30
- package/dist/migrations/afterImportActions.js +2 -2
- package/dist/migrations/appwriteToX.d.ts +10 -0
- package/dist/migrations/appwriteToX.js +15 -4
- package/dist/migrations/backup.d.ts +16 -16
- package/dist/migrations/dataLoader.d.ts +83 -1
- package/dist/migrations/dataLoader.js +4 -4
- package/dist/migrations/importController.js +25 -18
- package/dist/migrations/importDataActions.js +2 -2
- package/dist/migrations/logging.d.ts +9 -1
- package/dist/migrations/logging.js +41 -22
- package/dist/migrations/migrationHelper.d.ts +4 -4
- package/dist/migrations/relationships.js +1 -1
- package/dist/migrations/services/DataTransformationService.d.ts +55 -0
- package/dist/migrations/services/DataTransformationService.js +158 -0
- package/dist/migrations/services/FileHandlerService.d.ts +75 -0
- package/dist/migrations/services/FileHandlerService.js +236 -0
- package/dist/migrations/services/ImportOrchestrator.d.ts +97 -0
- package/dist/migrations/services/ImportOrchestrator.js +488 -0
- package/dist/migrations/services/RateLimitManager.d.ts +138 -0
- package/dist/migrations/services/RateLimitManager.js +279 -0
- package/dist/migrations/services/RelationshipResolver.d.ts +120 -0
- package/dist/migrations/services/RelationshipResolver.js +332 -0
- package/dist/migrations/services/UserMappingService.d.ts +109 -0
- package/dist/migrations/services/UserMappingService.js +277 -0
- package/dist/migrations/services/ValidationService.d.ts +74 -0
- package/dist/migrations/services/ValidationService.js +260 -0
- package/dist/migrations/transfer.d.ts +0 -6
- package/dist/migrations/transfer.js +16 -132
- package/dist/migrations/yaml/YamlImportConfigLoader.d.ts +384 -0
- package/dist/migrations/yaml/YamlImportConfigLoader.js +375 -0
- package/dist/migrations/yaml/YamlImportIntegration.d.ts +87 -0
- package/dist/migrations/yaml/YamlImportIntegration.js +330 -0
- package/dist/migrations/yaml/generateImportSchemas.d.ts +17 -0
- package/dist/migrations/yaml/generateImportSchemas.js +575 -0
- package/dist/schemas/authUser.d.ts +9 -9
- package/dist/shared/attributeManager.d.ts +17 -0
- package/dist/shared/attributeManager.js +273 -0
- package/dist/shared/confirmationDialogs.d.ts +75 -0
- package/dist/shared/confirmationDialogs.js +236 -0
- package/dist/shared/functionManager.d.ts +48 -0
- package/dist/shared/functionManager.js +322 -0
- package/dist/shared/indexManager.d.ts +24 -0
- package/dist/shared/indexManager.js +150 -0
- package/dist/shared/jsonSchemaGenerator.d.ts +51 -0
- package/dist/shared/jsonSchemaGenerator.js +313 -0
- package/dist/shared/logging.d.ts +10 -0
- package/dist/shared/logging.js +46 -0
- package/dist/shared/messageFormatter.d.ts +37 -0
- package/dist/shared/messageFormatter.js +152 -0
- package/dist/shared/migrationHelpers.d.ts +173 -0
- package/dist/shared/migrationHelpers.js +142 -0
- package/dist/shared/operationLogger.d.ts +3 -0
- package/dist/shared/operationLogger.js +25 -0
- package/dist/shared/operationQueue.d.ts +13 -0
- package/dist/shared/operationQueue.js +79 -0
- package/dist/shared/progressManager.d.ts +62 -0
- package/dist/shared/progressManager.js +215 -0
- package/dist/shared/schemaGenerator.d.ts +18 -0
- package/dist/shared/schemaGenerator.js +523 -0
- package/dist/storage/methods.d.ts +3 -1
- package/dist/storage/methods.js +144 -55
- package/dist/storage/schemas.d.ts +56 -16
- package/dist/types.d.ts +2 -2
- package/dist/types.js +1 -1
- package/dist/users/methods.d.ts +16 -0
- package/dist/users/methods.js +276 -0
- package/dist/utils/configMigration.d.ts +1 -0
- package/dist/utils/configMigration.js +156 -0
- package/dist/utils/dataConverters.d.ts +46 -0
- package/dist/utils/dataConverters.js +139 -0
- package/dist/utils/loadConfigs.d.ts +15 -4
- package/dist/utils/loadConfigs.js +377 -51
- package/dist/utils/schemaStrings.js +2 -1
- package/dist/utils/setupFiles.d.ts +2 -1
- package/dist/utils/setupFiles.js +723 -28
- package/dist/utils/validationRules.d.ts +43 -0
- package/dist/utils/validationRules.js +42 -0
- package/dist/utils/yamlConverter.d.ts +48 -0
- package/dist/utils/yamlConverter.js +98 -0
- package/dist/utilsController.js +65 -43
- package/package.json +19 -15
- package/src/collections/attributes.ts +3 -2
- package/src/collections/methods.ts +85 -51
- package/src/config/yamlConfig.ts +488 -0
- package/src/{migrations/setupDatabase.ts → databases/setup.ts} +11 -5
- package/src/functions/methods.ts +8 -4
- package/src/functions/templates/count-docs-in-collection/package.json +25 -0
- package/src/functions/templates/count-docs-in-collection/tsconfig.json +28 -0
- package/src/functions/templates/typescript-node/package.json +24 -0
- package/src/functions/templates/typescript-node/tsconfig.json +28 -0
- package/src/functions/templates/uv/README.md +31 -0
- package/src/functions/templates/uv/pyproject.toml +29 -0
- package/src/interactiveCLI.ts +226 -61
- package/src/main.ts +111 -37
- package/src/migrations/afterImportActions.ts +2 -2
- package/src/migrations/appwriteToX.ts +17 -4
- package/src/migrations/dataLoader.ts +4 -4
- package/src/migrations/importController.ts +30 -22
- package/src/migrations/importDataActions.ts +2 -2
- package/src/migrations/relationships.ts +1 -1
- package/src/migrations/services/DataTransformationService.ts +196 -0
- package/src/migrations/services/FileHandlerService.ts +311 -0
- package/src/migrations/services/ImportOrchestrator.ts +669 -0
- package/src/migrations/services/RateLimitManager.ts +363 -0
- package/src/migrations/services/RelationshipResolver.ts +461 -0
- package/src/migrations/services/UserMappingService.ts +345 -0
- package/src/migrations/services/ValidationService.ts +349 -0
- package/src/migrations/transfer.ts +22 -228
- package/src/migrations/yaml/YamlImportConfigLoader.ts +427 -0
- package/src/migrations/yaml/YamlImportIntegration.ts +419 -0
- package/src/migrations/yaml/generateImportSchemas.ts +589 -0
- package/src/shared/attributeManager.ts +429 -0
- package/src/shared/confirmationDialogs.ts +327 -0
- package/src/shared/functionManager.ts +515 -0
- package/src/shared/indexManager.ts +253 -0
- package/src/shared/jsonSchemaGenerator.ts +403 -0
- package/src/shared/logging.ts +74 -0
- package/src/shared/messageFormatter.ts +195 -0
- package/src/{migrations/migrationHelper.ts → shared/migrationHelpers.ts} +22 -4
- package/src/{migrations/helper.ts → shared/operationLogger.ts} +7 -2
- package/src/{migrations/queue.ts → shared/operationQueue.ts} +1 -1
- package/src/shared/progressManager.ts +278 -0
- package/src/{migrations/schemaStrings.ts → shared/schemaGenerator.ts} +71 -17
- package/src/storage/methods.ts +199 -78
- package/src/types.ts +2 -2
- package/src/{migrations/users.ts → users/methods.ts} +2 -2
- package/src/utils/configMigration.ts +212 -0
- package/src/utils/loadConfigs.ts +414 -52
- package/src/utils/schemaStrings.ts +2 -1
- package/src/utils/setupFiles.ts +742 -40
- package/src/{migrations → utils}/validationRules.ts +1 -1
- package/src/utils/yamlConverter.ts +131 -0
- package/src/utilsController.ts +75 -54
- package/src/functions/templates/poetry/README.md +0 -30
- package/src/functions/templates/poetry/pyproject.toml +0 -16
- package/src/migrations/attributes.ts +0 -561
- package/src/migrations/backup.ts +0 -205
- package/src/migrations/databases.ts +0 -39
- package/src/migrations/dbHelpers.ts +0 -92
- package/src/migrations/indexes.ts +0 -40
- package/src/migrations/logging.ts +0 -29
- package/src/migrations/storage.ts +0 -538
- /package/src/{migrations → functions}/openapi.ts +0 -0
- /package/src/functions/templates/{poetry → uv}/src/__init__.py +0 -0
- /package/src/functions/templates/{poetry → uv}/src/index.py +0 -0
- /package/src/{migrations/converters.ts → utils/dataConverters.ts} +0 -0
@@ -1,10 +1,12 @@
|
|
1
1
|
import { Client, Databases, ID, Permission, Query, } from "node-appwrite";
|
2
|
-
import { nameToIdMapping, processQueue } from "../
|
2
|
+
import { nameToIdMapping, processQueue } from "../shared/operationQueue.js";
|
3
3
|
import { createUpdateCollectionAttributes } from "./attributes.js";
|
4
4
|
import { createOrUpdateIndexes } from "./indexes.js";
|
5
|
-
import { SchemaGenerator } from "../
|
5
|
+
import { SchemaGenerator } from "../shared/schemaGenerator.js";
|
6
6
|
import { isNull, isUndefined, isNil, isPlainObject, isString, isJSONValue, chunk, } from "es-toolkit";
|
7
7
|
import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
8
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
9
|
+
import { ProgressManager } from "../shared/progressManager.js";
|
8
10
|
export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
|
9
11
|
const collection = await db.getCollection(dbId, targetCollectionId);
|
10
12
|
const attributes = collection.attributes;
|
@@ -48,19 +50,19 @@ export const documentExists = async (db, dbId, targetCollectionId, toCreateObjec
|
|
48
50
|
};
|
49
51
|
export const checkForCollection = async (db, dbId, collection) => {
|
50
52
|
try {
|
51
|
-
|
53
|
+
MessageFormatter.progress(`Checking for collection with name: ${collection.name}`, { prefix: "Collections" });
|
52
54
|
const response = await tryAwaitWithRetry(async () => await db.listCollections(dbId, [Query.equal("name", collection.name)]));
|
53
55
|
if (response.collections.length > 0) {
|
54
|
-
|
56
|
+
MessageFormatter.info(`Collection found: ${response.collections[0].$id}`, { prefix: "Collections" });
|
55
57
|
return { ...collection, ...response.collections[0] };
|
56
58
|
}
|
57
59
|
else {
|
58
|
-
|
60
|
+
MessageFormatter.info(`No collection found with name: ${collection.name}`, { prefix: "Collections" });
|
59
61
|
return null;
|
60
62
|
}
|
61
63
|
}
|
62
64
|
catch (error) {
|
63
|
-
|
65
|
+
MessageFormatter.error(`Error checking for collection: ${collection.name}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Collections" });
|
64
66
|
return null;
|
65
67
|
}
|
66
68
|
};
|
@@ -68,20 +70,20 @@ export const checkForCollection = async (db, dbId, collection) => {
|
|
68
70
|
export const fetchAndCacheCollectionByName = async (db, dbId, collectionName) => {
|
69
71
|
if (nameToIdMapping.has(collectionName)) {
|
70
72
|
const collectionId = nameToIdMapping.get(collectionName);
|
71
|
-
|
73
|
+
MessageFormatter.debug(`Collection found in cache: ${collectionId}`, undefined, { prefix: "Collections" });
|
72
74
|
return await tryAwaitWithRetry(async () => await db.getCollection(dbId, collectionId));
|
73
75
|
}
|
74
76
|
else {
|
75
|
-
|
77
|
+
MessageFormatter.progress(`Fetching collection by name: ${collectionName}`, { prefix: "Collections" });
|
76
78
|
const collectionsPulled = await tryAwaitWithRetry(async () => await db.listCollections(dbId, [Query.equal("name", collectionName)]));
|
77
79
|
if (collectionsPulled.total > 0) {
|
78
80
|
const collection = collectionsPulled.collections[0];
|
79
|
-
|
81
|
+
MessageFormatter.info(`Collection found: ${collection.$id}`, { prefix: "Collections" });
|
80
82
|
nameToIdMapping.set(collectionName, collection.$id);
|
81
83
|
return collection;
|
82
84
|
}
|
83
85
|
else {
|
84
|
-
|
86
|
+
MessageFormatter.warning(`Collection not found by name: ${collectionName}`, { prefix: "Collections" });
|
85
87
|
return undefined;
|
86
88
|
}
|
87
89
|
}
|
@@ -103,55 +105,71 @@ async function wipeDocumentsFromCollection(database, databaseId, collectionId) {
|
|
103
105
|
? docsResponse.documents[docsResponse.documents.length - 1].$id
|
104
106
|
: undefined;
|
105
107
|
if (totalDocuments % 10000 === 0) {
|
106
|
-
|
108
|
+
MessageFormatter.progress(`Found ${totalDocuments} documents...`, { prefix: "Wipe" });
|
107
109
|
}
|
108
110
|
}
|
109
|
-
|
111
|
+
MessageFormatter.info(`Found ${totalDocuments} documents to delete`, { prefix: "Wipe" });
|
112
|
+
if (totalDocuments === 0) {
|
113
|
+
MessageFormatter.info("No documents to delete", { prefix: "Wipe" });
|
114
|
+
return;
|
115
|
+
}
|
116
|
+
// Create progress tracker for deletion
|
117
|
+
const progress = ProgressManager.create(`delete-${collectionId}`, totalDocuments, { title: "Deleting documents" });
|
110
118
|
const maxStackSize = 50; // Reduced batch size
|
111
119
|
const docBatches = chunk(documents, maxStackSize);
|
112
|
-
|
120
|
+
let documentsProcessed = 0;
|
113
121
|
for (let i = 0; i < docBatches.length; i++) {
|
114
122
|
const batch = docBatches[i];
|
115
123
|
const deletePromises = batch.map(async (doc) => {
|
116
124
|
try {
|
117
125
|
await tryAwaitWithRetry(async () => database.deleteDocument(databaseId, collectionId, doc.$id));
|
126
|
+
documentsProcessed++;
|
127
|
+
progress.update(documentsProcessed);
|
118
128
|
}
|
119
129
|
catch (error) {
|
120
130
|
// Skip if document doesn't exist or other non-critical errors
|
121
131
|
if (!error.message?.includes("Document with the requested ID could not be found")) {
|
122
|
-
|
132
|
+
MessageFormatter.error(`Failed to delete document ${doc.$id}`, error.message, { prefix: "Wipe" });
|
123
133
|
}
|
134
|
+
documentsProcessed++;
|
135
|
+
progress.update(documentsProcessed);
|
124
136
|
}
|
125
137
|
});
|
126
138
|
await Promise.all(deletePromises);
|
127
139
|
await delay(50); // Increased delay between batches
|
128
|
-
//
|
129
|
-
if ((i + 1) % quarterBatchSize === 0 || i === docBatches.length - 1) {
|
130
|
-
const percentComplete = Math.round(((i + 1) / docBatches.length) * 100);
|
131
|
-
const documentsProcessed = Math.min((i + 1) * maxStackSize, totalDocuments);
|
132
|
-
console.log(`Deleted ${documentsProcessed} documents (${percentComplete}% complete)`);
|
133
|
-
}
|
140
|
+
// Progress is now handled by ProgressManager automatically
|
134
141
|
}
|
135
|
-
|
142
|
+
progress.stop();
|
143
|
+
MessageFormatter.success(`Completed deletion of ${totalDocuments} documents from collection ${collectionId}`, { prefix: "Wipe" });
|
136
144
|
}
|
137
145
|
catch (error) {
|
138
|
-
|
146
|
+
MessageFormatter.error(`Error wiping documents from collection ${collectionId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Wipe" });
|
139
147
|
throw error;
|
140
148
|
}
|
141
149
|
}
|
142
150
|
export const wipeDatabase = async (database, databaseId) => {
|
143
|
-
|
151
|
+
MessageFormatter.info(`Wiping database: ${databaseId}`, { prefix: "Wipe" });
|
144
152
|
const existingCollections = await fetchAllCollections(databaseId, database);
|
145
153
|
let collectionsDeleted = [];
|
154
|
+
if (existingCollections.length === 0) {
|
155
|
+
MessageFormatter.info("No collections to delete", { prefix: "Wipe" });
|
156
|
+
return collectionsDeleted;
|
157
|
+
}
|
158
|
+
const progress = ProgressManager.create(`wipe-db-${databaseId}`, existingCollections.length, { title: "Deleting collections" });
|
159
|
+
let processed = 0;
|
146
160
|
for (const { $id: collectionId, name: name } of existingCollections) {
|
147
|
-
|
161
|
+
MessageFormatter.progress(`Deleting collection: ${collectionId}`, { prefix: "Wipe" });
|
148
162
|
collectionsDeleted.push({
|
149
163
|
collectionId: collectionId,
|
150
164
|
collectionName: name,
|
151
165
|
});
|
152
166
|
tryAwaitWithRetry(async () => await database.deleteCollection(databaseId, collectionId)); // Try to delete the collection and ignore errors if it doesn't exist or if it's already being deleted
|
167
|
+
processed++;
|
168
|
+
progress.update(processed);
|
153
169
|
await delay(100);
|
154
170
|
}
|
171
|
+
progress.stop();
|
172
|
+
MessageFormatter.success(`Deleted ${collectionsDeleted.length} collections from database`, { prefix: "Wipe" });
|
155
173
|
return collectionsDeleted;
|
156
174
|
};
|
157
175
|
export const wipeCollection = async (database, databaseId, collectionId) => {
|
@@ -159,7 +177,7 @@ export const wipeCollection = async (database, databaseId, collectionId) => {
|
|
159
177
|
Query.equal("$id", collectionId),
|
160
178
|
]);
|
161
179
|
if (collections.total === 0) {
|
162
|
-
|
180
|
+
MessageFormatter.warning(`Collection ${collectionId} not found`, { prefix: "Wipe" });
|
163
181
|
return;
|
164
182
|
}
|
165
183
|
const collection = collections.collections[0];
|
@@ -202,7 +220,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
|
|
202
220
|
permissions.push(Permission.write(permission.target));
|
203
221
|
break;
|
204
222
|
default:
|
205
|
-
|
223
|
+
MessageFormatter.warning(`Unknown permission: ${permission.permission}`, { prefix: "Collections" });
|
206
224
|
break;
|
207
225
|
}
|
208
226
|
}
|
@@ -216,7 +234,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
|
|
216
234
|
// Determine the correct ID for the collection
|
217
235
|
let collectionId;
|
218
236
|
if (!collectionToUse) {
|
219
|
-
|
237
|
+
MessageFormatter.info(`Creating collection: ${collectionData.name}`, { prefix: "Collections" });
|
220
238
|
let foundColl = deletedCollections?.find((coll) => coll.collectionName.toLowerCase().trim().replace(" ", "") ===
|
221
239
|
collectionData.name.toLowerCase().trim().replace(" ", ""));
|
222
240
|
if (collectionData.$id) {
|
@@ -236,18 +254,18 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
|
|
236
254
|
nameToIdMapping.set(collectionData.name, collectionToUse.$id);
|
237
255
|
}
|
238
256
|
catch (error) {
|
239
|
-
|
257
|
+
MessageFormatter.error(`Failed to create collection ${collectionData.name} with ID ${collectionId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Collections" });
|
240
258
|
continue;
|
241
259
|
}
|
242
260
|
}
|
243
261
|
else {
|
244
|
-
|
262
|
+
MessageFormatter.info(`Collection ${collectionData.name} exists, updating it`, { prefix: "Collections" });
|
245
263
|
await tryAwaitWithRetry(async () => await database.updateCollection(databaseId, collectionToUse.$id, collectionData.name, permissions, collectionData.documentSecurity ?? false, collectionData.enabled ?? true));
|
246
264
|
}
|
247
265
|
// Add delay after creating/updating collection
|
248
266
|
await delay(250);
|
249
267
|
// Update attributes and indexes for the collection
|
250
|
-
|
268
|
+
MessageFormatter.progress("Creating Attributes", { prefix: "Collections" });
|
251
269
|
await createUpdateCollectionAttributes(database, databaseId, collectionToUse,
|
252
270
|
// @ts-expect-error
|
253
271
|
attributes);
|
@@ -257,7 +275,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
|
|
257
275
|
? indexes
|
258
276
|
: config.collections?.find((c) => c.$id === collectionToUse.$id)
|
259
277
|
?.indexes ?? [];
|
260
|
-
|
278
|
+
MessageFormatter.progress("Creating Indexes", { prefix: "Collections" });
|
261
279
|
await createOrUpdateIndexes(databaseId, database, collectionToUse.$id, indexesToUse);
|
262
280
|
// Add delay after creating indexes
|
263
281
|
await delay(250);
|
@@ -268,7 +286,7 @@ export const createOrUpdateCollections = async (database, databaseId, config, de
|
|
268
286
|
export const generateMockData = async (database, databaseId, configCollections) => {
|
269
287
|
for (const { collection, mockFunction } of configCollections) {
|
270
288
|
if (mockFunction) {
|
271
|
-
|
289
|
+
MessageFormatter.progress(`Generating mock data for collection: ${collection.name}`, { prefix: "Mock Data" });
|
272
290
|
const mockData = mockFunction();
|
273
291
|
for (const data of mockData) {
|
274
292
|
await database.createDocument(databaseId, collection.$id, ID.unique(), data);
|
@@ -277,7 +295,7 @@ export const generateMockData = async (database, databaseId, configCollections)
|
|
277
295
|
}
|
278
296
|
};
|
279
297
|
export const fetchAllCollections = async (dbId, database) => {
|
280
|
-
|
298
|
+
MessageFormatter.progress(`Fetching all collections for database ID: ${dbId}`, { prefix: "Collections" });
|
281
299
|
let collections = [];
|
282
300
|
let moreCollections = true;
|
283
301
|
let lastCollectionId;
|
@@ -294,7 +312,7 @@ export const fetchAllCollections = async (dbId, database) => {
|
|
294
312
|
response.collections[response.collections.length - 1].$id;
|
295
313
|
}
|
296
314
|
}
|
297
|
-
|
315
|
+
MessageFormatter.success(`Fetched a total of ${collections.length} collections`, { prefix: "Collections" });
|
298
316
|
return collections;
|
299
317
|
};
|
300
318
|
/**
|
@@ -305,7 +323,7 @@ export const transferDocumentsBetweenDbsLocalToLocal = async (db, fromDbId, toDb
|
|
305
323
|
let fromCollDocs = await tryAwaitWithRetry(async () => db.listDocuments(fromDbId, fromCollId, [Query.limit(50)]));
|
306
324
|
let totalDocumentsTransferred = 0;
|
307
325
|
if (fromCollDocs.documents.length === 0) {
|
308
|
-
|
326
|
+
MessageFormatter.info(`No documents found in collection ${fromCollId}`, { prefix: "Transfer" });
|
309
327
|
return;
|
310
328
|
}
|
311
329
|
else if (fromCollDocs.documents.length < 50) {
|
@@ -360,7 +378,7 @@ export const transferDocumentsBetweenDbsLocalToLocal = async (db, fromDbId, toDb
|
|
360
378
|
totalDocumentsTransferred += fromCollDocs.documents.length;
|
361
379
|
}
|
362
380
|
}
|
363
|
-
|
381
|
+
MessageFormatter.success(`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`, { prefix: "Transfer" });
|
364
382
|
};
|
365
383
|
export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint, projectId, apiKey, fromDbId, toDbId, fromCollId, toCollId) => {
|
366
384
|
const client = new Client()
|
@@ -371,7 +389,7 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint
|
|
371
389
|
const remoteDb = new Databases(client);
|
372
390
|
let fromCollDocs = await tryAwaitWithRetry(async () => localDb.listDocuments(fromDbId, fromCollId, [Query.limit(50)]));
|
373
391
|
if (fromCollDocs.documents.length === 0) {
|
374
|
-
|
392
|
+
MessageFormatter.info(`No documents found in collection ${fromCollId}`, { prefix: "Transfer" });
|
375
393
|
return;
|
376
394
|
}
|
377
395
|
else if (fromCollDocs.documents.length < 50) {
|
@@ -426,5 +444,5 @@ export const transferDocumentsBetweenDbsLocalToRemote = async (localDb, endpoint
|
|
426
444
|
totalDocumentsTransferred += fromCollDocs.documents.length;
|
427
445
|
}
|
428
446
|
}
|
429
|
-
|
447
|
+
MessageFormatter.success(`Total documents transferred from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}: ${totalDocumentsTransferred}`, { prefix: "Transfer" });
|
430
448
|
};
|