appwrite-utils-cli 0.9.0 → 0.9.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/README.md +40 -0
- package/dist/main.js +103 -106
- package/dist/migrations/transfer.js +1 -1
- package/package.json +2 -2
- package/src/main.ts +106 -109
- package/src/migrations/transfer.ts +1 -1
package/README.md
CHANGED
@@ -120,3 +120,43 @@ npx appwrite-utils-cli appwrite-migrate --transfer --fromBucketId sourceBucketId
|
|
120
120
|
- The CLI now supports OpenAPI generation for each attribute in the schema. Add a `description` to any attribute or collection, and it will export that schema to the `appwrite/openapi` folder.
|
121
121
|
|
122
122
|
This updated CLI ensures that developers have robust tools at their fingertips to manage complex Appwrite projects effectively from the command line, with both interactive and non-interactive modes available for flexibility.
|
123
|
+
|
124
|
+
## Changelog
|
125
|
+
|
126
|
+
- 0.9.3: Fixed deployment error
|
127
|
+
- 0.9.2: Added changelog back, whoops
|
128
|
+
- 0.0.90: Updated README with new command-line options and fixed alias issues
|
129
|
+
- 0.0.74: Added `--backup` support, even if only one database
|
130
|
+
- 0.0.73: Fixed weird `workspace` issue
|
131
|
+
- 0.0.72: Remove `ulid` for `ulidx`, fixing compatibility issues
|
132
|
+
- 0.0.71: Slight change to file download logic after errors
|
133
|
+
- 0.0.70: Bump to `node-appwrite` version
|
134
|
+
- 0.0.69: Fixed single ID not getting replaced due to the below change =D also, `nice`
|
135
|
+
- 0.0.68: Fixed the occasional case where, when mapping ID's from old data to new, there would be an array of ID's to match against. `idMappings` now supports arrays.
|
136
|
+
- 0.0.67: Fixed `updates` in `importDef`'s update mappings overwriting postImportActions from the original
|
137
|
+
- 0.0.57: Fixed `dataLoader`'s `idMapping`'s giving me issues
|
138
|
+
- 0.0.55: Added `documentExists` check to batch creation functionality to try to prevent duplicates
|
139
|
+
- 0.0.54: Various fixes in here
|
140
|
+
- 0.0.50: Actually fixed the slight bug, it was really in the `mergeObjects`
|
141
|
+
- 0.0.49: Fixed a slight bug with `dataLoader` not mapping updates correctly with `updateMapping`
|
142
|
+
- 0.0.48: Added `--transfer`, `--fromdb <targetDatabaseId>`, `--targetdb <targetDatabaseId>`, `--transferendpoint <transferEndpoint>`, `--transferproject <transferProjectId>`, `--transferkey <transferApiKey>`. Additionally, I've added `--fromcoll <collectionId>` and `--targetcoll <collectionId>`. These allow you to do a few things. First, you can now transfer databases in the same project, and from local to a remote project. Second, you can now specify specific collections to transfer from one place to another, with all of their data. If `--fromcoll` and `--targetcoll` are ommitted, it will transfer the databases. During the database transfer, it will create any missing collections, attributes, and indices.
|
143
|
+
- 0.0.47: Minor bugfixes in many releases, too small to take note of
|
144
|
+
- 0.0.38: Lots of optimizations done to the code, added `tryAwaitWithRetry` for `fetch failed` and others like it errors (looking at you `server error`) -- this should prevent things from going sideways.
|
145
|
+
- 0.0.37: Added `documentSecurity`, `enabled`, and `$id` to the `init` collection
|
146
|
+
- 0.0.36: Made it update collections by default, sometimes you gotta do what you gotta do
|
147
|
+
- 0.0.35: Added update collection if it exists and permissions or such are different (`documentSecurity` and `enabled`), also added a check for `fetch failed` errors to retry them with recursion, not sure how well that will work out, but we're gonna try it! It will still fail after 5 tries, but hopefully that gives Appwrite some time to figure it's stuff out
|
148
|
+
- 0.0.34: Fixed the `bin` section of the package.json, apparently you can't use `node` to run it
|
149
|
+
- 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.
|
150
|
+
- 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`
|
151
|
+
- 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!
|
152
|
+
- 0.0.274: Small improvement for attribute handling, rather than getting it every attribute, I check the collections attributes
|
153
|
+
- 0.0.273: Small fix for relationship attribute comparisons
|
154
|
+
- 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"`)
|
155
|
+
- 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
|
156
|
+
- 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)
|
157
|
+
- 0.0.254: Added `--sync` to synchronize your Appwrite instance with your local `appwriteConfig.yaml` and generate schemas
|
158
|
+
- 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
|
159
|
+
- 0.0.23: Added batching to user deletion
|
160
|
+
- 0.0.22: Converted all import processes except `postImportActions` and Relationship Resolution to the local data import, so it should be much faster.
|
161
|
+
- 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.
|
162
|
+
- 0.0.5: Added `setFieldFromOtherCollectionDocuments` to set an array of ID's for instance from another collection as a `postImportAction`
|
package/dist/main.js
CHANGED
@@ -7,112 +7,109 @@ import { UtilsController } from "./utilsController.js";
|
|
7
7
|
import { Databases, Storage } from "node-appwrite";
|
8
8
|
import { getClient } from "./utils/getClientFromConfig.js";
|
9
9
|
const argv = yargs(hideBin(process.argv))
|
10
|
-
.
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
type: "string",
|
114
|
-
description: "Set the remote Appwrite API key for transfers",
|
115
|
-
});
|
10
|
+
.option("it", {
|
11
|
+
alias: ["interactive", "i"],
|
12
|
+
type: "boolean",
|
13
|
+
description: "Run in interactive mode",
|
14
|
+
})
|
15
|
+
.option("dbIds", {
|
16
|
+
type: "string",
|
17
|
+
description: "Comma-separated list of database IDs to operate on",
|
18
|
+
})
|
19
|
+
.option("collectionIds", {
|
20
|
+
alias: ["collIds"],
|
21
|
+
type: "string",
|
22
|
+
description: "Comma-separated list of collection IDs to operate on",
|
23
|
+
})
|
24
|
+
.option("bucketIds", {
|
25
|
+
type: "string",
|
26
|
+
description: "Comma-separated list of bucket IDs to operate on",
|
27
|
+
})
|
28
|
+
.option("wipe", {
|
29
|
+
choices: ["all", "docs", "users"],
|
30
|
+
description: "Wipe data (all: everything, docs: only documents, users: only user data)",
|
31
|
+
})
|
32
|
+
.option("generate", {
|
33
|
+
type: "boolean",
|
34
|
+
description: "Generate TypeScript schemas from database schemas",
|
35
|
+
})
|
36
|
+
.option("import", {
|
37
|
+
type: "boolean",
|
38
|
+
description: "Import data into your databases",
|
39
|
+
})
|
40
|
+
.option("backup", {
|
41
|
+
type: "boolean",
|
42
|
+
description: "Perform a backup of your databases",
|
43
|
+
})
|
44
|
+
.option("writeData", {
|
45
|
+
type: "boolean",
|
46
|
+
description: "Write converted imported data to file",
|
47
|
+
})
|
48
|
+
.option("push", {
|
49
|
+
type: "boolean",
|
50
|
+
description: "Push your local Appwrite config to your configured Appwrite Project",
|
51
|
+
})
|
52
|
+
.option("sync", {
|
53
|
+
type: "boolean",
|
54
|
+
description: "Synchronize by pulling your Appwrite config from your configured Appwrite Project",
|
55
|
+
})
|
56
|
+
.option("endpoint", {
|
57
|
+
type: "string",
|
58
|
+
description: "Set the Appwrite endpoint",
|
59
|
+
})
|
60
|
+
.option("projectId", {
|
61
|
+
type: "string",
|
62
|
+
description: "Set the Appwrite project ID",
|
63
|
+
})
|
64
|
+
.option("apiKey", {
|
65
|
+
type: "string",
|
66
|
+
description: "Set the Appwrite API key",
|
67
|
+
})
|
68
|
+
.option("transfer", {
|
69
|
+
type: "boolean",
|
70
|
+
description: "Transfer data between databases or collections",
|
71
|
+
})
|
72
|
+
.option("fromDbId", {
|
73
|
+
alias: ["fromDb"],
|
74
|
+
type: "string",
|
75
|
+
description: "Set the source database ID for transfer",
|
76
|
+
})
|
77
|
+
.option("toDbId", {
|
78
|
+
alias: ["toDb"],
|
79
|
+
type: "string",
|
80
|
+
description: "Set the destination database ID for transfer",
|
81
|
+
})
|
82
|
+
.option("fromCollectionId", {
|
83
|
+
alias: ["fromCollId", "fromColl"],
|
84
|
+
type: "string",
|
85
|
+
description: "Set the source collection ID for transfer",
|
86
|
+
})
|
87
|
+
.option("toCollectionId", {
|
88
|
+
alias: ["toCollId", "toColl"],
|
89
|
+
type: "string",
|
90
|
+
description: "Set the destination collection ID for transfer",
|
91
|
+
})
|
92
|
+
.option("fromBucketId", {
|
93
|
+
alias: ["fromBucket"],
|
94
|
+
type: "string",
|
95
|
+
description: "Set the source bucket ID for transfer",
|
96
|
+
})
|
97
|
+
.option("toBucketId", {
|
98
|
+
alias: ["toBucket"],
|
99
|
+
type: "string",
|
100
|
+
description: "Set the destination bucket ID for transfer",
|
101
|
+
})
|
102
|
+
.option("remoteEndpoint", {
|
103
|
+
type: "string",
|
104
|
+
description: "Set the remote Appwrite endpoint for transfers",
|
105
|
+
})
|
106
|
+
.option("remoteProjectId", {
|
107
|
+
type: "string",
|
108
|
+
description: "Set the remote Appwrite project ID for transfers",
|
109
|
+
})
|
110
|
+
.option("remoteApiKey", {
|
111
|
+
type: "string",
|
112
|
+
description: "Set the remote Appwrite API key for transfers",
|
116
113
|
})
|
117
114
|
.help()
|
118
115
|
.parse();
|
@@ -1,7 +1,7 @@
|
|
1
1
|
import { tryAwaitWithRetry } from "appwrite-utils";
|
2
2
|
import { Client, Databases, IndexType, Query, Storage, } from "node-appwrite";
|
3
3
|
import { InputFile } from "node-appwrite/file";
|
4
|
-
import { getAppwriteClient } from "
|
4
|
+
import { getAppwriteClient } from "../utils/helperFunctions.js";
|
5
5
|
import { createOrUpdateAttribute } from "./attributes.js";
|
6
6
|
import { parseAttribute } from "appwrite-utils";
|
7
7
|
export const transferStorageLocalToLocal = async (storage, fromBucketId, toBucketId) => {
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "appwrite-utils-cli",
|
3
3
|
"description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
|
4
|
-
"version": "0.9.
|
4
|
+
"version": "0.9.2",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -25,7 +25,7 @@
|
|
25
25
|
},
|
26
26
|
"scripts": {
|
27
27
|
"build": "bun run tsc",
|
28
|
-
"start": "tsx --no-cache src/main.ts
|
28
|
+
"start": "tsx --no-cache src/main.ts",
|
29
29
|
"deploy": "bun run build && npm publish --access public",
|
30
30
|
"postinstall": "echo 'This package is intended for CLI use only and should not be added as a dependency in other projects.'"
|
31
31
|
},
|
package/src/main.ts
CHANGED
@@ -38,115 +38,112 @@ interface CliOptions {
|
|
38
38
|
type ParsedArgv = ArgumentsCamelCase<CliOptions>;
|
39
39
|
|
40
40
|
const argv = yargs(hideBin(process.argv))
|
41
|
-
.
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
type: "string",
|
148
|
-
description: "Set the remote Appwrite API key for transfers",
|
149
|
-
});
|
41
|
+
.option("it", {
|
42
|
+
alias: ["interactive", "i"],
|
43
|
+
type: "boolean",
|
44
|
+
description: "Run in interactive mode",
|
45
|
+
})
|
46
|
+
.option("dbIds", {
|
47
|
+
type: "string",
|
48
|
+
description: "Comma-separated list of database IDs to operate on",
|
49
|
+
})
|
50
|
+
.option("collectionIds", {
|
51
|
+
alias: ["collIds"],
|
52
|
+
type: "string",
|
53
|
+
description: "Comma-separated list of collection IDs to operate on",
|
54
|
+
})
|
55
|
+
.option("bucketIds", {
|
56
|
+
type: "string",
|
57
|
+
description: "Comma-separated list of bucket IDs to operate on",
|
58
|
+
})
|
59
|
+
.option("wipe", {
|
60
|
+
choices: ["all", "docs", "users"] as const,
|
61
|
+
description:
|
62
|
+
"Wipe data (all: everything, docs: only documents, users: only user data)",
|
63
|
+
})
|
64
|
+
.option("generate", {
|
65
|
+
type: "boolean",
|
66
|
+
description: "Generate TypeScript schemas from database schemas",
|
67
|
+
})
|
68
|
+
.option("import", {
|
69
|
+
type: "boolean",
|
70
|
+
description: "Import data into your databases",
|
71
|
+
})
|
72
|
+
.option("backup", {
|
73
|
+
type: "boolean",
|
74
|
+
description: "Perform a backup of your databases",
|
75
|
+
})
|
76
|
+
.option("writeData", {
|
77
|
+
type: "boolean",
|
78
|
+
description: "Write converted imported data to file",
|
79
|
+
})
|
80
|
+
.option("push", {
|
81
|
+
type: "boolean",
|
82
|
+
description:
|
83
|
+
"Push your local Appwrite config to your configured Appwrite Project",
|
84
|
+
})
|
85
|
+
.option("sync", {
|
86
|
+
type: "boolean",
|
87
|
+
description:
|
88
|
+
"Synchronize by pulling your Appwrite config from your configured Appwrite Project",
|
89
|
+
})
|
90
|
+
.option("endpoint", {
|
91
|
+
type: "string",
|
92
|
+
description: "Set the Appwrite endpoint",
|
93
|
+
})
|
94
|
+
.option("projectId", {
|
95
|
+
type: "string",
|
96
|
+
description: "Set the Appwrite project ID",
|
97
|
+
})
|
98
|
+
.option("apiKey", {
|
99
|
+
type: "string",
|
100
|
+
description: "Set the Appwrite API key",
|
101
|
+
})
|
102
|
+
.option("transfer", {
|
103
|
+
type: "boolean",
|
104
|
+
description: "Transfer data between databases or collections",
|
105
|
+
})
|
106
|
+
.option("fromDbId", {
|
107
|
+
alias: ["fromDb"],
|
108
|
+
type: "string",
|
109
|
+
description: "Set the source database ID for transfer",
|
110
|
+
})
|
111
|
+
.option("toDbId", {
|
112
|
+
alias: ["toDb"],
|
113
|
+
type: "string",
|
114
|
+
description: "Set the destination database ID for transfer",
|
115
|
+
})
|
116
|
+
.option("fromCollectionId", {
|
117
|
+
alias: ["fromCollId", "fromColl"],
|
118
|
+
type: "string",
|
119
|
+
description: "Set the source collection ID for transfer",
|
120
|
+
})
|
121
|
+
.option("toCollectionId", {
|
122
|
+
alias: ["toCollId", "toColl"],
|
123
|
+
type: "string",
|
124
|
+
description: "Set the destination collection ID for transfer",
|
125
|
+
})
|
126
|
+
.option("fromBucketId", {
|
127
|
+
alias: ["fromBucket"],
|
128
|
+
type: "string",
|
129
|
+
description: "Set the source bucket ID for transfer",
|
130
|
+
})
|
131
|
+
.option("toBucketId", {
|
132
|
+
alias: ["toBucket"],
|
133
|
+
type: "string",
|
134
|
+
description: "Set the destination bucket ID for transfer",
|
135
|
+
})
|
136
|
+
.option("remoteEndpoint", {
|
137
|
+
type: "string",
|
138
|
+
description: "Set the remote Appwrite endpoint for transfers",
|
139
|
+
})
|
140
|
+
.option("remoteProjectId", {
|
141
|
+
type: "string",
|
142
|
+
description: "Set the remote Appwrite project ID for transfers",
|
143
|
+
})
|
144
|
+
.option("remoteApiKey", {
|
145
|
+
type: "string",
|
146
|
+
description: "Set the remote Appwrite API key for transfers",
|
150
147
|
})
|
151
148
|
.help()
|
152
149
|
.parse();
|
@@ -8,7 +8,7 @@ import {
|
|
8
8
|
type Models,
|
9
9
|
} from "node-appwrite";
|
10
10
|
import { InputFile } from "node-appwrite/file";
|
11
|
-
import { getAppwriteClient } from "
|
11
|
+
import { getAppwriteClient } from "../utils/helperFunctions.js";
|
12
12
|
import { createOrUpdateAttribute } from "./attributes.js";
|
13
13
|
import { parseAttribute } from "appwrite-utils";
|
14
14
|
|