appwrite-utils-cli 0.9.993 → 0.9.995
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/README.md +1 -2
- package/dist/collections/methods.js +6 -4
- package/dist/functions/deployments.d.ts +4 -0
- package/dist/functions/deployments.js +114 -0
- package/dist/functions/methods.d.ts +13 -8
- package/dist/functions/methods.js +74 -20
- package/dist/functions/templates/count-docs-in-collection/src/main.d.ts +21 -0
- package/dist/functions/templates/count-docs-in-collection/src/main.js +114 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.d.ts +15 -0
- package/dist/functions/templates/count-docs-in-collection/src/request.js +6 -0
- package/dist/functions/templates/typescript-node/src/index.d.ts +11 -0
- package/dist/functions/templates/typescript-node/src/index.js +11 -0
- package/dist/interactiveCLI.d.ts +6 -0
- package/dist/interactiveCLI.js +437 -32
- package/dist/main.js +0 -0
- package/dist/migrations/appwriteToX.js +32 -1
- package/dist/migrations/schemaStrings.d.ts +1 -0
- package/dist/migrations/schemaStrings.js +74 -2
- package/dist/migrations/transfer.js +112 -123
- package/dist/utils/loadConfigs.d.ts +1 -0
- package/dist/utils/loadConfigs.js +19 -0
- package/dist/utils/schemaStrings.js +27 -0
- package/dist/utilsController.d.ts +5 -1
- package/dist/utilsController.js +54 -2
- package/package.json +57 -55
- package/src/collections/methods.ts +29 -10
- package/src/functions/deployments.ts +190 -0
- package/src/functions/methods.ts +295 -235
- package/src/functions/templates/count-docs-in-collection/README.md +54 -0
- package/src/functions/templates/count-docs-in-collection/src/main.ts +159 -0
- package/src/functions/templates/count-docs-in-collection/src/request.ts +9 -0
- package/src/functions/templates/poetry/README.md +30 -0
- package/src/functions/templates/poetry/pyproject.toml +16 -0
- package/src/functions/templates/poetry/src/__init__.py +0 -0
- package/src/functions/templates/poetry/src/index.py +16 -0
- package/src/functions/templates/typescript-node/README.md +32 -0
- package/src/functions/templates/typescript-node/src/index.ts +23 -0
- package/src/interactiveCLI.ts +606 -47
- package/src/migrations/appwriteToX.ts +44 -1
- package/src/migrations/schemaStrings.ts +83 -2
- package/src/migrations/transfer.ts +280 -207
- package/src/setupController.ts +41 -41
- package/src/utils/loadConfigs.ts +24 -0
- package/src/utils/schemaStrings.ts +27 -0
- package/src/utilsController.ts +63 -3
- package/tsconfig.json +8 -1
@@ -9,8 +9,17 @@ import {
|
|
9
9
|
} from "node-appwrite";
|
10
10
|
import { InputFile } from "node-appwrite/file";
|
11
11
|
import { getAppwriteClient } from "../utils/helperFunctions.js";
|
12
|
-
import {
|
12
|
+
import {
|
13
|
+
createOrUpdateAttribute,
|
14
|
+
createUpdateCollectionAttributes,
|
15
|
+
} from "../collections/attributes.js";
|
13
16
|
import { parseAttribute } from "appwrite-utils";
|
17
|
+
import chalk from "chalk";
|
18
|
+
import { fetchAllCollections } from "../collections/methods.js";
|
19
|
+
import {
|
20
|
+
createOrUpdateIndex,
|
21
|
+
createOrUpdateIndexes,
|
22
|
+
} from "../collections/indexes.js";
|
14
23
|
|
15
24
|
export interface TransferOptions {
|
16
25
|
fromDb: Models.Database | undefined;
|
@@ -67,12 +76,12 @@ export const transferStorageLocalToLocal = async (
|
|
67
76
|
try {
|
68
77
|
await tryAwaitWithRetry(
|
69
78
|
async () =>
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
79
|
+
await storage.createFile(
|
80
|
+
toBucketId,
|
81
|
+
file.$id,
|
82
|
+
fileToCreate,
|
83
|
+
file.$permissions
|
84
|
+
)
|
76
85
|
);
|
77
86
|
} catch (error: any) {
|
78
87
|
// File already exists, so we can skip it
|
@@ -112,15 +121,18 @@ export const transferStorageLocalToLocal = async (
|
|
112
121
|
try {
|
113
122
|
await tryAwaitWithRetry(
|
114
123
|
async () =>
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
124
|
+
await storage.createFile(
|
125
|
+
toBucketId,
|
126
|
+
file.$id,
|
127
|
+
fileToCreate,
|
128
|
+
file.$permissions
|
129
|
+
)
|
121
130
|
);
|
122
131
|
} catch (error: any) {
|
123
132
|
// File already exists, so we can skip it
|
133
|
+
console.log(
|
134
|
+
chalk.yellow(`File ${file.$id} already exists, skipping...`)
|
135
|
+
);
|
124
136
|
continue;
|
125
137
|
}
|
126
138
|
numberOfFiles++;
|
@@ -180,15 +192,16 @@ export const transferStorageLocalToRemote = async (
|
|
180
192
|
try {
|
181
193
|
await tryAwaitWithRetry(
|
182
194
|
async () =>
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
195
|
+
await remoteStorage.createFile(
|
196
|
+
toBucketId,
|
197
|
+
file.$id,
|
198
|
+
fileToCreate,
|
199
|
+
file.$permissions
|
200
|
+
)
|
189
201
|
);
|
190
202
|
} catch (error: any) {
|
191
203
|
// File already exists, so we can skip it
|
204
|
+
console.log(chalk.yellow(`File ${file.$id} already exists, skipping...`));
|
192
205
|
continue;
|
193
206
|
}
|
194
207
|
numberOfFiles++;
|
@@ -426,69 +439,64 @@ export const transferDatabaseLocalToLocal = async (
|
|
426
439
|
fromDbId: string,
|
427
440
|
targetDbId: string
|
428
441
|
) => {
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
lastCollectionId = undefined;
|
436
|
-
} else {
|
437
|
-
lastCollectionId =
|
438
|
-
fromCollections.collections[fromCollections.collections.length - 1].$id;
|
439
|
-
while (lastCollectionId) {
|
440
|
-
const collections = await localDb.listCollections(fromDbId, [
|
441
|
-
Query.limit(50),
|
442
|
-
Query.cursorAfter(lastCollectionId),
|
443
|
-
]);
|
444
|
-
allFromCollections.push(...collections.collections);
|
445
|
-
if (collections.collections.length < 50) {
|
446
|
-
break;
|
447
|
-
}
|
448
|
-
lastCollectionId =
|
449
|
-
collections.collections[collections.collections.length - 1].$id;
|
450
|
-
}
|
451
|
-
}
|
452
|
-
lastCollectionId = undefined;
|
453
|
-
let toCollections = await tryAwaitWithRetry(
|
454
|
-
async () => await localDb.listCollections(targetDbId, [Query.limit(50)])
|
442
|
+
// Get all collections from source database
|
443
|
+
const sourceCollections = await fetchAllCollections(fromDbId, localDb);
|
444
|
+
console.log(
|
445
|
+
chalk.blue(
|
446
|
+
`Found ${sourceCollections.length} collections in source database`
|
447
|
+
)
|
455
448
|
);
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
}
|
473
|
-
}
|
474
|
-
}
|
475
|
-
for (const collection of allFromCollections) {
|
476
|
-
const toCollection = allToCollections.find((c) => c.$id === collection.$id);
|
477
|
-
if (toCollection) {
|
478
|
-
await transferDocumentsBetweenDbsLocalToLocal(
|
479
|
-
localDb,
|
480
|
-
fromDbId,
|
481
|
-
targetDbId,
|
482
|
-
collection.$id,
|
483
|
-
toCollection.$id
|
484
|
-
);
|
485
|
-
} else {
|
486
|
-
console.log(
|
487
|
-
`Collection ${collection.name} not found in destination database, creating...`
|
449
|
+
|
450
|
+
// Process each collection
|
451
|
+
for (const collection of sourceCollections) {
|
452
|
+
console.log(
|
453
|
+
chalk.yellow(
|
454
|
+
`Processing collection: ${collection.name} (${collection.$id})`
|
455
|
+
)
|
456
|
+
);
|
457
|
+
|
458
|
+
try {
|
459
|
+
// Create or update collection in target
|
460
|
+
let targetCollection: Models.Collection;
|
461
|
+
const existingCollection = await tryAwaitWithRetry(async () =>
|
462
|
+
localDb.listCollections(targetDbId, [
|
463
|
+
Query.equal("$id", collection.$id),
|
464
|
+
])
|
488
465
|
);
|
489
|
-
|
490
|
-
|
491
|
-
|
466
|
+
|
467
|
+
if (existingCollection.collections.length > 0) {
|
468
|
+
targetCollection = existingCollection.collections[0];
|
469
|
+
console.log(
|
470
|
+
chalk.green(`Collection ${collection.name} exists in target database`)
|
471
|
+
);
|
472
|
+
|
473
|
+
// Update collection if needed
|
474
|
+
if (
|
475
|
+
targetCollection.name !== collection.name ||
|
476
|
+
targetCollection.$permissions !== collection.$permissions ||
|
477
|
+
targetCollection.documentSecurity !== collection.documentSecurity ||
|
478
|
+
targetCollection.enabled !== collection.enabled
|
479
|
+
) {
|
480
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
481
|
+
localDb.updateCollection(
|
482
|
+
targetDbId,
|
483
|
+
collection.$id,
|
484
|
+
collection.name,
|
485
|
+
collection.$permissions,
|
486
|
+
collection.documentSecurity,
|
487
|
+
collection.enabled
|
488
|
+
)
|
489
|
+
);
|
490
|
+
console.log(chalk.green(`Collection ${collection.name} updated`));
|
491
|
+
}
|
492
|
+
} else {
|
493
|
+
console.log(
|
494
|
+
chalk.yellow(
|
495
|
+
`Creating collection ${collection.name} in target database...`
|
496
|
+
)
|
497
|
+
);
|
498
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
499
|
+
localDb.createCollection(
|
492
500
|
targetDbId,
|
493
501
|
collection.$id,
|
494
502
|
collection.name,
|
@@ -496,38 +504,91 @@ export const transferDatabaseLocalToLocal = async (
|
|
496
504
|
collection.documentSecurity,
|
497
505
|
collection.enabled
|
498
506
|
)
|
507
|
+
);
|
508
|
+
}
|
509
|
+
|
510
|
+
// Handle attributes
|
511
|
+
const existingAttributes = await tryAwaitWithRetry(
|
512
|
+
async () =>
|
513
|
+
await localDb.listAttributes(targetDbId, targetCollection.$id)
|
499
514
|
);
|
500
|
-
|
515
|
+
|
501
516
|
for (const attribute of collection.attributes) {
|
502
|
-
|
503
|
-
|
504
|
-
|
517
|
+
const parsedAttribute = parseAttribute(attribute as any);
|
518
|
+
const existingAttribute = existingAttributes.attributes.find(
|
519
|
+
(attr: any) => attr.key === parsedAttribute.key
|
520
|
+
);
|
521
|
+
|
522
|
+
if (!existingAttribute) {
|
523
|
+
await tryAwaitWithRetry(async () =>
|
524
|
+
createOrUpdateAttribute(
|
505
525
|
localDb,
|
506
526
|
targetDbId,
|
507
|
-
|
508
|
-
|
527
|
+
targetCollection,
|
528
|
+
parsedAttribute
|
509
529
|
)
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
530
|
+
);
|
531
|
+
console.log(chalk.green(`Attribute ${parsedAttribute.key} created`));
|
532
|
+
} else {
|
533
|
+
console.log(
|
534
|
+
chalk.blue(
|
535
|
+
`Attribute ${parsedAttribute.key} exists, checking for updates...`
|
536
|
+
)
|
537
|
+
);
|
538
|
+
await tryAwaitWithRetry(async () =>
|
539
|
+
createOrUpdateAttribute(
|
540
|
+
localDb,
|
516
541
|
targetDbId,
|
517
|
-
|
518
|
-
|
519
|
-
index.type as IndexType,
|
520
|
-
index.attributes,
|
521
|
-
index.orders
|
542
|
+
targetCollection,
|
543
|
+
parsedAttribute
|
522
544
|
)
|
545
|
+
);
|
546
|
+
}
|
547
|
+
}
|
548
|
+
|
549
|
+
// Handle indexes
|
550
|
+
const existingIndexes = await tryAwaitWithRetry(
|
551
|
+
async () => await localDb.listIndexes(targetDbId, targetCollection.$id)
|
552
|
+
);
|
553
|
+
|
554
|
+
for (const index of collection.indexes) {
|
555
|
+
const existingIndex = existingIndexes.indexes.find(
|
556
|
+
(idx) => idx.key === index.key
|
523
557
|
);
|
558
|
+
|
559
|
+
if (!existingIndex) {
|
560
|
+
await createOrUpdateIndex(
|
561
|
+
targetDbId,
|
562
|
+
localDb,
|
563
|
+
targetCollection.$id,
|
564
|
+
index as any
|
565
|
+
);
|
566
|
+
console.log(chalk.green(`Index ${index.key} created`));
|
567
|
+
} else {
|
568
|
+
console.log(
|
569
|
+
chalk.blue(`Index ${index.key} exists, checking for updates...`)
|
570
|
+
);
|
571
|
+
await createOrUpdateIndex(
|
572
|
+
targetDbId,
|
573
|
+
localDb,
|
574
|
+
targetCollection.$id,
|
575
|
+
index as any
|
576
|
+
);
|
577
|
+
}
|
524
578
|
}
|
579
|
+
|
580
|
+
// Transfer documents
|
525
581
|
await transferDocumentsBetweenDbsLocalToLocal(
|
526
582
|
localDb,
|
527
583
|
fromDbId,
|
528
584
|
targetDbId,
|
529
585
|
collection.$id,
|
530
|
-
|
586
|
+
targetCollection.$id
|
587
|
+
);
|
588
|
+
} catch (error) {
|
589
|
+
console.error(
|
590
|
+
chalk.red(`Error processing collection ${collection.name}:`),
|
591
|
+
error
|
531
592
|
);
|
532
593
|
}
|
533
594
|
}
|
@@ -544,53 +605,44 @@ export const transferDatabaseLocalToRemote = async (
|
|
544
605
|
const client = getAppwriteClient(endpoint, projectId, apiKey);
|
545
606
|
const remoteDb = new Databases(client);
|
546
607
|
|
547
|
-
|
548
|
-
|
549
|
-
|
608
|
+
// Get all collections from source database
|
609
|
+
const sourceCollections = await fetchAllCollections(fromDbId, localDb);
|
610
|
+
console.log(
|
611
|
+
chalk.blue(
|
612
|
+
`Found ${sourceCollections.length} collections in source database`
|
613
|
+
)
|
550
614
|
);
|
551
|
-
const allFromCollections = fromCollections.collections;
|
552
|
-
if (fromCollections.collections.length >= 50) {
|
553
|
-
lastCollectionId =
|
554
|
-
fromCollections.collections[fromCollections.collections.length - 1].$id;
|
555
|
-
while (lastCollectionId) {
|
556
|
-
const collections = await tryAwaitWithRetry(
|
557
|
-
async () =>
|
558
|
-
await localDb.listCollections(fromDbId, [
|
559
|
-
Query.limit(50),
|
560
|
-
Query.cursorAfter(lastCollectionId!),
|
561
|
-
])
|
562
|
-
);
|
563
|
-
allFromCollections.push(...collections.collections);
|
564
|
-
if (collections.collections.length < 50) {
|
565
|
-
break;
|
566
|
-
}
|
567
|
-
lastCollectionId =
|
568
|
-
collections.collections[collections.collections.length - 1].$id;
|
569
|
-
}
|
570
|
-
}
|
571
615
|
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
])
|
616
|
+
// Process each collection
|
617
|
+
for (const collection of sourceCollections) {
|
618
|
+
console.log(
|
619
|
+
chalk.yellow(
|
620
|
+
`Processing collection: ${collection.name} (${collection.$id})`
|
621
|
+
)
|
579
622
|
);
|
580
623
|
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
624
|
+
try {
|
625
|
+
// Create or update collection in target
|
626
|
+
let targetCollection: Models.Collection;
|
627
|
+
const existingCollection = await tryAwaitWithRetry(async () =>
|
628
|
+
remoteDb.listCollections(toDbId, [Query.equal("$id", collection.$id)])
|
629
|
+
);
|
630
|
+
|
631
|
+
if (existingCollection.collections.length > 0) {
|
632
|
+
targetCollection = existingCollection.collections[0];
|
633
|
+
console.log(
|
634
|
+
chalk.green(`Collection ${collection.name} exists in remote database`)
|
635
|
+
);
|
636
|
+
|
637
|
+
// Update collection if needed
|
638
|
+
if (
|
639
|
+
targetCollection.name !== collection.name ||
|
640
|
+
targetCollection.$permissions !== collection.$permissions ||
|
641
|
+
targetCollection.documentSecurity !== collection.documentSecurity ||
|
642
|
+
targetCollection.enabled !== collection.enabled
|
643
|
+
) {
|
644
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
645
|
+
remoteDb.updateCollection(
|
594
646
|
toDbId,
|
595
647
|
collection.$id,
|
596
648
|
collection.name,
|
@@ -598,13 +650,17 @@ export const transferDatabaseLocalToRemote = async (
|
|
598
650
|
collection.documentSecurity,
|
599
651
|
collection.enabled
|
600
652
|
)
|
653
|
+
);
|
654
|
+
console.log(chalk.green(`Collection ${collection.name} updated`));
|
655
|
+
}
|
656
|
+
} else {
|
657
|
+
console.log(
|
658
|
+
chalk.yellow(
|
659
|
+
`Creating collection ${collection.name} in remote database...`
|
660
|
+
)
|
601
661
|
);
|
602
|
-
|
603
|
-
|
604
|
-
} else {
|
605
|
-
toCollection = await tryAwaitWithRetry(
|
606
|
-
async () =>
|
607
|
-
await remoteDb.createCollection(
|
662
|
+
targetCollection = await tryAwaitWithRetry(async () =>
|
663
|
+
remoteDb.createCollection(
|
608
664
|
toDbId,
|
609
665
|
collection.$id,
|
610
666
|
collection.name,
|
@@ -612,77 +668,94 @@ export const transferDatabaseLocalToRemote = async (
|
|
612
668
|
collection.documentSecurity,
|
613
669
|
collection.enabled
|
614
670
|
)
|
615
|
-
|
616
|
-
|
617
|
-
}
|
671
|
+
);
|
672
|
+
}
|
618
673
|
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
);
|
623
|
-
for (const attribute of collection.attributes) {
|
624
|
-
const parsedAttribute = parseAttribute(attribute as any);
|
625
|
-
const existingAttribute = existingAttributes.attributes.find(
|
626
|
-
// @ts-expect-error
|
627
|
-
(attr) => attr.key === parsedAttribute.key
|
674
|
+
// Handle attributes
|
675
|
+
const existingAttributes = await tryAwaitWithRetry(
|
676
|
+
async () => await remoteDb.listAttributes(toDbId, targetCollection.$id)
|
628
677
|
);
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
678
|
+
|
679
|
+
for (const attribute of collection.attributes) {
|
680
|
+
const parsedAttribute = parseAttribute(attribute as any);
|
681
|
+
const existingAttribute = existingAttributes.attributes.find(
|
682
|
+
(attr: any) => attr.key === parsedAttribute.key
|
683
|
+
);
|
684
|
+
|
685
|
+
if (!existingAttribute) {
|
686
|
+
await tryAwaitWithRetry(async () =>
|
687
|
+
createOrUpdateAttribute(
|
633
688
|
remoteDb,
|
634
689
|
toDbId,
|
635
|
-
|
690
|
+
targetCollection,
|
636
691
|
parsedAttribute
|
637
692
|
)
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
693
|
+
);
|
694
|
+
console.log(chalk.green(`Attribute ${parsedAttribute.key} created`));
|
695
|
+
} else {
|
696
|
+
console.log(
|
697
|
+
chalk.blue(
|
698
|
+
`Attribute ${parsedAttribute.key} exists, checking for updates...`
|
699
|
+
)
|
700
|
+
);
|
701
|
+
await tryAwaitWithRetry(async () =>
|
702
|
+
createOrUpdateAttribute(
|
703
|
+
remoteDb,
|
704
|
+
toDbId,
|
705
|
+
targetCollection,
|
706
|
+
parsedAttribute
|
707
|
+
)
|
708
|
+
);
|
709
|
+
}
|
645
710
|
}
|
646
|
-
}
|
647
711
|
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
);
|
652
|
-
for (const index of collection.indexes) {
|
653
|
-
const existingIndex = existingIndexes.indexes.find(
|
654
|
-
(idx) => idx.key === index.key
|
712
|
+
// Handle indexes
|
713
|
+
const existingIndexes = await tryAwaitWithRetry(
|
714
|
+
async () => await remoteDb.listIndexes(toDbId, targetCollection.$id)
|
655
715
|
);
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
toDbId,
|
661
|
-
toCollection.$id,
|
662
|
-
index.key,
|
663
|
-
index.type as IndexType,
|
664
|
-
index.attributes,
|
665
|
-
index.orders
|
666
|
-
)
|
716
|
+
|
717
|
+
for (const index of collection.indexes) {
|
718
|
+
const existingIndex = existingIndexes.indexes.find(
|
719
|
+
(idx) => idx.key === index.key
|
667
720
|
);
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
721
|
+
|
722
|
+
if (!existingIndex) {
|
723
|
+
await createOrUpdateIndex(
|
724
|
+
toDbId,
|
725
|
+
remoteDb,
|
726
|
+
targetCollection.$id,
|
727
|
+
index as any
|
728
|
+
);
|
729
|
+
console.log(chalk.green(`Index ${index.key} created`));
|
730
|
+
} else {
|
731
|
+
console.log(
|
732
|
+
chalk.blue(`Index ${index.key} exists, checking for updates...`)
|
733
|
+
);
|
734
|
+
await createOrUpdateIndex(
|
735
|
+
toDbId,
|
736
|
+
remoteDb,
|
737
|
+
targetCollection.$id,
|
738
|
+
index as any
|
739
|
+
);
|
740
|
+
}
|
674
741
|
}
|
675
|
-
}
|
676
742
|
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
743
|
+
// Transfer documents
|
744
|
+
await transferDocumentsBetweenDbsLocalToRemote(
|
745
|
+
localDb,
|
746
|
+
endpoint,
|
747
|
+
projectId,
|
748
|
+
apiKey,
|
749
|
+
fromDbId,
|
750
|
+
toDbId,
|
751
|
+
collection.$id,
|
752
|
+
targetCollection.$id
|
753
|
+
);
|
754
|
+
} catch (error) {
|
755
|
+
console.error(
|
756
|
+
chalk.red(`Error processing collection ${collection.name}:`),
|
757
|
+
error
|
758
|
+
);
|
759
|
+
}
|
687
760
|
}
|
688
761
|
};
|
package/src/setupController.ts
CHANGED
@@ -1,42 +1,42 @@
|
|
1
|
-
import { setupDirsFiles } from "./utils/setupFiles.js";
|
2
|
-
import { loadConfig } from "./utils/loadConfigs.js";
|
3
|
-
import path from "path";
|
4
|
-
import fs from "fs";
|
5
|
-
import type { AppwriteConfig } from "appwrite-utils";
|
6
|
-
|
7
|
-
export class SetupController {
|
8
|
-
private currentDir: string;
|
9
|
-
private config: AppwriteConfig | null = null;
|
10
|
-
|
11
|
-
constructor(currentDir: string) {
|
12
|
-
this.currentDir = currentDir;
|
13
|
-
}
|
14
|
-
|
15
|
-
async runSetup(withExampleData: boolean = false): Promise<void> {
|
16
|
-
await setupDirsFiles(withExampleData, this.currentDir);
|
17
|
-
console.log("Setup completed successfully.");
|
18
|
-
}
|
19
|
-
|
20
|
-
async loadConfig(): Promise<AppwriteConfig | null> {
|
21
|
-
if (this.hasExistingConfig()) {
|
22
|
-
try {
|
23
|
-
const appwriteDir = path.join(this.currentDir, "appwrite");
|
24
|
-
this.config = await loadConfig(appwriteDir);
|
25
|
-
return this.config;
|
26
|
-
} catch (error) {
|
27
|
-
console.error("Error loading config:", error);
|
28
|
-
return null;
|
29
|
-
}
|
30
|
-
}
|
31
|
-
return null;
|
32
|
-
}
|
33
|
-
|
34
|
-
hasExistingConfig(): boolean {
|
35
|
-
const configPath = path.join(
|
36
|
-
this.currentDir,
|
37
|
-
"appwrite",
|
38
|
-
"appwriteConfig.ts"
|
39
|
-
);
|
40
|
-
return fs.existsSync(configPath);
|
41
|
-
}
|
1
|
+
import { setupDirsFiles } from "./utils/setupFiles.js";
|
2
|
+
import { loadConfig } from "./utils/loadConfigs.js";
|
3
|
+
import path from "path";
|
4
|
+
import fs from "fs";
|
5
|
+
import type { AppwriteConfig } from "appwrite-utils";
|
6
|
+
|
7
|
+
export class SetupController {
|
8
|
+
private currentDir: string;
|
9
|
+
private config: AppwriteConfig | null = null;
|
10
|
+
|
11
|
+
constructor(currentDir: string) {
|
12
|
+
this.currentDir = currentDir;
|
13
|
+
}
|
14
|
+
|
15
|
+
async runSetup(withExampleData: boolean = false): Promise<void> {
|
16
|
+
await setupDirsFiles(withExampleData, this.currentDir);
|
17
|
+
console.log("Setup completed successfully.");
|
18
|
+
}
|
19
|
+
|
20
|
+
async loadConfig(): Promise<AppwriteConfig | null> {
|
21
|
+
if (this.hasExistingConfig()) {
|
22
|
+
try {
|
23
|
+
const appwriteDir = path.join(this.currentDir, "appwrite");
|
24
|
+
this.config = await loadConfig(appwriteDir);
|
25
|
+
return this.config;
|
26
|
+
} catch (error) {
|
27
|
+
console.error("Error loading config:", error);
|
28
|
+
return null;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return null;
|
32
|
+
}
|
33
|
+
|
34
|
+
hasExistingConfig(): boolean {
|
35
|
+
const configPath = path.join(
|
36
|
+
this.currentDir,
|
37
|
+
"appwrite",
|
38
|
+
"appwriteConfig.ts"
|
39
|
+
);
|
40
|
+
return fs.existsSync(configPath);
|
41
|
+
}
|
42
42
|
}
|