appwrite-utils-cli 0.9.77 → 0.9.78
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 -0
- package/dist/collections/attributes.js +12 -5
- package/dist/collections/methods.d.ts +2 -1
- package/dist/collections/methods.js +68 -36
- package/dist/interactiveCLI.d.ts +2 -0
- package/dist/interactiveCLI.js +108 -52
- package/dist/main.js +53 -39
- package/dist/migrations/importController.d.ts +3 -3
- package/dist/migrations/importController.js +126 -149
- package/dist/migrations/setupDatabase.d.ts +2 -1
- package/dist/migrations/setupDatabase.js +27 -5
- package/dist/storage/methods.js +4 -1
- package/dist/utils/setupFiles.js +4 -1
- package/dist/utilsController.d.ts +8 -4
- package/dist/utilsController.js +45 -15
- package/package.json +4 -3
- package/src/collections/attributes.ts +12 -7
- package/src/collections/methods.ts +78 -40
- package/src/interactiveCLI.ts +142 -73
- package/src/main.ts +60 -45
- package/src/migrations/importController.ts +167 -279
- package/src/migrations/setupDatabase.ts +48 -7
- package/src/storage/methods.ts +4 -4
- package/src/utils/setupFiles.ts +4 -1
- package/src/utilsController.ts +50 -13
package/src/utilsController.ts
CHANGED
@@ -9,12 +9,14 @@ import {
|
|
9
9
|
setupMigrationDatabase,
|
10
10
|
ensureDatabasesExist,
|
11
11
|
wipeOtherDatabases,
|
12
|
+
ensureCollectionsExist,
|
12
13
|
} from "./migrations/setupDatabase.js";
|
13
14
|
import {
|
14
15
|
createOrUpdateCollections,
|
15
16
|
wipeDatabase,
|
16
17
|
generateSchemas,
|
17
18
|
fetchAllCollections,
|
19
|
+
wipeCollection,
|
18
20
|
} from "./collections/methods.js";
|
19
21
|
import {
|
20
22
|
backupDatabase,
|
@@ -46,6 +48,7 @@ export interface SetupOptions {
|
|
46
48
|
collections?: string[];
|
47
49
|
doBackup?: boolean;
|
48
50
|
wipeDatabase?: boolean;
|
51
|
+
wipeCollections?: boolean;
|
49
52
|
wipeDocumentStorage?: boolean;
|
50
53
|
wipeUsers?: boolean;
|
51
54
|
generateSchemas?: boolean;
|
@@ -96,6 +99,18 @@ export class UtilsController {
|
|
96
99
|
}
|
97
100
|
}
|
98
101
|
|
102
|
+
async reloadConfig() {
|
103
|
+
this.config = await loadConfig(this.appwriteFolderPath);
|
104
|
+
this.appwriteServer = new Client();
|
105
|
+
this.appwriteServer
|
106
|
+
.setEndpoint(this.config.appwriteEndpoint)
|
107
|
+
.setProject(this.config.appwriteProject)
|
108
|
+
.setKey(this.config.appwriteKey);
|
109
|
+
this.database = new Databases(this.appwriteServer);
|
110
|
+
this.storage = new Storage(this.appwriteServer);
|
111
|
+
this.config.appwriteClient = this.appwriteServer;
|
112
|
+
}
|
113
|
+
|
99
114
|
async setupMigrationDatabase() {
|
100
115
|
await this.init();
|
101
116
|
if (!this.config) throw new Error("Config not initialized");
|
@@ -118,7 +133,13 @@ export class UtilsController {
|
|
118
133
|
if (!this.config) throw new Error("Config not initialized");
|
119
134
|
await this.setupMigrationDatabase();
|
120
135
|
await this.ensureDatabaseConfigBucketsExist(databases);
|
121
|
-
await ensureDatabasesExist(this.config);
|
136
|
+
await ensureDatabasesExist(this.config, databases);
|
137
|
+
}
|
138
|
+
|
139
|
+
async ensureCollectionsExist(database: Models.Database, collections?: Models.Collection[]) {
|
140
|
+
await this.init();
|
141
|
+
if (!this.config) throw new Error("Config not initialized");
|
142
|
+
await ensureCollectionsExist(this.config, database, collections);
|
122
143
|
}
|
123
144
|
|
124
145
|
async getDatabasesByIds(ids: string[]) {
|
@@ -163,25 +184,32 @@ export class UtilsController {
|
|
163
184
|
return await wipeDatabase(this.database, database.$id);
|
164
185
|
}
|
165
186
|
|
187
|
+
async wipeCollection(database: Models.Database, collection: Models.Collection) {
|
188
|
+
await this.init();
|
189
|
+
if (!this.database) throw new Error("Database not initialized");
|
190
|
+
await wipeCollection(this.database, database.$id, collection.$id);
|
191
|
+
}
|
192
|
+
|
166
193
|
async wipeDocumentStorage(bucketId: string) {
|
167
194
|
await this.init();
|
168
195
|
if (!this.storage) throw new Error("Storage not initialized");
|
169
196
|
await wipeDocumentStorage(this.storage, bucketId);
|
170
197
|
}
|
171
198
|
|
172
|
-
async createOrUpdateCollectionsForDatabases(databases: Models.Database[]) {
|
199
|
+
async createOrUpdateCollectionsForDatabases(databases: Models.Database[], collections: Models.Collection[] = []) {
|
173
200
|
await this.init();
|
174
201
|
if (!this.database || !this.config)
|
175
202
|
throw new Error("Database or config not initialized");
|
176
203
|
for (const database of databases) {
|
177
204
|
if (database.$id === "migrations") continue;
|
178
|
-
await this.createOrUpdateCollections(database);
|
205
|
+
await this.createOrUpdateCollections(database, undefined, collections);
|
179
206
|
}
|
180
207
|
}
|
181
208
|
|
182
209
|
async createOrUpdateCollections(
|
183
210
|
database: Models.Database,
|
184
|
-
deletedCollections?: { collectionId: string; collectionName: string }[]
|
211
|
+
deletedCollections?: { collectionId: string; collectionName: string }[],
|
212
|
+
collections: Models.Collection[] = []
|
185
213
|
) {
|
186
214
|
await this.init();
|
187
215
|
if (!this.database || !this.config)
|
@@ -190,7 +218,8 @@ export class UtilsController {
|
|
190
218
|
this.database,
|
191
219
|
database.$id,
|
192
220
|
this.config,
|
193
|
-
deletedCollections
|
221
|
+
deletedCollections,
|
222
|
+
collections
|
194
223
|
);
|
195
224
|
}
|
196
225
|
|
@@ -200,10 +229,12 @@ export class UtilsController {
|
|
200
229
|
await generateSchemas(this.config, this.appwriteFolderPath);
|
201
230
|
}
|
202
231
|
|
203
|
-
async importData(options: SetupOptions) {
|
232
|
+
async importData(options: SetupOptions = {}) {
|
204
233
|
await this.init();
|
205
|
-
if (!this.
|
206
|
-
|
234
|
+
if (!this.database) throw new Error("Database not initialized");
|
235
|
+
if (!this.storage) throw new Error("Storage not initialized");
|
236
|
+
if (!this.config) throw new Error("Config not initialized");
|
237
|
+
|
207
238
|
const importDataActions = new ImportDataActions(
|
208
239
|
this.database,
|
209
240
|
this.storage,
|
@@ -212,15 +243,18 @@ export class UtilsController {
|
|
212
243
|
this.validityRuleDefinitions,
|
213
244
|
this.afterImportActionsDefinitions
|
214
245
|
);
|
246
|
+
|
215
247
|
const importController = new ImportController(
|
216
248
|
this.config,
|
217
249
|
this.database,
|
218
250
|
this.storage,
|
219
251
|
this.appwriteFolderPath,
|
220
252
|
importDataActions,
|
221
|
-
options
|
253
|
+
options,
|
254
|
+
options.databases
|
222
255
|
);
|
223
|
-
|
256
|
+
|
257
|
+
await importController.run(options.collections);
|
224
258
|
}
|
225
259
|
|
226
260
|
async synchronizeConfigurations(
|
@@ -239,13 +273,16 @@ export class UtilsController {
|
|
239
273
|
await appwriteToX.toSchemas(databases);
|
240
274
|
}
|
241
275
|
|
242
|
-
async syncDb() {
|
276
|
+
async syncDb(databases: Models.Database[] = [], collections: Models.Collection[] = []) {
|
243
277
|
await this.init();
|
244
278
|
if (!this.database) throw new Error("Database not initialized");
|
245
|
-
|
279
|
+
if (databases.length === 0) {
|
280
|
+
const allDatabases = await fetchAllDatabases(this.database);
|
281
|
+
databases = allDatabases;
|
282
|
+
}
|
246
283
|
await this.ensureDatabasesExist(databases);
|
247
284
|
await this.ensureDatabaseConfigBucketsExist(databases);
|
248
|
-
await this.createOrUpdateCollectionsForDatabases(databases);
|
285
|
+
await this.createOrUpdateCollectionsForDatabases(databases, collections);
|
249
286
|
}
|
250
287
|
|
251
288
|
getAppwriteFolderPath() {
|