appwrite-utils-cli 0.10.86 → 1.0.2
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 +264 -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 +262 -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 +379 -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 +349 -0
- package/src/utils/loadConfigs.ts +416 -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
@@ -17,6 +17,8 @@ import {
|
|
17
17
|
import { parseAttribute } from "appwrite-utils";
|
18
18
|
import chalk from "chalk";
|
19
19
|
import { fetchAllCollections } from "../collections/methods.js";
|
20
|
+
import { MessageFormatter } from "../shared/messageFormatter.js";
|
21
|
+
import { ProgressManager } from "../shared/progressManager.js";
|
20
22
|
import {
|
21
23
|
createOrUpdateIndex,
|
22
24
|
createOrUpdateIndexes,
|
@@ -41,7 +43,7 @@ export const transferStorageLocalToLocal = async (
|
|
41
43
|
fromBucketId: string,
|
42
44
|
toBucketId: string
|
43
45
|
) => {
|
44
|
-
|
46
|
+
MessageFormatter.info(`Transferring files from ${fromBucketId} to ${toBucketId}`, { prefix: "Transfer" });
|
45
47
|
let lastFileId: string | undefined;
|
46
48
|
let fromFiles = await tryAwaitWithRetry(
|
47
49
|
async () => await storage.listFiles(fromBucketId, [Query.limit(100)])
|
@@ -55,7 +57,7 @@ export const transferStorageLocalToLocal = async (
|
|
55
57
|
try {
|
56
58
|
return await storage.getFileDownload(bucketId, fileId);
|
57
59
|
} catch (error) {
|
58
|
-
|
60
|
+
MessageFormatter.error(`Error downloading file ${fileId}`, error instanceof Error ? error : new Error(String(error)), { prefix: "Transfer" });
|
59
61
|
attempts--;
|
60
62
|
if (attempts === 0) throw error;
|
61
63
|
}
|
@@ -68,14 +70,14 @@ export const transferStorageLocalToLocal = async (
|
|
68
70
|
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
69
71
|
);
|
70
72
|
if (!fileData) {
|
71
|
-
|
73
|
+
MessageFormatter.error(`Error downloading file ${file.$id}`, undefined, { prefix: "Transfer" });
|
72
74
|
continue;
|
73
75
|
}
|
74
76
|
const fileToCreate = InputFile.fromBuffer(
|
75
77
|
new Uint8Array(fileData),
|
76
78
|
file.name
|
77
79
|
);
|
78
|
-
|
80
|
+
MessageFormatter.progress(`Creating file: ${file.name}`, { prefix: "Transfer" });
|
79
81
|
try {
|
80
82
|
await tryAwaitWithRetry(
|
81
83
|
async () =>
|
@@ -114,7 +116,7 @@ export const transferStorageLocalToLocal = async (
|
|
114
116
|
async () => await downloadFileWithRetry(file.bucketId, file.$id)
|
115
117
|
);
|
116
118
|
if (!fileData) {
|
117
|
-
|
119
|
+
MessageFormatter.error(`Error downloading file ${file.$id}`, undefined, { prefix: "Transfer" });
|
118
120
|
continue;
|
119
121
|
}
|
120
122
|
const fileToCreate = InputFile.fromBuffer(
|
@@ -133,17 +135,16 @@ export const transferStorageLocalToLocal = async (
|
|
133
135
|
);
|
134
136
|
} catch (error: any) {
|
135
137
|
// File already exists, so we can skip it
|
136
|
-
|
137
|
-
chalk.yellow(`File ${file.$id} already exists, skipping...`)
|
138
|
-
);
|
138
|
+
MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
|
139
139
|
continue;
|
140
140
|
}
|
141
141
|
numberOfFiles++;
|
142
142
|
}
|
143
143
|
}
|
144
144
|
|
145
|
-
|
146
|
-
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}
|
145
|
+
MessageFormatter.success(
|
146
|
+
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`,
|
147
|
+
{ prefix: "Transfer" }
|
147
148
|
);
|
148
149
|
};
|
149
150
|
|
@@ -155,8 +156,9 @@ export const transferStorageLocalToRemote = async (
|
|
155
156
|
fromBucketId: string,
|
156
157
|
toBucketId: string
|
157
158
|
) => {
|
158
|
-
|
159
|
-
`Transferring files from current storage ${fromBucketId} to ${endpoint} bucket ${toBucketId}
|
159
|
+
MessageFormatter.info(
|
160
|
+
`Transferring files from current storage ${fromBucketId} to ${endpoint} bucket ${toBucketId}`,
|
161
|
+
{ prefix: "Transfer" }
|
160
162
|
);
|
161
163
|
const client = getAppwriteClient(endpoint, projectId, apiKey);
|
162
164
|
const remoteStorage = new Storage(client);
|
@@ -204,230 +206,20 @@ export const transferStorageLocalToRemote = async (
|
|
204
206
|
);
|
205
207
|
} catch (error: any) {
|
206
208
|
// File already exists, so we can skip it
|
207
|
-
|
209
|
+
MessageFormatter.warning(`File ${file.$id} already exists, skipping...`, { prefix: "Transfer" });
|
208
210
|
continue;
|
209
211
|
}
|
210
212
|
numberOfFiles++;
|
211
213
|
}
|
212
|
-
|
213
|
-
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}
|
214
|
-
|
215
|
-
};
|
216
|
-
|
217
|
-
/**
|
218
|
-
* Transfers all documents from one collection to another in a different database
|
219
|
-
* within the same Appwrite Project
|
220
|
-
*/
|
221
|
-
export const transferDocumentsBetweenDbsLocalToLocal = async (
|
222
|
-
db: Databases,
|
223
|
-
fromDbId: string,
|
224
|
-
toDbId: string,
|
225
|
-
fromCollId: string,
|
226
|
-
toCollId: string
|
227
|
-
) => {
|
228
|
-
let totalDocumentsTransferred = 0;
|
229
|
-
let lastDocumentId: string | undefined;
|
230
|
-
let hasMoreDocuments = true;
|
231
|
-
|
232
|
-
while (hasMoreDocuments) {
|
233
|
-
const queryParams = [Query.limit(50)];
|
234
|
-
if (lastDocumentId) {
|
235
|
-
queryParams.push(Query.cursorAfter(lastDocumentId));
|
236
|
-
}
|
237
|
-
|
238
|
-
const fromCollDocs = await tryAwaitWithRetry(async () =>
|
239
|
-
db.listDocuments(fromDbId, fromCollId, queryParams)
|
240
|
-
);
|
241
|
-
|
242
|
-
if (fromCollDocs.documents.length === 0) {
|
243
|
-
if (totalDocumentsTransferred === 0) {
|
244
|
-
console.log(`No documents found in collection ${fromCollId}`);
|
245
|
-
}
|
246
|
-
break;
|
247
|
-
}
|
248
|
-
|
249
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(
|
250
|
-
async () =>
|
251
|
-
await db.listDocuments(toDbId, toCollId, [
|
252
|
-
Query.equal(
|
253
|
-
"$id",
|
254
|
-
fromCollDocs.documents.map((doc) => doc.$id)
|
255
|
-
),
|
256
|
-
])
|
257
|
-
);
|
258
|
-
|
259
|
-
const docsToCreate = fromCollDocs.documents.filter(
|
260
|
-
(doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id)
|
261
|
-
);
|
262
|
-
|
263
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
264
|
-
const toCreateObject: Partial<typeof doc> = {
|
265
|
-
...doc,
|
266
|
-
};
|
267
|
-
delete toCreateObject.$databaseId;
|
268
|
-
delete toCreateObject.$collectionId;
|
269
|
-
delete toCreateObject.$createdAt;
|
270
|
-
delete toCreateObject.$updatedAt;
|
271
|
-
delete toCreateObject.$id;
|
272
|
-
delete toCreateObject.$permissions;
|
273
|
-
return tryAwaitWithRetry(
|
274
|
-
async () =>
|
275
|
-
await db.createDocument(
|
276
|
-
toDbId,
|
277
|
-
toCollId,
|
278
|
-
doc.$id,
|
279
|
-
toCreateObject,
|
280
|
-
doc.$permissions
|
281
|
-
)
|
282
|
-
);
|
283
|
-
});
|
284
|
-
|
285
|
-
await Promise.all(batchedPromises);
|
286
|
-
totalDocumentsTransferred += docsToCreate.length;
|
287
|
-
|
288
|
-
if (fromCollDocs.documents.length < 50) {
|
289
|
-
hasMoreDocuments = false;
|
290
|
-
} else {
|
291
|
-
lastDocumentId =
|
292
|
-
fromCollDocs.documents[fromCollDocs.documents.length - 1].$id;
|
293
|
-
}
|
294
|
-
}
|
295
|
-
|
296
|
-
console.log(
|
297
|
-
`Transferred ${totalDocumentsTransferred} documents from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}`
|
214
|
+
MessageFormatter.success(
|
215
|
+
`Transferred ${numberOfFiles} files from ${fromBucketId} to ${toBucketId}`,
|
216
|
+
{ prefix: "Transfer" }
|
298
217
|
);
|
299
218
|
};
|
300
219
|
|
301
|
-
|
302
|
-
localDb: Databases,
|
303
|
-
endpoint: string,
|
304
|
-
projectId: string,
|
305
|
-
apiKey: string,
|
306
|
-
fromDbId: string,
|
307
|
-
toDbId: string,
|
308
|
-
fromCollId: string,
|
309
|
-
toCollId: string
|
310
|
-
) => {
|
311
|
-
const client = new Client()
|
312
|
-
.setEndpoint(endpoint)
|
313
|
-
.setProject(projectId)
|
314
|
-
.setKey(apiKey);
|
315
|
-
let totalDocumentsTransferred = 0;
|
316
|
-
const remoteDb = new Databases(client);
|
317
|
-
let fromCollDocs = await tryAwaitWithRetry(async () =>
|
318
|
-
localDb.listDocuments(fromDbId, fromCollId, [Query.limit(50)])
|
319
|
-
);
|
220
|
+
// Document transfer functions moved to collections/methods.ts with enhanced UX
|
320
221
|
|
321
|
-
|
322
|
-
console.log(`No documents found in collection ${fromCollId}`);
|
323
|
-
return;
|
324
|
-
} else if (fromCollDocs.documents.length < 50) {
|
325
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(
|
326
|
-
async () =>
|
327
|
-
await remoteDb.listDocuments(toDbId, toCollId, [
|
328
|
-
Query.equal(
|
329
|
-
"$id",
|
330
|
-
fromCollDocs.documents.map((doc) => doc.$id)
|
331
|
-
),
|
332
|
-
])
|
333
|
-
);
|
334
|
-
const docsToCreate = fromCollDocs.documents.filter(
|
335
|
-
(doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id)
|
336
|
-
);
|
337
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
338
|
-
const toCreateObject: Partial<typeof doc> = {
|
339
|
-
...doc,
|
340
|
-
};
|
341
|
-
delete toCreateObject.$databaseId;
|
342
|
-
delete toCreateObject.$collectionId;
|
343
|
-
delete toCreateObject.$createdAt;
|
344
|
-
delete toCreateObject.$updatedAt;
|
345
|
-
delete toCreateObject.$id;
|
346
|
-
delete toCreateObject.$permissions;
|
347
|
-
return tryAwaitWithRetry(async () =>
|
348
|
-
remoteDb.createDocument(
|
349
|
-
toDbId,
|
350
|
-
toCollId,
|
351
|
-
doc.$id,
|
352
|
-
toCreateObject,
|
353
|
-
doc.$permissions
|
354
|
-
)
|
355
|
-
);
|
356
|
-
});
|
357
|
-
await Promise.all(batchedPromises);
|
358
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
359
|
-
} else {
|
360
|
-
const allDocsToCreateCheck = await tryAwaitWithRetry(
|
361
|
-
async () =>
|
362
|
-
await remoteDb.listDocuments(toDbId, toCollId, [
|
363
|
-
Query.equal(
|
364
|
-
"$id",
|
365
|
-
fromCollDocs.documents.map((doc) => doc.$id)
|
366
|
-
),
|
367
|
-
])
|
368
|
-
);
|
369
|
-
const docsToCreate = fromCollDocs.documents.filter(
|
370
|
-
(doc) => !allDocsToCreateCheck.documents.some((d) => d.$id === doc.$id)
|
371
|
-
);
|
372
|
-
const batchedPromises = docsToCreate.map((doc) => {
|
373
|
-
const toCreateObject: Partial<typeof doc> = {
|
374
|
-
...doc,
|
375
|
-
};
|
376
|
-
delete toCreateObject.$databaseId;
|
377
|
-
delete toCreateObject.$collectionId;
|
378
|
-
delete toCreateObject.$createdAt;
|
379
|
-
delete toCreateObject.$updatedAt;
|
380
|
-
delete toCreateObject.$id;
|
381
|
-
delete toCreateObject.$permissions;
|
382
|
-
return tryAwaitWithRetry(async () =>
|
383
|
-
remoteDb.createDocument(
|
384
|
-
toDbId,
|
385
|
-
toCollId,
|
386
|
-
doc.$id,
|
387
|
-
toCreateObject,
|
388
|
-
doc.$permissions
|
389
|
-
)
|
390
|
-
);
|
391
|
-
});
|
392
|
-
await Promise.all(batchedPromises);
|
393
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
394
|
-
while (fromCollDocs.documents.length === 50) {
|
395
|
-
fromCollDocs = await tryAwaitWithRetry(async () =>
|
396
|
-
localDb.listDocuments(fromDbId, fromCollId, [
|
397
|
-
Query.limit(50),
|
398
|
-
Query.cursorAfter(
|
399
|
-
fromCollDocs.documents[fromCollDocs.documents.length - 1].$id
|
400
|
-
),
|
401
|
-
])
|
402
|
-
);
|
403
|
-
const batchedPromises = fromCollDocs.documents.map((doc) => {
|
404
|
-
const toCreateObject: Partial<typeof doc> = {
|
405
|
-
...doc,
|
406
|
-
};
|
407
|
-
delete toCreateObject.$databaseId;
|
408
|
-
delete toCreateObject.$collectionId;
|
409
|
-
delete toCreateObject.$createdAt;
|
410
|
-
delete toCreateObject.$updatedAt;
|
411
|
-
delete toCreateObject.$id;
|
412
|
-
delete toCreateObject.$permissions;
|
413
|
-
return tryAwaitWithRetry(async () =>
|
414
|
-
remoteDb.createDocument(
|
415
|
-
toDbId,
|
416
|
-
toCollId,
|
417
|
-
doc.$id,
|
418
|
-
toCreateObject,
|
419
|
-
doc.$permissions
|
420
|
-
)
|
421
|
-
);
|
422
|
-
});
|
423
|
-
await Promise.all(batchedPromises);
|
424
|
-
totalDocumentsTransferred += fromCollDocs.documents.length;
|
425
|
-
}
|
426
|
-
}
|
427
|
-
console.log(
|
428
|
-
`Total documents transferred from database ${fromDbId} to database ${toDbId} -- collection ${fromCollId} to collection ${toCollId}: ${totalDocumentsTransferred}`
|
429
|
-
);
|
430
|
-
};
|
222
|
+
// Remote document transfer functions moved to collections/methods.ts with enhanced UX
|
431
223
|
|
432
224
|
/**
|
433
225
|
* Transfers all collections and documents from one local database to another local database.
|
@@ -588,6 +380,7 @@ export const transferDatabaseLocalToLocal = async (
|
|
588
380
|
}
|
589
381
|
|
590
382
|
// Transfer documents
|
383
|
+
const { transferDocumentsBetweenDbsLocalToLocal } = await import("../collections/methods.js");
|
591
384
|
await transferDocumentsBetweenDbsLocalToLocal(
|
592
385
|
localDb,
|
593
386
|
fromDbId,
|
@@ -751,6 +544,7 @@ export const transferDatabaseLocalToRemote = async (
|
|
751
544
|
}
|
752
545
|
|
753
546
|
// Transfer documents
|
547
|
+
const { transferDocumentsBetweenDbsLocalToRemote } = await import("../collections/methods.js");
|
754
548
|
await transferDocumentsBetweenDbsLocalToRemote(
|
755
549
|
localDb,
|
756
550
|
endpoint,
|