appwrite-utils-cli 0.9.983 → 0.9.984

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.
Files changed (42) hide show
  1. package/dist/main.js +56 -42
  2. package/dist/migrations/dataLoader.js +44 -8
  3. package/dist/migrations/importController.js +16 -7
  4. package/dist/migrations/transfer.d.ts +2 -2
  5. package/dist/utilsController.js +39 -26
  6. package/package.json +1 -1
  7. package/src/appwrite.zip +0 -0
  8. package/src/main.ts +77 -52
  9. package/src/migrations/dataLoader.ts +65 -25
  10. package/src/migrations/importController.ts +30 -19
  11. package/src/migrations/transfer.ts +2 -2
  12. package/src/utilsController.ts +62 -53
  13. package/zlogs/album.json +0 -4
  14. package/zlogs/announcements.json +0 -397
  15. package/zlogs/announcementscomments.json +0 -36
  16. package/zlogs/articles.json +0 -138
  17. package/zlogs/articlescomments.json +0 -4
  18. package/zlogs/artist.json +0 -4
  19. package/zlogs/businesscategories.json +0 -7097
  20. package/zlogs/contacts.json +0 -517063
  21. package/zlogs/contactscouncils.json +0 -61905
  22. package/zlogs/contactssociallinks.json +0 -13776
  23. package/zlogs/councils.json +0 -5076
  24. package/zlogs/documents.json +0 -917
  25. package/zlogs/emails.json +0 -4
  26. package/zlogs/events.json +0 -132625
  27. package/zlogs/genre.json +0 -4
  28. package/zlogs/knowledgebase.json +0 -333
  29. package/zlogs/knowledgebasecomments.json +0 -4
  30. package/zlogs/linkcategories.json +0 -180
  31. package/zlogs/links.json +0 -4364
  32. package/zlogs/memberrequests.json +0 -83
  33. package/zlogs/memberrequestscomments.json +0 -65
  34. package/zlogs/mergedUserMap.json +0 -1
  35. package/zlogs/oldIdToNewIdPerCollectionMap.json +0 -1
  36. package/zlogs/playlist.json +0 -4
  37. package/zlogs/regions.json +0 -145
  38. package/zlogs/song.json +0 -4
  39. package/zlogs/testimonials.json +0 -335
  40. package/zlogs/useractivity.json +0 -4
  41. package/zlogs/userdata.json +0 -4
  42. package/zlogs/users.json +0 -4
@@ -119,27 +119,38 @@ export class ImportController {
119
119
  updatedDb: Models.Database,
120
120
  targetDb: Models.Database
121
121
  ) {
122
- await transferDatabaseLocalToLocal(
123
- this.database,
124
- updatedDb.$id,
125
- targetDb.$id
126
- );
127
-
128
- // Find the corresponding database configs
129
- const updatedDbConfig = this.config.databases.find(
130
- (db) => db.$id === updatedDb.$id
131
- );
132
- const targetDbConfig = this.config.databases.find(
133
- (db) => db.$id === targetDb.$id
134
- );
122
+ if (this.database) {
123
+ await transferDatabaseLocalToLocal(
124
+ this.database,
125
+ updatedDb.$id,
126
+ targetDb.$id
127
+ );
128
+ }
135
129
 
136
- // Transfer database-specific bucket if both databases have a bucket defined
137
- if (updatedDbConfig?.bucket && targetDbConfig?.bucket) {
138
- await transferStorageLocalToLocal(
139
- this.storage,
140
- updatedDbConfig.bucket.$id,
141
- targetDbConfig.bucket.$id
130
+ if (this.storage) {
131
+ // Find the corresponding database configs
132
+ const updatedDbConfig = this.config.databases.find(
133
+ (db) => db.$id === updatedDb.$id
134
+ );
135
+ const targetDbConfig = this.config.databases.find(
136
+ (db) => db.$id === targetDb.$id
142
137
  );
138
+
139
+ const sourceBucketId = updatedDbConfig?.bucket?.$id ||
140
+ (this.config.documentBucketId &&
141
+ `${this.config.documentBucketId}_${updatedDb.$id.toLowerCase().trim().replace(" ", "")}`);
142
+
143
+ const targetBucketId = targetDbConfig?.bucket?.$id ||
144
+ (this.config.documentBucketId &&
145
+ `${this.config.documentBucketId}_${targetDb.$id.toLowerCase().trim().replace(" ", "")}`);
146
+
147
+ if (sourceBucketId && targetBucketId) {
148
+ await transferStorageLocalToLocal(
149
+ this.storage,
150
+ sourceBucketId,
151
+ targetBucketId
152
+ );
153
+ }
143
154
  }
144
155
  }
145
156
 
@@ -13,8 +13,8 @@ import { createOrUpdateAttribute } from "../collections/attributes.js";
13
13
  import { parseAttribute } from "appwrite-utils";
14
14
 
15
15
  export interface TransferOptions {
16
- fromDb: Models.Database;
17
- targetDb: Models.Database;
16
+ fromDb: Models.Database | undefined;
17
+ targetDb: Models.Database | undefined;
18
18
  isRemote: boolean;
19
19
  collections?: string[];
20
20
  transferEndpoint?: string;
@@ -145,6 +145,7 @@ export class UtilsController {
145
145
  async getDatabasesByIds(ids: string[]) {
146
146
  await this.init();
147
147
  if (!this.database) throw new Error("Database not initialized");
148
+ if (ids.length === 0) return [];
148
149
  const dbs = await this.database.list([
149
150
  Query.limit(500),
150
151
  Query.equal("$id", ids),
@@ -289,16 +290,11 @@ export class UtilsController {
289
290
  }
290
291
 
291
292
  async transferData(options: TransferOptions): Promise<void> {
292
- if (!this.database) {
293
- throw new Error(
294
- "Database is not initialized, is the config file correct & created?"
295
- );
296
- }
297
-
293
+ // Remove database requirement check
298
294
  let sourceClient = this.database;
299
- let targetClient: Databases;
300
- let sourceDatabases: Models.Database[];
301
- let targetDatabases: Models.Database[];
295
+ let targetClient: Databases | undefined;
296
+ let sourceDatabases: Models.Database[] = [];
297
+ let targetDatabases: Models.Database[] = [];
302
298
 
303
299
  if (options.isRemote) {
304
300
  if (
@@ -314,63 +310,76 @@ export class UtilsController {
314
310
  options.transferProject,
315
311
  options.transferKey
316
312
  );
317
- targetClient = new Databases(remoteClient);
318
-
319
- sourceDatabases = await fetchAllDatabases(sourceClient);
320
- targetDatabases = await fetchAllDatabases(targetClient);
321
- } else {
313
+
314
+ if (this.database) {
315
+ targetClient = new Databases(remoteClient);
316
+ sourceDatabases = await fetchAllDatabases(sourceClient!);
317
+ targetDatabases = await fetchAllDatabases(targetClient);
318
+ }
319
+ } else if (this.database) {
322
320
  targetClient = sourceClient;
323
- sourceDatabases = targetDatabases = await fetchAllDatabases(sourceClient);
324
- }
325
-
326
- // Validate that the provided databases exist in the fetched lists
327
- const fromDb = sourceDatabases.find((db) => db.$id === options.fromDb.$id);
328
- const targetDb = targetDatabases.find(
329
- (db) => db.$id === options.targetDb.$id
330
- );
331
-
332
- if (!fromDb || !targetDb) {
333
- throw new Error("Source or target database not found");
321
+ sourceDatabases = targetDatabases = await fetchAllDatabases(sourceClient!);
334
322
  }
335
323
 
336
- if (options.isRemote) {
337
- // Remote transfer
338
- await transferDatabaseLocalToRemote(
339
- sourceClient,
340
- options.transferEndpoint!,
341
- options.transferProject!,
342
- options.transferKey!,
343
- fromDb.$id,
344
- targetDb.$id
324
+ // Only validate databases if they're provided in options
325
+ if (options.fromDb && options.targetDb) {
326
+ const fromDb = sourceDatabases.find((db) => db.$id === options.fromDb!.$id);
327
+ const targetDb = targetDatabases.find(
328
+ (db) => db.$id === options.targetDb!.$id
345
329
  );
346
330
 
347
- if (this.storage && options.sourceBucket && options.targetBucket) {
348
- await transferStorageLocalToRemote(
349
- this.storage,
331
+ if (!fromDb || !targetDb) {
332
+ throw new Error("Source or target database not found");
333
+ }
334
+
335
+ if (options.isRemote && targetClient) {
336
+ await transferDatabaseLocalToRemote(
337
+ sourceClient!,
350
338
  options.transferEndpoint!,
351
339
  options.transferProject!,
352
340
  options.transferKey!,
353
- options.sourceBucket.$id,
354
- options.targetBucket.$id
341
+ fromDb.$id,
342
+ targetDb.$id
343
+ );
344
+ } else if (targetClient) {
345
+ await transferDatabaseLocalToLocal(
346
+ sourceClient!,
347
+ fromDb.$id,
348
+ targetDb.$id
355
349
  );
356
350
  }
357
- } else {
358
- // Local transfer
359
- await transferDatabaseLocalToLocal(
360
- sourceClient,
361
- fromDb.$id,
362
- targetDb.$id
363
- );
351
+ }
364
352
 
365
- if (this.storage && options.sourceBucket && options.targetBucket) {
366
- await transferStorageLocalToLocal(
367
- this.storage,
368
- options.sourceBucket.$id,
369
- options.targetBucket.$id
370
- );
353
+ // Handle storage transfer separately
354
+ if (this.storage && (options.sourceBucket || options.fromDb)) {
355
+ const sourceBucketId = options.sourceBucket?.$id ||
356
+ (options.fromDb && this.config?.documentBucketId &&
357
+ `${this.config.documentBucketId}_${options.fromDb.$id.toLowerCase().trim().replace(" ", "")}`);
358
+
359
+ const targetBucketId = options.targetBucket?.$id ||
360
+ (options.targetDb && this.config?.documentBucketId &&
361
+ `${this.config.documentBucketId}_${options.targetDb.$id.toLowerCase().trim().replace(" ", "")}`);
362
+
363
+ if (sourceBucketId && targetBucketId) {
364
+ if (options.isRemote) {
365
+ await transferStorageLocalToRemote(
366
+ this.storage,
367
+ options.transferEndpoint!,
368
+ options.transferProject!,
369
+ options.transferKey!,
370
+ sourceBucketId,
371
+ targetBucketId
372
+ );
373
+ } else {
374
+ await transferStorageLocalToLocal(
375
+ this.storage,
376
+ sourceBucketId,
377
+ targetBucketId
378
+ );
379
+ }
371
380
  }
372
381
  }
373
382
 
374
- console.log("Data transfer completed");
383
+ console.log("Transfer completed");
375
384
  }
376
385
  }
package/zlogs/album.json DELETED
@@ -1,4 +0,0 @@
1
- {
2
- "collection": "album",
3
- "data": []
4
- }