appwrite-utils-cli 0.0.31 → 0.0.33

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 CHANGED
@@ -1,97 +1,98 @@
1
- # appwrite-utils-cli
2
-
3
- ## Overview
4
-
5
- `appwrite-utils-cli` is a powerful command-line interface tool designed for Appwrite developers who need to manage database migrations, schema generation, data import, and much more. This CLI tool facilitates complex tasks like setting up databases, running migrations, generating schemas, and managing backups efficiently, making it an indispensable part of your Appwrite project management.
6
-
7
- ## Features
8
-
9
- - **Easy Configuration**: Initialize your Appwrite project configurations interactively directly from the command line.
10
- - **Database Migrations**: Control the migration process with options to target production, staging, or development environments.
11
- - **Schema Generation**: Generate and manage TypeScript schemas directly from your Appwrite database schemas.
12
- - **Data Import**: Facilitate the import of data into your Appwrite databases with comprehensive command-line support.
13
- - **Backup Management**: Create backups of your Appwrite databases to ensure data integrity and safety.
14
- - **Flexible Database Management**: Includes commands to wipe databases, documents, or user data, providing flexibility in managing your database state during development or testing.
15
-
16
- ## Installation
17
-
18
- To use `appwrite-utils-cli`, you can install it globally via npm to make it accessible from anywhere in your command line:
19
-
20
- ```bash
21
- npm install -g appwrite-utils-cli
22
- ```
23
-
24
- However, due to the nature of the speed at which I am developing this project, I would recommend the following command:
25
-
26
- ```bash
27
- npx --package=appwrite-utils-cli@latest appwrite-migrate --arg1 --arg2 --arg3
28
- ```
29
-
30
- **DO NOT INSTALL THIS LOCALLY INTO YOUR PROJECT, IT IS MEANT TO BE USED AS A COMMAND LINE TOOL ONLY**
31
-
32
- ## Usage
33
-
34
- After installation, you can access the tool directly from your command line using the provided commands. Here's how you can use the different functionalities:
35
-
36
- ### Initialization
37
-
38
- Interactively set up your Appwrite project with necessary configurations:
39
-
40
- ```bash
41
- npx --package=appwrite-utils-cli@latest appwrite-init
42
- ```
43
-
44
- ### Running Migrations and Tasks
45
-
46
- Run migration and management tasks with specific flags according to your needs:
47
-
48
- ```bash
49
- npx --package=appwrite-utils-cli@latest appwrite-migrate --args
50
- ```
51
-
52
- Replace `--args` with the appropriate options:
53
-
54
- - `--prod`: Run tasks in the production environment.
55
- - `--staging`: Run tasks in the staging environment.
56
- - `--dev`: Run tasks in the development environment.
57
- - `--wipe`: Wipe all databases.
58
- - `--wipe-docs` or `--wipeDocs`: Wipe all documents in the databases.
59
- - `--generate`: Generate TypeScript schemas from database schemas.
60
- - `--import`: Import data into your databases.
61
- - `--backup`: Perform a backup of your databases.
62
- - `--wipe-users` or `--wipeUsers`: Wipe all user data.
63
- - `--write-data` or `--writeData`: Write converted imported data to file
64
- - `--sync`: Synchronize your project's config and generate schema for your database
65
- - `--endpoint`: Set a different endpoint for the migration target
66
- - `--project`: Set a different project ID for the migration target
67
- - `--key`: Set a different API key for the migration target
68
-
69
- ### OpenAPI Generation (almost done, in progress)
70
-
71
- Recently, I have also added an optional OpenAPI generation for each attribute in the schema. This is because I needed it and because I felt it would be nice to have. This is done using [this package](https://github.com/asteasolutions/zod-to-openapi), many thanks to them.
72
-
73
- To use it, add a `description` to any attribute or collection, and it will export that schema to the `appwrite/openapi` folder
74
-
75
- This setup ensures that developers have robust tools at their fingertips to manage complex Appwrite projects effectively from the command line. I also have added logging automatically for information and errors as the console can be hard to keep up with.
76
-
77
- ### Roadmap
78
-
79
- - Syncing configuration (DONE)
80
- - Better file format for config (potentially)
81
- - Separation of collections and import configuration from main config
82
-
83
- ### Changelog
84
-
85
- - 0.0.29: If you use the `description` variable in an attribute and collection, it'll add that description to the generated schemas. This assumes you have `zod-to-openpi`
86
- - 0.0.275: THINGS ARE NOW IN TYPESCRIPT WOOHOO. No but for reaal, super happy to report that everything has been converted to TypeScript, just way too many changes, I hope you enjoy it!
87
- - 0.0.274: Small improvement for attribute handling, rather than getting it every attribute, I check the collections attributes
88
- - 0.0.273: Small fix for relationship attribute comparisons
89
- - 0.0.272: That's what I get for not testing lmao, also updated logic for checking for existing attributes to take the `format` into consideration from the database (URL's are not of `type: "url"`, they are of `format: "url"`)
90
- - 0.0.271: Small change to update attributes that are different from each other by deleting the attribute and recreating, as we cannot update most things
91
- - 0.0.270: Fixed enums in `--sync`, added optional OpenAPI generation (in progress, almost done, but wanted to push other changes), added `--endpoint`, `--project`, `--key` as optional parameters to change the target destination (shoutout to [pingu24k](https://github.com/pingu2k4) for pointing out these bugs and suggesting those changes for endpoint customization)
92
- - 0.0.254: Added `--sync` to synchronize your Appwrite instance with your local `appwriteConfig.yaml` and generate schemas
93
- - 0.0.253: Added `--writeData` (or `--write-data`) to command to write the output of the import data to a file called dataLoaderOutput in your root dir
94
- - 0.0.23: Added batching to user deletion
95
- - 0.0.22: Converted all import processes except `postImportActions` and Relationship Resolution to the local data import, so it should be much faster.
96
- - 0.0.6: Added `setTargetFieldFromOtherCollectionDocumentsByMatchingField` for the below, but setting a different field than the field you matched. The names are long, but at least you know what's going on lmao.
97
- - 0.0.5: Added `setFieldFromOtherCollectionDocuments` to set an array of ID's for instance from another collection as a `postImportAction`
1
+ # appwrite-utils-cli
2
+
3
+ ## Overview
4
+
5
+ `appwrite-utils-cli` is a powerful command-line interface tool designed for Appwrite developers who need to manage database migrations, schema generation, data import, and much more. This CLI tool facilitates complex tasks like setting up databases, running migrations, generating schemas, and managing backups efficiently, making it an indispensable part of your Appwrite project management.
6
+
7
+ ## Features
8
+
9
+ - **Easy Configuration**: Initialize your Appwrite project configurations interactively directly from the command line.
10
+ - **Database Migrations**: Control the migration process with options to target production, staging, or development environments.
11
+ - **Schema Generation**: Generate and manage TypeScript schemas directly from your Appwrite database schemas.
12
+ - **Data Import**: Facilitate the import of data into your Appwrite databases with comprehensive command-line support.
13
+ - **Backup Management**: Create backups of your Appwrite databases to ensure data integrity and safety.
14
+ - **Flexible Database Management**: Includes commands to wipe databases, documents, or user data, providing flexibility in managing your database state during development or testing.
15
+
16
+ ## Installation
17
+
18
+ To use `appwrite-utils-cli`, you can install it globally via npm to make it accessible from anywhere in your command line:
19
+
20
+ ```bash
21
+ npm install -g appwrite-utils-cli
22
+ ```
23
+
24
+ However, due to the nature of the speed at which I am developing this project, I would recommend the following command:
25
+
26
+ ```bash
27
+ npx --package=appwrite-utils-cli@latest appwrite-migrate --arg1 --arg2 --arg3
28
+ ```
29
+
30
+ **DO NOT INSTALL THIS LOCALLY INTO YOUR PROJECT, IT IS MEANT TO BE USED AS A COMMAND LINE TOOL ONLY**
31
+
32
+ ## Usage
33
+
34
+ After installation, you can access the tool directly from your command line using the provided commands. Here's how you can use the different functionalities:
35
+
36
+ ### Initialization
37
+
38
+ Interactively set up your Appwrite project with necessary configurations:
39
+
40
+ ```bash
41
+ npx --package=appwrite-utils-cli@latest appwrite-init
42
+ ```
43
+
44
+ ### Running Migrations and Tasks
45
+
46
+ Run migration and management tasks with specific flags according to your needs:
47
+
48
+ ```bash
49
+ npx --package=appwrite-utils-cli@latest appwrite-migrate --args
50
+ ```
51
+
52
+ Replace `--args` with the appropriate options:
53
+
54
+ - `--prod`: Run tasks in the production environment.
55
+ - `--staging`: Run tasks in the staging environment.
56
+ - `--dev`: Run tasks in the development environment.
57
+ - `--wipe`: Wipe all databases.
58
+ - `--wipe-docs` or `--wipeDocs`: Wipe all documents in the databases.
59
+ - `--generate`: Generate TypeScript schemas from database schemas.
60
+ - `--import`: Import data into your databases.
61
+ - `--backup`: Perform a backup of your databases.
62
+ - `--wipe-users` or `--wipeUsers`: Wipe all user data.
63
+ - `--write-data` or `--writeData`: Write converted imported data to file
64
+ - `--sync`: Synchronize your project's config and generate schema for your database
65
+ - `--endpoint`: Set a different endpoint for the migration target
66
+ - `--project`: Set a different project ID for the migration target
67
+ - `--key`: Set a different API key for the migration target
68
+
69
+ ### OpenAPI Generation (almost done, in progress)
70
+
71
+ Recently, I have also added an optional OpenAPI generation for each attribute in the schema. This is because I needed it and because I felt it would be nice to have. This is done using [this package](https://github.com/asteasolutions/zod-to-openapi), many thanks to them.
72
+
73
+ To use it, add a `description` to any attribute or collection, and it will export that schema to the `appwrite/openapi` folder
74
+
75
+ This setup ensures that developers have robust tools at their fingertips to manage complex Appwrite projects effectively from the command line. I also have added logging automatically for information and errors as the console can be hard to keep up with.
76
+
77
+ ### Roadmap
78
+
79
+ - Syncing configuration (DONE)
80
+ - Better file format for config (potentially)
81
+ - Separation of collections and import configuration from main config
82
+
83
+ ### Changelog
84
+
85
+ - 0.0.33: Fixed `idMappings`, if you are importing data and use the `idMappings` functionality, you can set a `fieldToSet` based on the value of a `sourceField` in the current imported items data (whether it's in the final data or the original), in order to match another field in another collection. So if you had a store, and it had items and the items have a Region ID for instance. You can then, in your regionId of the items, setup an `idMapping` that will allow you to map the value of the `targetField` based on the value of the `targetFieldToMatch` in the `targetCollection`. Sounds complex, but it's very useful. Like psuedo-relationship resolution, without the relationships.
86
+ - 0.0.29: If you use the `description` variable in an attribute and collection, it'll add that description to the generated schemas. This assumes you have `zod-to-openpi`
87
+ - 0.0.275: THINGS ARE NOW IN TYPESCRIPT WOOHOO. No but for reaal, super happy to report that everything has been converted to TypeScript, just way too many changes, I hope you enjoy it!
88
+ - 0.0.274: Small improvement for attribute handling, rather than getting it every attribute, I check the collections attributes
89
+ - 0.0.273: Small fix for relationship attribute comparisons
90
+ - 0.0.272: That's what I get for not testing lmao, also updated logic for checking for existing attributes to take the `format` into consideration from the database (URL's are not of `type: "url"`, they are of `format: "url"`)
91
+ - 0.0.271: Small change to update attributes that are different from each other by deleting the attribute and recreating, as we cannot update most things
92
+ - 0.0.270: Fixed enums in `--sync`, added optional OpenAPI generation (in progress, almost done, but wanted to push other changes), added `--endpoint`, `--project`, `--key` as optional parameters to change the target destination (shoutout to [pingu24k](https://github.com/pingu2k4) for pointing out these bugs and suggesting those changes for endpoint customization)
93
+ - 0.0.254: Added `--sync` to synchronize your Appwrite instance with your local `appwriteConfig.yaml` and generate schemas
94
+ - 0.0.253: Added `--writeData` (or `--write-data`) to command to write the output of the import data to a file called dataLoaderOutput in your root dir
95
+ - 0.0.23: Added batching to user deletion
96
+ - 0.0.22: Converted all import processes except `postImportActions` and Relationship Resolution to the local data import, so it should be much faster.
97
+ - 0.0.6: Added `setTargetFieldFromOtherCollectionDocumentsByMatchingField` for the below, but setting a different field than the field you matched. The names are long, but at least you know what's going on lmao.
98
+ - 0.0.5: Added `setFieldFromOtherCollectionDocuments` to set an array of ID's for instance from another collection as a `postImportAction`
@@ -316,6 +316,7 @@ export declare const getMigrationCollectionSchemas: () => {
316
316
  targetField: string;
317
317
  targetCollection: string;
318
318
  fieldToSet?: string | undefined;
319
+ targetFieldToMatch?: string | undefined;
319
320
  }[] | undefined;
320
321
  updateMapping?: {
321
322
  targetField: string;
@@ -568,6 +569,7 @@ export declare const getMigrationCollectionSchemas: () => {
568
569
  targetField: string;
569
570
  targetCollection: string;
570
571
  fieldToSet?: string | undefined;
572
+ targetFieldToMatch?: string | undefined;
571
573
  }[] | undefined;
572
574
  updateMapping?: {
573
575
  targetField: string;
@@ -1,5 +1,5 @@
1
1
  import type { ImportDataActions } from "./importDataActions.js";
2
- import { type AppwriteConfig, type AttributeMappings, type CollectionCreate, type ConfigDatabase, type IdMapping, type ImportDef } from "appwrite-utils";
2
+ import { type AppwriteConfig, type AttributeMappings, type CollectionCreate, type ConfigDatabase, type ImportDef } from "appwrite-utils";
3
3
  import { z } from "zod";
4
4
  import { type Databases } from "node-appwrite";
5
5
  export declare const CollectionImportDataSchema: z.ZodObject<{
@@ -363,6 +363,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
363
363
  idMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
364
364
  sourceField: z.ZodString;
365
365
  fieldToSet: z.ZodOptional<z.ZodString>;
366
+ targetFieldToMatch: z.ZodOptional<z.ZodString>;
366
367
  targetField: z.ZodString;
367
368
  targetCollection: z.ZodString;
368
369
  }, "strip", z.ZodTypeAny, {
@@ -370,11 +371,13 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
370
371
  targetField: string;
371
372
  targetCollection: string;
372
373
  fieldToSet?: string | undefined;
374
+ targetFieldToMatch?: string | undefined;
373
375
  }, {
374
376
  sourceField: string;
375
377
  targetField: string;
376
378
  targetCollection: string;
377
379
  fieldToSet?: string | undefined;
380
+ targetFieldToMatch?: string | undefined;
378
381
  }>, "many">>;
379
382
  updateMapping: z.ZodOptional<z.ZodObject<{
380
383
  originalIdField: z.ZodString;
@@ -484,6 +487,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
484
487
  targetField: string;
485
488
  targetCollection: string;
486
489
  fieldToSet?: string | undefined;
490
+ targetFieldToMatch?: string | undefined;
487
491
  }[] | undefined;
488
492
  updateMapping?: {
489
493
  targetField: string;
@@ -517,6 +521,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
517
521
  targetField: string;
518
522
  targetCollection: string;
519
523
  fieldToSet?: string | undefined;
524
+ targetFieldToMatch?: string | undefined;
520
525
  }[] | undefined;
521
526
  updateMapping?: {
522
527
  targetField: string;
@@ -665,6 +670,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
665
670
  targetField: string;
666
671
  targetCollection: string;
667
672
  fieldToSet?: string | undefined;
673
+ targetFieldToMatch?: string | undefined;
668
674
  }[] | undefined;
669
675
  updateMapping?: {
670
676
  targetField: string;
@@ -819,6 +825,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
819
825
  targetField: string;
820
826
  targetCollection: string;
821
827
  fieldToSet?: string | undefined;
828
+ targetFieldToMatch?: string | undefined;
822
829
  }[] | undefined;
823
830
  updateMapping?: {
824
831
  targetField: string;
@@ -839,6 +846,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
839
846
  idMappings: z.ZodOptional<z.ZodArray<z.ZodObject<{
840
847
  sourceField: z.ZodString;
841
848
  fieldToSet: z.ZodOptional<z.ZodString>;
849
+ targetFieldToMatch: z.ZodOptional<z.ZodString>;
842
850
  targetField: z.ZodString;
843
851
  targetCollection: z.ZodString;
844
852
  }, "strip", z.ZodTypeAny, {
@@ -846,11 +854,13 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
846
854
  targetField: string;
847
855
  targetCollection: string;
848
856
  fieldToSet?: string | undefined;
857
+ targetFieldToMatch?: string | undefined;
849
858
  }, {
850
859
  sourceField: string;
851
860
  targetField: string;
852
861
  targetCollection: string;
853
862
  fieldToSet?: string | undefined;
863
+ targetFieldToMatch?: string | undefined;
854
864
  }>, "many">>;
855
865
  updateMapping: z.ZodOptional<z.ZodObject<{
856
866
  originalIdField: z.ZodString;
@@ -960,6 +970,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
960
970
  targetField: string;
961
971
  targetCollection: string;
962
972
  fieldToSet?: string | undefined;
973
+ targetFieldToMatch?: string | undefined;
963
974
  }[] | undefined;
964
975
  updateMapping?: {
965
976
  targetField: string;
@@ -993,6 +1004,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
993
1004
  targetField: string;
994
1005
  targetCollection: string;
995
1006
  fieldToSet?: string | undefined;
1007
+ targetFieldToMatch?: string | undefined;
996
1008
  }[] | undefined;
997
1009
  updateMapping?: {
998
1010
  targetField: string;
@@ -1031,6 +1043,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1031
1043
  targetField: string;
1032
1044
  targetCollection: string;
1033
1045
  fieldToSet?: string | undefined;
1046
+ targetFieldToMatch?: string | undefined;
1034
1047
  }[] | undefined;
1035
1048
  updateMapping?: {
1036
1049
  targetField: string;
@@ -1069,6 +1082,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1069
1082
  targetField: string;
1070
1083
  targetCollection: string;
1071
1084
  fieldToSet?: string | undefined;
1085
+ targetFieldToMatch?: string | undefined;
1072
1086
  }[] | undefined;
1073
1087
  updateMapping?: {
1074
1088
  targetField: string;
@@ -1109,6 +1123,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1109
1123
  targetField: string;
1110
1124
  targetCollection: string;
1111
1125
  fieldToSet?: string | undefined;
1126
+ targetFieldToMatch?: string | undefined;
1112
1127
  }[] | undefined;
1113
1128
  updateMapping?: {
1114
1129
  targetField: string;
@@ -1257,6 +1272,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1257
1272
  targetField: string;
1258
1273
  targetCollection: string;
1259
1274
  fieldToSet?: string | undefined;
1275
+ targetFieldToMatch?: string | undefined;
1260
1276
  }[] | undefined;
1261
1277
  updateMapping?: {
1262
1278
  targetField: string;
@@ -1301,6 +1317,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1301
1317
  targetField: string;
1302
1318
  targetCollection: string;
1303
1319
  fieldToSet?: string | undefined;
1320
+ targetFieldToMatch?: string | undefined;
1304
1321
  }[] | undefined;
1305
1322
  updateMapping?: {
1306
1323
  targetField: string;
@@ -1452,6 +1469,7 @@ export declare const CollectionImportDataSchema: z.ZodObject<{
1452
1469
  targetField: string;
1453
1470
  targetCollection: string;
1454
1471
  fieldToSet?: string | undefined;
1472
+ targetFieldToMatch?: string | undefined;
1455
1473
  }[] | undefined;
1456
1474
  updateMapping?: {
1457
1475
  targetField: string;
@@ -1501,6 +1519,7 @@ export declare class DataLoader {
1501
1519
  targetField: string;
1502
1520
  targetCollection: string;
1503
1521
  fieldToSet?: string | undefined;
1522
+ targetFieldToMatch?: string | undefined;
1504
1523
  }[] | undefined;
1505
1524
  updateMapping?: {
1506
1525
  targetField: string;
@@ -1649,6 +1668,7 @@ export declare class DataLoader {
1649
1668
  targetField: string;
1650
1669
  targetCollection: string;
1651
1670
  fieldToSet?: string | undefined;
1671
+ targetFieldToMatch?: string | undefined;
1652
1672
  }[] | undefined;
1653
1673
  updateMapping?: {
1654
1674
  targetField: string;
@@ -1697,10 +1717,8 @@ export declare class DataLoader {
1697
1717
  setupMaps(dbId: string): Promise<void>;
1698
1718
  getAllUsers(): Promise<import("node-appwrite").Models.User<import("node-appwrite").Models.Preferences>[]>;
1699
1719
  start(dbId: string): Promise<void>;
1700
- dealWithMergedUsers(): Promise<void>;
1720
+ dealWithMergedUsers(): void;
1701
1721
  updateOldReferencesForNew(): Promise<void>;
1702
- updateReferencesInRelatedCollections(): Promise<void>;
1703
- findNewIdForOldId(oldId: string, idMapping: IdMapping, importDef: ImportDef): any;
1704
1722
  private writeMapsToJsonFile;
1705
1723
  /**
1706
1724
  * Prepares user data by checking for duplicates based on email or phone, adding to a duplicate map if found,