appwrite-utils-cli 0.0.273 → 0.0.275
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 +5 -39
- package/dist/init.d.ts +2 -0
- package/dist/init.js +57 -0
- package/dist/main.js +62 -100
- package/dist/migrations/afterImportActions.d.ts +1 -4
- package/dist/migrations/afterImportActions.js +1 -0
- package/dist/migrations/appwriteToX.d.ts +46 -46
- package/dist/migrations/appwriteToX.js +6 -2
- package/dist/migrations/attributes.d.ts +1 -1
- package/dist/migrations/attributes.js +98 -70
- package/dist/migrations/backup.d.ts +240 -240
- package/dist/migrations/backup.js +1 -1
- package/dist/migrations/collections.d.ts +1 -1
- package/dist/migrations/collections.js +5 -5
- package/dist/migrations/converters.d.ts +9 -127
- package/dist/migrations/converters.js +1 -504
- package/dist/migrations/dataLoader.d.ts +470 -453
- package/dist/migrations/dataLoader.js +19 -1
- package/dist/migrations/dbHelpers.d.ts +1 -1
- package/dist/migrations/dbHelpers.js +3 -0
- package/dist/migrations/importController.d.ts +1 -1
- package/dist/migrations/importController.js +4 -7
- package/dist/migrations/importDataActions.d.ts +4 -6
- package/dist/migrations/importDataActions.js +6 -4
- package/dist/migrations/indexes.d.ts +1 -1
- package/dist/migrations/indexes.js +1 -1
- package/dist/migrations/migrationHelper.d.ts +29 -29
- package/dist/migrations/migrationHelper.js +1 -1
- package/dist/migrations/openapi.d.ts +1 -1
- package/dist/migrations/openapi.js +4 -1
- package/dist/migrations/queue.d.ts +1 -1
- package/dist/migrations/relationships.d.ts +5 -5
- package/dist/migrations/relationships.js +3 -0
- package/dist/migrations/schemaStrings.d.ts +2 -2
- package/dist/migrations/schemaStrings.js +93 -8
- package/dist/migrations/setupDatabase.d.ts +1 -1
- package/dist/migrations/setupDatabase.js +1 -1
- package/dist/migrations/storage.d.ts +1 -1
- package/dist/migrations/users.d.ts +1 -1
- package/dist/schemas/authUser.d.ts +12 -10
- package/dist/types.d.ts +0 -5
- package/dist/types.js +0 -2
- package/dist/utils/helperFunctions.d.ts +2 -3
- package/dist/utils/loadConfigs.d.ts +13 -0
- package/dist/utils/loadConfigs.js +47 -0
- package/dist/utils/setupFiles.d.ts +1 -0
- package/dist/utils/setupFiles.js +98 -223
- package/dist/utilsController.d.ts +1 -3
- package/dist/utilsController.js +14 -18
- package/package.json +9 -2
- package/src/init.ts +64 -0
- package/src/main.ts +73 -98
- package/src/migrations/afterImportActions.ts +1 -5
- package/src/migrations/appwriteToX.ts +6 -2
- package/src/migrations/attributes.ts +198 -145
- package/src/migrations/backup.ts +1 -1
- package/src/migrations/collections.ts +6 -12
- package/src/migrations/converters.ts +1 -540
- package/src/migrations/dataLoader.ts +19 -2
- package/src/migrations/dbHelpers.ts +4 -1
- package/src/migrations/importController.ts +5 -15
- package/src/migrations/importDataActions.ts +10 -14
- package/src/migrations/indexes.ts +1 -1
- package/src/migrations/migrationHelper.ts +1 -1
- package/src/migrations/openapi.ts +4 -1
- package/src/migrations/queue.ts +1 -1
- package/src/migrations/relationships.ts +4 -1
- package/src/migrations/schemaStrings.ts +106 -9
- package/src/migrations/setupDatabase.ts +1 -1
- package/src/migrations/storage.ts +1 -1
- package/src/migrations/users.ts +1 -1
- package/src/types.ts +0 -5
- package/src/utils/helperFunctions.ts +2 -3
- package/src/utils/loadConfigs.ts +55 -0
- package/src/utils/setupFiles.ts +114 -225
- package/src/utilsController.ts +27 -35
- package/src/migrations/schema.ts +0 -748
@@ -1,49 +1,21 @@
|
|
1
1
|
import { Query, type Databases, type Models } from "node-appwrite";
|
2
|
-
import {
|
2
|
+
import {
|
3
|
+
attributeSchema,
|
4
|
+
parseAttribute,
|
5
|
+
type Attribute,
|
6
|
+
} from "appwrite-utils";
|
3
7
|
import { nameToIdMapping, enqueueOperation } from "./queue.js";
|
4
8
|
import _ from "lodash";
|
5
9
|
|
6
|
-
const attributesSame = (
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
return (
|
16
|
-
a.key === b.key &&
|
17
|
-
a.relationType === b.relationType &&
|
18
|
-
a.twoWay === b.twoWay &&
|
19
|
-
a.twoWayKey === b.twoWayKey &&
|
20
|
-
a.required === b.required
|
21
|
-
);
|
22
|
-
}
|
23
|
-
return a.key === b.key && a.array === b.array && a.required === b.required;
|
24
|
-
}
|
25
|
-
|
26
|
-
if (a.type === "string" && a.format) {
|
27
|
-
// @ts-expect-error
|
28
|
-
a.type = a.format;
|
29
|
-
}
|
30
|
-
if (b.type === "string" && b.format) {
|
31
|
-
// @ts-expect-error
|
32
|
-
b.type = b.format;
|
33
|
-
}
|
34
|
-
|
35
|
-
// Handling string types with specific formats in Appwrite
|
36
|
-
if (a.type === "string" && b.type === "string") {
|
37
|
-
return (
|
38
|
-
a.key === b.key &&
|
39
|
-
a.format === b.format &&
|
40
|
-
a.array === b.array &&
|
41
|
-
a.required === b.required
|
42
|
-
);
|
43
|
-
}
|
44
|
-
|
45
|
-
// Fallback to false if none of the above conditions are met
|
46
|
-
return false;
|
10
|
+
const attributesSame = (
|
11
|
+
databaseAttribute: Attribute,
|
12
|
+
configAttribute: Attribute
|
13
|
+
): boolean => {
|
14
|
+
return (
|
15
|
+
databaseAttribute.key == configAttribute.key &&
|
16
|
+
databaseAttribute.type == configAttribute.type &&
|
17
|
+
databaseAttribute.array == configAttribute.array
|
18
|
+
);
|
47
19
|
};
|
48
20
|
|
49
21
|
export const createOrUpdateAttribute = async (
|
@@ -53,36 +25,90 @@ export const createOrUpdateAttribute = async (
|
|
53
25
|
attribute: Attribute
|
54
26
|
): Promise<void> => {
|
55
27
|
let action = "create";
|
56
|
-
let foundAttribute;
|
28
|
+
let foundAttribute: Attribute | undefined;
|
29
|
+
const updateEnabled = false;
|
30
|
+
let finalAttribute: any = attribute;
|
57
31
|
try {
|
58
|
-
|
59
|
-
|
32
|
+
const collectionAttr = collection.attributes.find(
|
33
|
+
// @ts-expect-error
|
34
|
+
(attr) => attr.key === attribute.key
|
35
|
+
) as unknown;
|
36
|
+
foundAttribute = parseAttribute(collectionAttr);
|
60
37
|
} catch (error) {
|
61
38
|
foundAttribute = undefined;
|
62
39
|
}
|
63
|
-
|
64
|
-
if (
|
65
|
-
|
66
|
-
|
67
|
-
|
40
|
+
|
41
|
+
if (
|
42
|
+
foundAttribute &&
|
43
|
+
attributesSame(foundAttribute, attribute) &&
|
44
|
+
updateEnabled
|
45
|
+
) {
|
46
|
+
// Check if mutable properties have changed and set action to "update" if necessary
|
47
|
+
const requiredChanged =
|
48
|
+
"required" in foundAttribute && "required" in attribute
|
49
|
+
? foundAttribute.required !== attribute.required
|
50
|
+
: false;
|
51
|
+
|
52
|
+
// const xdefaultChanged =
|
53
|
+
// "xdefault" in foundAttribute && "xdefault" in attribute
|
54
|
+
// ? foundAttribute.xdefault !== attribute.xdefault
|
55
|
+
// : false;
|
56
|
+
|
57
|
+
const onDeleteChanged =
|
58
|
+
foundAttribute.type === "relationship" &&
|
59
|
+
attribute.type === "relationship" &&
|
60
|
+
"onDelete" in foundAttribute &&
|
61
|
+
"onDelete" in attribute
|
62
|
+
? foundAttribute.onDelete !== attribute.onDelete
|
63
|
+
: false;
|
64
|
+
|
65
|
+
if (requiredChanged || onDeleteChanged) {
|
66
|
+
console.log(
|
67
|
+
`Required changed: ${requiredChanged}\nOnDelete changed: ${onDeleteChanged}`
|
68
|
+
);
|
69
|
+
console.log(
|
70
|
+
`Found attribute: ${JSON.stringify(foundAttribute, null, 2)}`
|
71
|
+
);
|
72
|
+
console.log(`Attribute: ${JSON.stringify(attribute, null, 2)}`);
|
73
|
+
finalAttribute = {
|
74
|
+
...attribute,
|
75
|
+
...foundAttribute,
|
76
|
+
};
|
77
|
+
action = "update";
|
78
|
+
} else {
|
79
|
+
// If no properties that can be updated have changed, return early
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
} else if (
|
83
|
+
foundAttribute &&
|
84
|
+
!attributesSame(foundAttribute, attribute) &&
|
85
|
+
updateEnabled
|
86
|
+
) {
|
68
87
|
console.log(
|
69
|
-
`Deleting attribute with same key ${
|
70
|
-
|
71
|
-
} but different values -- ${JSON.stringify(
|
88
|
+
`Deleting attribute with same key ${
|
89
|
+
attribute.key
|
90
|
+
} -- but different values -- ${JSON.stringify(
|
72
91
|
attribute,
|
73
92
|
null,
|
74
93
|
2
|
75
94
|
)} -- ${JSON.stringify(foundAttribute, null, 2)}`
|
76
95
|
);
|
77
96
|
await db.deleteAttribute(dbId, collection.$id, attribute.key);
|
97
|
+
// After deletion, you might want to create the attribute anew
|
98
|
+
finalAttribute = attribute;
|
99
|
+
action = "create";
|
100
|
+
} else if (!updateEnabled && foundAttribute) {
|
101
|
+
return;
|
78
102
|
}
|
79
103
|
|
80
104
|
// Relationship attribute logic with adjustments
|
81
105
|
let collectionFoundViaRelatedCollection: Models.Collection | undefined;
|
82
106
|
let relatedCollectionId: string | undefined;
|
83
|
-
if (
|
84
|
-
if (nameToIdMapping.has(
|
85
|
-
relatedCollectionId = nameToIdMapping.get(
|
107
|
+
if (finalAttribute.type === "relationship") {
|
108
|
+
if (nameToIdMapping.has(finalAttribute.relatedCollection)) {
|
109
|
+
relatedCollectionId = nameToIdMapping.get(
|
110
|
+
finalAttribute.relatedCollection
|
111
|
+
);
|
86
112
|
try {
|
87
113
|
collectionFoundViaRelatedCollection = await db.getCollection(
|
88
114
|
dbId,
|
@@ -90,77 +116,104 @@ export const createOrUpdateAttribute = async (
|
|
90
116
|
);
|
91
117
|
} catch (e) {
|
92
118
|
console.log(
|
93
|
-
`Collection not found: ${
|
119
|
+
`Collection not found: ${finalAttribute.relatedCollection} when nameToIdMapping was set`
|
94
120
|
);
|
95
121
|
collectionFoundViaRelatedCollection = undefined;
|
96
122
|
}
|
97
123
|
} else {
|
98
124
|
const collectionsPulled = await db.listCollections(dbId, [
|
99
|
-
Query.equal("name",
|
125
|
+
Query.equal("name", finalAttribute.relatedCollection),
|
100
126
|
]);
|
101
127
|
if (collectionsPulled.total > 0) {
|
102
128
|
collectionFoundViaRelatedCollection = collectionsPulled.collections[0];
|
103
129
|
relatedCollectionId = collectionFoundViaRelatedCollection.$id;
|
104
|
-
nameToIdMapping.set(
|
130
|
+
nameToIdMapping.set(
|
131
|
+
finalAttribute.relatedCollection,
|
132
|
+
relatedCollectionId
|
133
|
+
);
|
105
134
|
}
|
106
135
|
}
|
107
136
|
if (!(relatedCollectionId && collectionFoundViaRelatedCollection)) {
|
108
|
-
console.log(`Enqueueing operation for attribute: ${
|
137
|
+
console.log(`Enqueueing operation for attribute: ${finalAttribute.key}`);
|
109
138
|
enqueueOperation({
|
110
139
|
type: "attribute",
|
111
140
|
collectionId: collection.$id,
|
112
141
|
collection: collection,
|
113
142
|
attribute,
|
114
|
-
dependencies: [
|
143
|
+
dependencies: [finalAttribute.relatedCollection],
|
115
144
|
});
|
116
145
|
return;
|
117
146
|
}
|
118
147
|
}
|
119
|
-
|
120
|
-
switch (
|
148
|
+
finalAttribute = attributeSchema.parse(finalAttribute);
|
149
|
+
switch (finalAttribute.type) {
|
121
150
|
case "string":
|
122
151
|
if (action === "create") {
|
123
152
|
await db.createStringAttribute(
|
124
153
|
dbId,
|
125
154
|
collection.$id,
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
155
|
+
finalAttribute.key,
|
156
|
+
finalAttribute.size,
|
157
|
+
finalAttribute.required || false,
|
158
|
+
(finalAttribute.xdefault as string) || undefined,
|
159
|
+
finalAttribute.array || false,
|
160
|
+
finalAttribute.encrypted
|
132
161
|
);
|
133
162
|
} else {
|
134
163
|
await db.updateStringAttribute(
|
135
164
|
dbId,
|
136
165
|
collection.$id,
|
137
|
-
|
138
|
-
|
139
|
-
|
166
|
+
finalAttribute.key,
|
167
|
+
finalAttribute.required || false,
|
168
|
+
(finalAttribute.xdefault as string) || undefined
|
140
169
|
);
|
141
170
|
}
|
142
171
|
break;
|
143
172
|
case "integer":
|
144
173
|
if (action === "create") {
|
174
|
+
if (
|
175
|
+
finalAttribute.min &&
|
176
|
+
BigInt(finalAttribute.min) === BigInt(-9223372036854776000)
|
177
|
+
) {
|
178
|
+
delete finalAttribute.min;
|
179
|
+
}
|
180
|
+
if (
|
181
|
+
finalAttribute.max &&
|
182
|
+
BigInt(finalAttribute.max) === BigInt(9223372036854776000)
|
183
|
+
) {
|
184
|
+
delete finalAttribute.max;
|
185
|
+
}
|
145
186
|
await db.createIntegerAttribute(
|
146
187
|
dbId,
|
147
188
|
collection.$id,
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
189
|
+
finalAttribute.key,
|
190
|
+
finalAttribute.required || false,
|
191
|
+
finalAttribute.min,
|
192
|
+
finalAttribute.max,
|
193
|
+
finalAttribute.xdefault || undefined,
|
194
|
+
finalAttribute.array
|
154
195
|
);
|
155
196
|
} else {
|
197
|
+
if (
|
198
|
+
finalAttribute.min &&
|
199
|
+
BigInt(finalAttribute.min) === BigInt(-9223372036854776000)
|
200
|
+
) {
|
201
|
+
delete finalAttribute.min;
|
202
|
+
}
|
203
|
+
if (
|
204
|
+
finalAttribute.max &&
|
205
|
+
BigInt(finalAttribute.max) === BigInt(9223372036854776000)
|
206
|
+
) {
|
207
|
+
delete finalAttribute.max;
|
208
|
+
}
|
156
209
|
await db.updateIntegerAttribute(
|
157
210
|
dbId,
|
158
211
|
collection.$id,
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
212
|
+
finalAttribute.key,
|
213
|
+
finalAttribute.required || false,
|
214
|
+
finalAttribute.min || 0,
|
215
|
+
finalAttribute.max || 2147483647,
|
216
|
+
finalAttribute.xdefault || undefined
|
164
217
|
);
|
165
218
|
}
|
166
219
|
break;
|
@@ -169,22 +222,22 @@ export const createOrUpdateAttribute = async (
|
|
169
222
|
await db.createFloatAttribute(
|
170
223
|
dbId,
|
171
224
|
collection.$id,
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
225
|
+
finalAttribute.key,
|
226
|
+
finalAttribute.required || false,
|
227
|
+
finalAttribute.min,
|
228
|
+
finalAttribute.max,
|
229
|
+
finalAttribute.xdefault || undefined,
|
230
|
+
finalAttribute.array
|
178
231
|
);
|
179
232
|
} else {
|
180
233
|
await db.updateFloatAttribute(
|
181
234
|
dbId,
|
182
235
|
collection.$id,
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
236
|
+
finalAttribute.key,
|
237
|
+
finalAttribute.required || false,
|
238
|
+
finalAttribute.min || 0,
|
239
|
+
finalAttribute.max || 2147483647,
|
240
|
+
finalAttribute.xdefault || undefined
|
188
241
|
);
|
189
242
|
}
|
190
243
|
break;
|
@@ -193,18 +246,18 @@ export const createOrUpdateAttribute = async (
|
|
193
246
|
await db.createBooleanAttribute(
|
194
247
|
dbId,
|
195
248
|
collection.$id,
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
249
|
+
finalAttribute.key,
|
250
|
+
finalAttribute.required || false,
|
251
|
+
finalAttribute.xdefault || undefined,
|
252
|
+
finalAttribute.array
|
200
253
|
);
|
201
254
|
} else {
|
202
255
|
await db.updateBooleanAttribute(
|
203
256
|
dbId,
|
204
257
|
collection.$id,
|
205
|
-
|
206
|
-
|
207
|
-
|
258
|
+
finalAttribute.key,
|
259
|
+
finalAttribute.required || false,
|
260
|
+
finalAttribute.xdefault || null
|
208
261
|
);
|
209
262
|
}
|
210
263
|
break;
|
@@ -213,18 +266,18 @@ export const createOrUpdateAttribute = async (
|
|
213
266
|
await db.createDatetimeAttribute(
|
214
267
|
dbId,
|
215
268
|
collection.$id,
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
269
|
+
finalAttribute.key,
|
270
|
+
finalAttribute.required || false,
|
271
|
+
finalAttribute.xdefault || undefined,
|
272
|
+
finalAttribute.array
|
220
273
|
);
|
221
274
|
} else {
|
222
275
|
await db.updateDatetimeAttribute(
|
223
276
|
dbId,
|
224
277
|
collection.$id,
|
225
|
-
|
226
|
-
|
227
|
-
|
278
|
+
finalAttribute.key,
|
279
|
+
finalAttribute.required || false,
|
280
|
+
finalAttribute.xdefault || undefined
|
228
281
|
);
|
229
282
|
}
|
230
283
|
break;
|
@@ -233,18 +286,18 @@ export const createOrUpdateAttribute = async (
|
|
233
286
|
await db.createEmailAttribute(
|
234
287
|
dbId,
|
235
288
|
collection.$id,
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
289
|
+
finalAttribute.key,
|
290
|
+
finalAttribute.required || false,
|
291
|
+
finalAttribute.xdefault || undefined,
|
292
|
+
finalAttribute.array
|
240
293
|
);
|
241
294
|
} else {
|
242
295
|
await db.updateEmailAttribute(
|
243
296
|
dbId,
|
244
297
|
collection.$id,
|
245
|
-
|
246
|
-
|
247
|
-
|
298
|
+
finalAttribute.key,
|
299
|
+
finalAttribute.required || false,
|
300
|
+
finalAttribute.xdefault || undefined
|
248
301
|
);
|
249
302
|
}
|
250
303
|
break;
|
@@ -253,18 +306,18 @@ export const createOrUpdateAttribute = async (
|
|
253
306
|
await db.createIpAttribute(
|
254
307
|
dbId,
|
255
308
|
collection.$id,
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
309
|
+
finalAttribute.key,
|
310
|
+
finalAttribute.required || false,
|
311
|
+
finalAttribute.xdefault || undefined,
|
312
|
+
finalAttribute.array
|
260
313
|
);
|
261
314
|
} else {
|
262
315
|
await db.updateIpAttribute(
|
263
316
|
dbId,
|
264
317
|
collection.$id,
|
265
|
-
|
266
|
-
|
267
|
-
|
318
|
+
finalAttribute.key,
|
319
|
+
finalAttribute.required || false,
|
320
|
+
finalAttribute.xdefault || undefined
|
268
321
|
);
|
269
322
|
}
|
270
323
|
break;
|
@@ -273,18 +326,18 @@ export const createOrUpdateAttribute = async (
|
|
273
326
|
await db.createUrlAttribute(
|
274
327
|
dbId,
|
275
328
|
collection.$id,
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
329
|
+
finalAttribute.key,
|
330
|
+
finalAttribute.required || false,
|
331
|
+
finalAttribute.xdefault || undefined,
|
332
|
+
finalAttribute.array
|
280
333
|
);
|
281
334
|
} else {
|
282
335
|
await db.updateUrlAttribute(
|
283
336
|
dbId,
|
284
337
|
collection.$id,
|
285
|
-
|
286
|
-
|
287
|
-
|
338
|
+
finalAttribute.key,
|
339
|
+
finalAttribute.required || false,
|
340
|
+
finalAttribute.xdefault || undefined
|
288
341
|
);
|
289
342
|
}
|
290
343
|
break;
|
@@ -293,20 +346,20 @@ export const createOrUpdateAttribute = async (
|
|
293
346
|
await db.createEnumAttribute(
|
294
347
|
dbId,
|
295
348
|
collection.$id,
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
349
|
+
finalAttribute.key,
|
350
|
+
finalAttribute.elements,
|
351
|
+
finalAttribute.required || false,
|
352
|
+
finalAttribute.xdefault || undefined,
|
353
|
+
finalAttribute.array
|
301
354
|
);
|
302
355
|
} else {
|
303
356
|
await db.updateEnumAttribute(
|
304
357
|
dbId,
|
305
358
|
collection.$id,
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
359
|
+
finalAttribute.key,
|
360
|
+
finalAttribute.elements,
|
361
|
+
finalAttribute.required || false,
|
362
|
+
finalAttribute.xdefault || undefined
|
310
363
|
);
|
311
364
|
}
|
312
365
|
break;
|
@@ -316,18 +369,18 @@ export const createOrUpdateAttribute = async (
|
|
316
369
|
dbId,
|
317
370
|
collection.$id,
|
318
371
|
relatedCollectionId!,
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
372
|
+
finalAttribute.relationType,
|
373
|
+
finalAttribute.twoWay,
|
374
|
+
finalAttribute.key,
|
375
|
+
finalAttribute.twoWayKey,
|
376
|
+
finalAttribute.onDelete
|
324
377
|
);
|
325
378
|
} else {
|
326
379
|
await db.updateRelationshipAttribute(
|
327
380
|
dbId,
|
328
381
|
collection.$id,
|
329
|
-
|
330
|
-
|
382
|
+
finalAttribute.key,
|
383
|
+
finalAttribute.onDelete
|
331
384
|
);
|
332
385
|
}
|
333
386
|
break;
|
package/src/migrations/backup.ts
CHANGED
@@ -1,19 +1,10 @@
|
|
1
1
|
import { Databases, ID, Permission, Query, type Models } from "node-appwrite";
|
2
|
-
import type { AppwriteConfig, CollectionCreate } from "
|
2
|
+
import type { AppwriteConfig, CollectionCreate } from "appwrite-utils";
|
3
3
|
import { nameToIdMapping, processQueue } from "./queue.js";
|
4
4
|
import { createUpdateCollectionAttributes } from "./attributes.js";
|
5
5
|
import { createOrUpdateIndexes } from "./indexes.js";
|
6
|
-
import {
|
7
|
-
ensureDirectoryExistence,
|
8
|
-
toCamelCase,
|
9
|
-
toPascalCase,
|
10
|
-
writeFileSync,
|
11
|
-
} from "../utils/index.js";
|
12
6
|
import _ from "lodash";
|
13
7
|
import { SchemaGenerator } from "./schemaStrings.js";
|
14
|
-
import path from "path";
|
15
|
-
|
16
|
-
const { join } = _;
|
17
8
|
|
18
9
|
export const documentExists = async (
|
19
10
|
db: Databases,
|
@@ -157,6 +148,9 @@ export const createOrUpdateCollections = async (
|
|
157
148
|
deletedCollections?: { collectionId: string; collectionName: string }[]
|
158
149
|
): Promise<void> => {
|
159
150
|
const configCollections = config.collections;
|
151
|
+
if (!configCollections) {
|
152
|
+
return;
|
153
|
+
}
|
160
154
|
const usedIds = new Set(); // To track IDs used in this operation
|
161
155
|
|
162
156
|
for (const { attributes, indexes, ...collection } of configCollections) {
|
@@ -234,7 +228,7 @@ export const createOrUpdateCollections = async (
|
|
234
228
|
continue; // Skip to the next collection on failure
|
235
229
|
}
|
236
230
|
} else {
|
237
|
-
console.log(`Collection ${collection.name}
|
231
|
+
console.log(`Collection ${collection.name} exists, using it`);
|
238
232
|
}
|
239
233
|
|
240
234
|
// Update attributes and indexes for the collection
|
@@ -250,7 +244,7 @@ export const createOrUpdateCollections = async (
|
|
250
244
|
databaseId,
|
251
245
|
database,
|
252
246
|
collectionToUse.$id,
|
253
|
-
indexes
|
247
|
+
indexes ?? []
|
254
248
|
);
|
255
249
|
}
|
256
250
|
// Process any remaining tasks in the queue
|