appwrite-utils-cli 0.0.274 → 0.0.276
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 +4 -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 +97 -71
- 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 +4 -4
- 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 -150
- package/src/migrations/backup.ts +1 -1
- package/src/migrations/collections.ts +5 -11
- 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,41 +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
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
);
|
64
|
-
foundAttribute = parseAttribute(foundAttribute);
|
32
|
+
const collectionAttr = collection.attributes.find(
|
33
|
+
// @ts-expect-error
|
34
|
+
(attr) => attr.key === attribute.key
|
35
|
+
) as unknown;
|
36
|
+
foundAttribute = parseAttribute(collectionAttr);
|
65
37
|
} catch (error) {
|
66
38
|
foundAttribute = undefined;
|
67
39
|
}
|
68
|
-
|
69
|
-
if (
|
70
|
-
|
71
|
-
|
72
|
-
|
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
|
+
) {
|
73
87
|
console.log(
|
74
|
-
`Deleting attribute with same key ${
|
75
|
-
|
76
|
-
} but different values -- ${JSON.stringify(
|
88
|
+
`Deleting attribute with same key ${
|
89
|
+
attribute.key
|
90
|
+
} -- but different values -- ${JSON.stringify(
|
77
91
|
attribute,
|
78
92
|
null,
|
79
93
|
2
|
80
94
|
)} -- ${JSON.stringify(foundAttribute, null, 2)}`
|
81
95
|
);
|
82
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;
|
83
102
|
}
|
84
103
|
|
85
104
|
// Relationship attribute logic with adjustments
|
86
105
|
let collectionFoundViaRelatedCollection: Models.Collection | undefined;
|
87
106
|
let relatedCollectionId: string | undefined;
|
88
|
-
if (
|
89
|
-
if (nameToIdMapping.has(
|
90
|
-
relatedCollectionId = nameToIdMapping.get(
|
107
|
+
if (finalAttribute.type === "relationship") {
|
108
|
+
if (nameToIdMapping.has(finalAttribute.relatedCollection)) {
|
109
|
+
relatedCollectionId = nameToIdMapping.get(
|
110
|
+
finalAttribute.relatedCollection
|
111
|
+
);
|
91
112
|
try {
|
92
113
|
collectionFoundViaRelatedCollection = await db.getCollection(
|
93
114
|
dbId,
|
@@ -95,77 +116,104 @@ export const createOrUpdateAttribute = async (
|
|
95
116
|
);
|
96
117
|
} catch (e) {
|
97
118
|
console.log(
|
98
|
-
`Collection not found: ${
|
119
|
+
`Collection not found: ${finalAttribute.relatedCollection} when nameToIdMapping was set`
|
99
120
|
);
|
100
121
|
collectionFoundViaRelatedCollection = undefined;
|
101
122
|
}
|
102
123
|
} else {
|
103
124
|
const collectionsPulled = await db.listCollections(dbId, [
|
104
|
-
Query.equal("name",
|
125
|
+
Query.equal("name", finalAttribute.relatedCollection),
|
105
126
|
]);
|
106
127
|
if (collectionsPulled.total > 0) {
|
107
128
|
collectionFoundViaRelatedCollection = collectionsPulled.collections[0];
|
108
129
|
relatedCollectionId = collectionFoundViaRelatedCollection.$id;
|
109
|
-
nameToIdMapping.set(
|
130
|
+
nameToIdMapping.set(
|
131
|
+
finalAttribute.relatedCollection,
|
132
|
+
relatedCollectionId
|
133
|
+
);
|
110
134
|
}
|
111
135
|
}
|
112
136
|
if (!(relatedCollectionId && collectionFoundViaRelatedCollection)) {
|
113
|
-
console.log(`Enqueueing operation for attribute: ${
|
137
|
+
console.log(`Enqueueing operation for attribute: ${finalAttribute.key}`);
|
114
138
|
enqueueOperation({
|
115
139
|
type: "attribute",
|
116
140
|
collectionId: collection.$id,
|
117
141
|
collection: collection,
|
118
142
|
attribute,
|
119
|
-
dependencies: [
|
143
|
+
dependencies: [finalAttribute.relatedCollection],
|
120
144
|
});
|
121
145
|
return;
|
122
146
|
}
|
123
147
|
}
|
124
|
-
|
125
|
-
switch (
|
148
|
+
finalAttribute = attributeSchema.parse(finalAttribute);
|
149
|
+
switch (finalAttribute.type) {
|
126
150
|
case "string":
|
127
151
|
if (action === "create") {
|
128
152
|
await db.createStringAttribute(
|
129
153
|
dbId,
|
130
154
|
collection.$id,
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
155
|
+
finalAttribute.key,
|
156
|
+
finalAttribute.size,
|
157
|
+
finalAttribute.required || false,
|
158
|
+
(finalAttribute.xdefault as string) || undefined,
|
159
|
+
finalAttribute.array || false,
|
160
|
+
finalAttribute.encrypted
|
137
161
|
);
|
138
162
|
} else {
|
139
163
|
await db.updateStringAttribute(
|
140
164
|
dbId,
|
141
165
|
collection.$id,
|
142
|
-
|
143
|
-
|
144
|
-
|
166
|
+
finalAttribute.key,
|
167
|
+
finalAttribute.required || false,
|
168
|
+
(finalAttribute.xdefault as string) || undefined
|
145
169
|
);
|
146
170
|
}
|
147
171
|
break;
|
148
172
|
case "integer":
|
149
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
|
+
}
|
150
186
|
await db.createIntegerAttribute(
|
151
187
|
dbId,
|
152
188
|
collection.$id,
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
189
|
+
finalAttribute.key,
|
190
|
+
finalAttribute.required || false,
|
191
|
+
finalAttribute.min,
|
192
|
+
finalAttribute.max,
|
193
|
+
finalAttribute.xdefault || undefined,
|
194
|
+
finalAttribute.array
|
159
195
|
);
|
160
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
|
+
}
|
161
209
|
await db.updateIntegerAttribute(
|
162
210
|
dbId,
|
163
211
|
collection.$id,
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
212
|
+
finalAttribute.key,
|
213
|
+
finalAttribute.required || false,
|
214
|
+
finalAttribute.min || 0,
|
215
|
+
finalAttribute.max || 2147483647,
|
216
|
+
finalAttribute.xdefault || undefined
|
169
217
|
);
|
170
218
|
}
|
171
219
|
break;
|
@@ -174,22 +222,22 @@ export const createOrUpdateAttribute = async (
|
|
174
222
|
await db.createFloatAttribute(
|
175
223
|
dbId,
|
176
224
|
collection.$id,
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
225
|
+
finalAttribute.key,
|
226
|
+
finalAttribute.required || false,
|
227
|
+
finalAttribute.min,
|
228
|
+
finalAttribute.max,
|
229
|
+
finalAttribute.xdefault || undefined,
|
230
|
+
finalAttribute.array
|
183
231
|
);
|
184
232
|
} else {
|
185
233
|
await db.updateFloatAttribute(
|
186
234
|
dbId,
|
187
235
|
collection.$id,
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
236
|
+
finalAttribute.key,
|
237
|
+
finalAttribute.required || false,
|
238
|
+
finalAttribute.min || 0,
|
239
|
+
finalAttribute.max || 2147483647,
|
240
|
+
finalAttribute.xdefault || undefined
|
193
241
|
);
|
194
242
|
}
|
195
243
|
break;
|
@@ -198,18 +246,18 @@ export const createOrUpdateAttribute = async (
|
|
198
246
|
await db.createBooleanAttribute(
|
199
247
|
dbId,
|
200
248
|
collection.$id,
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
249
|
+
finalAttribute.key,
|
250
|
+
finalAttribute.required || false,
|
251
|
+
finalAttribute.xdefault || undefined,
|
252
|
+
finalAttribute.array
|
205
253
|
);
|
206
254
|
} else {
|
207
255
|
await db.updateBooleanAttribute(
|
208
256
|
dbId,
|
209
257
|
collection.$id,
|
210
|
-
|
211
|
-
|
212
|
-
|
258
|
+
finalAttribute.key,
|
259
|
+
finalAttribute.required || false,
|
260
|
+
finalAttribute.xdefault || null
|
213
261
|
);
|
214
262
|
}
|
215
263
|
break;
|
@@ -218,18 +266,18 @@ export const createOrUpdateAttribute = async (
|
|
218
266
|
await db.createDatetimeAttribute(
|
219
267
|
dbId,
|
220
268
|
collection.$id,
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
269
|
+
finalAttribute.key,
|
270
|
+
finalAttribute.required || false,
|
271
|
+
finalAttribute.xdefault || undefined,
|
272
|
+
finalAttribute.array
|
225
273
|
);
|
226
274
|
} else {
|
227
275
|
await db.updateDatetimeAttribute(
|
228
276
|
dbId,
|
229
277
|
collection.$id,
|
230
|
-
|
231
|
-
|
232
|
-
|
278
|
+
finalAttribute.key,
|
279
|
+
finalAttribute.required || false,
|
280
|
+
finalAttribute.xdefault || undefined
|
233
281
|
);
|
234
282
|
}
|
235
283
|
break;
|
@@ -238,18 +286,18 @@ export const createOrUpdateAttribute = async (
|
|
238
286
|
await db.createEmailAttribute(
|
239
287
|
dbId,
|
240
288
|
collection.$id,
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
289
|
+
finalAttribute.key,
|
290
|
+
finalAttribute.required || false,
|
291
|
+
finalAttribute.xdefault || undefined,
|
292
|
+
finalAttribute.array
|
245
293
|
);
|
246
294
|
} else {
|
247
295
|
await db.updateEmailAttribute(
|
248
296
|
dbId,
|
249
297
|
collection.$id,
|
250
|
-
|
251
|
-
|
252
|
-
|
298
|
+
finalAttribute.key,
|
299
|
+
finalAttribute.required || false,
|
300
|
+
finalAttribute.xdefault || undefined
|
253
301
|
);
|
254
302
|
}
|
255
303
|
break;
|
@@ -258,18 +306,18 @@ export const createOrUpdateAttribute = async (
|
|
258
306
|
await db.createIpAttribute(
|
259
307
|
dbId,
|
260
308
|
collection.$id,
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
309
|
+
finalAttribute.key,
|
310
|
+
finalAttribute.required || false,
|
311
|
+
finalAttribute.xdefault || undefined,
|
312
|
+
finalAttribute.array
|
265
313
|
);
|
266
314
|
} else {
|
267
315
|
await db.updateIpAttribute(
|
268
316
|
dbId,
|
269
317
|
collection.$id,
|
270
|
-
|
271
|
-
|
272
|
-
|
318
|
+
finalAttribute.key,
|
319
|
+
finalAttribute.required || false,
|
320
|
+
finalAttribute.xdefault || undefined
|
273
321
|
);
|
274
322
|
}
|
275
323
|
break;
|
@@ -278,18 +326,18 @@ export const createOrUpdateAttribute = async (
|
|
278
326
|
await db.createUrlAttribute(
|
279
327
|
dbId,
|
280
328
|
collection.$id,
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
329
|
+
finalAttribute.key,
|
330
|
+
finalAttribute.required || false,
|
331
|
+
finalAttribute.xdefault || undefined,
|
332
|
+
finalAttribute.array
|
285
333
|
);
|
286
334
|
} else {
|
287
335
|
await db.updateUrlAttribute(
|
288
336
|
dbId,
|
289
337
|
collection.$id,
|
290
|
-
|
291
|
-
|
292
|
-
|
338
|
+
finalAttribute.key,
|
339
|
+
finalAttribute.required || false,
|
340
|
+
finalAttribute.xdefault || undefined
|
293
341
|
);
|
294
342
|
}
|
295
343
|
break;
|
@@ -298,20 +346,20 @@ export const createOrUpdateAttribute = async (
|
|
298
346
|
await db.createEnumAttribute(
|
299
347
|
dbId,
|
300
348
|
collection.$id,
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
349
|
+
finalAttribute.key,
|
350
|
+
finalAttribute.elements,
|
351
|
+
finalAttribute.required || false,
|
352
|
+
finalAttribute.xdefault || undefined,
|
353
|
+
finalAttribute.array
|
306
354
|
);
|
307
355
|
} else {
|
308
356
|
await db.updateEnumAttribute(
|
309
357
|
dbId,
|
310
358
|
collection.$id,
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
359
|
+
finalAttribute.key,
|
360
|
+
finalAttribute.elements,
|
361
|
+
finalAttribute.required || false,
|
362
|
+
finalAttribute.xdefault || undefined
|
315
363
|
);
|
316
364
|
}
|
317
365
|
break;
|
@@ -321,18 +369,18 @@ export const createOrUpdateAttribute = async (
|
|
321
369
|
dbId,
|
322
370
|
collection.$id,
|
323
371
|
relatedCollectionId!,
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
372
|
+
finalAttribute.relationType,
|
373
|
+
finalAttribute.twoWay,
|
374
|
+
finalAttribute.key,
|
375
|
+
finalAttribute.twoWayKey,
|
376
|
+
finalAttribute.onDelete
|
329
377
|
);
|
330
378
|
} else {
|
331
379
|
await db.updateRelationshipAttribute(
|
332
380
|
dbId,
|
333
381
|
collection.$id,
|
334
|
-
|
335
|
-
|
382
|
+
finalAttribute.key,
|
383
|
+
finalAttribute.onDelete
|
336
384
|
);
|
337
385
|
}
|
338
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) {
|
@@ -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
|