@strapi/database 4.14.5 → 4.15.0
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/dist/index.js +48 -70
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -244,8 +244,7 @@ const SQL_QUERIES$3 = {
|
|
|
244
244
|
)
|
|
245
245
|
};
|
|
246
246
|
const toStrapiType$2 = (column) => {
|
|
247
|
-
|
|
248
|
-
const rootType = (_a = column.data_type.toLowerCase().match(/[^(), ]+/)) == null ? void 0 : _a[0];
|
|
247
|
+
const rootType = column.data_type.toLowerCase().match(/[^(), ]+/)?.[0];
|
|
249
248
|
switch (rootType) {
|
|
250
249
|
case "integer": {
|
|
251
250
|
return { type: "integer" };
|
|
@@ -540,8 +539,7 @@ const SQL_QUERIES$2 = {
|
|
|
540
539
|
)
|
|
541
540
|
};
|
|
542
541
|
const toStrapiType$1 = (column) => {
|
|
543
|
-
|
|
544
|
-
const rootType = (_a = column.data_type.toLowerCase().match(/[^(), ]+/)) == null ? void 0 : _a[0];
|
|
542
|
+
const rootType = column.data_type.toLowerCase().match(/[^(), ]+/)?.[0];
|
|
545
543
|
switch (rootType) {
|
|
546
544
|
case "int": {
|
|
547
545
|
if (column.column_key === "PRI") {
|
|
@@ -776,9 +774,8 @@ class MysqlDialect extends Dialect {
|
|
|
776
774
|
return true;
|
|
777
775
|
}
|
|
778
776
|
supportsWindowFunctions() {
|
|
779
|
-
|
|
780
|
-
const
|
|
781
|
-
const isBeforeV8 = !semver__default.default.valid((_b = this.info) == null ? void 0 : _b.version) || semver__default.default.lt(((_c = this.info) == null ? void 0 : _c.version) ?? "", "8.0.0");
|
|
777
|
+
const isMysqlDB = !this.info?.database || this.info.database === MYSQL;
|
|
778
|
+
const isBeforeV8 = !semver__default.default.valid(this.info?.version) || semver__default.default.lt(this.info?.version ?? "", "8.0.0");
|
|
782
779
|
if (isMysqlDB && isBeforeV8) {
|
|
783
780
|
return false;
|
|
784
781
|
}
|
|
@@ -799,9 +796,8 @@ const SQL_QUERIES = {
|
|
|
799
796
|
FOREIGN_KEY_LIST: "pragma foreign_key_list(??)"
|
|
800
797
|
};
|
|
801
798
|
const toStrapiType = (column) => {
|
|
802
|
-
var _a;
|
|
803
799
|
const { type } = column;
|
|
804
|
-
const rootType =
|
|
800
|
+
const rootType = type.toLowerCase().match(/[^(), ]+/)?.[0];
|
|
805
801
|
switch (rootType) {
|
|
806
802
|
case "integer": {
|
|
807
803
|
if (column.pk) {
|
|
@@ -1077,8 +1073,7 @@ const createSchemaBuilder = (db) => {
|
|
|
1077
1073
|
*/
|
|
1078
1074
|
// TODO: implement force option to disable removal in DB
|
|
1079
1075
|
async updateSchema(schemaDiff) {
|
|
1080
|
-
|
|
1081
|
-
const forceMigration = (_a = db.config.settings) == null ? void 0 : _a.forceMigration;
|
|
1076
|
+
const forceMigration = db.config.settings?.forceMigration;
|
|
1082
1077
|
await db.dialect.startSchemaUpdate();
|
|
1083
1078
|
await db.connection.transaction(async (trx) => {
|
|
1084
1079
|
await this.createTables(schemaDiff.tables.added, trx);
|
|
@@ -1134,8 +1129,7 @@ const createHelpers = (db) => {
|
|
|
1134
1129
|
}
|
|
1135
1130
|
};
|
|
1136
1131
|
const dropIndex = (tableBuilder, index2) => {
|
|
1137
|
-
|
|
1138
|
-
if (!((_a = db.config.settings) == null ? void 0 : _a.forceMigration)) {
|
|
1132
|
+
if (!db.config.settings?.forceMigration) {
|
|
1139
1133
|
return;
|
|
1140
1134
|
}
|
|
1141
1135
|
const { type, columns, name } = index2;
|
|
@@ -1173,8 +1167,7 @@ const createHelpers = (db) => {
|
|
|
1173
1167
|
return col;
|
|
1174
1168
|
};
|
|
1175
1169
|
const dropColumn = (tableBuilder, column) => {
|
|
1176
|
-
|
|
1177
|
-
if (!((_a = db.config.settings) == null ? void 0 : _a.forceMigration)) {
|
|
1170
|
+
if (!db.config.settings?.forceMigration) {
|
|
1178
1171
|
return;
|
|
1179
1172
|
}
|
|
1180
1173
|
return tableBuilder.dropColumn(column.name);
|
|
@@ -1553,7 +1546,7 @@ const createSchemaDiff = (db) => {
|
|
|
1553
1546
|
for (const srcTable of srcSchema.tables) {
|
|
1554
1547
|
if (!helpers.hasTable(destSchema, srcTable.name) && !reservedTables.includes(srcTable.name)) {
|
|
1555
1548
|
const dependencies = persistedTables.filter((table) => {
|
|
1556
|
-
const dependsOn = table
|
|
1549
|
+
const dependsOn = table?.dependsOn;
|
|
1557
1550
|
if (!___default.default.isArray(dependsOn)) {
|
|
1558
1551
|
return;
|
|
1559
1552
|
}
|
|
@@ -3245,7 +3238,7 @@ const morphToMany = async (input, ctx) => {
|
|
|
3245
3238
|
continue;
|
|
3246
3239
|
}
|
|
3247
3240
|
const qb2 = db.entityManager.createQueryBuilder(type);
|
|
3248
|
-
const rows = await qb2.init(
|
|
3241
|
+
const rows = await qb2.init(on?.[type] ?? typePopulate).addSelect(`${qb2.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
|
|
3249
3242
|
map[type] = ___default.default.groupBy(idColumn.referencedColumn)(rows);
|
|
3250
3243
|
}
|
|
3251
3244
|
results.forEach((result) => {
|
|
@@ -3291,7 +3284,7 @@ const morphToOne = async (input, ctx) => {
|
|
|
3291
3284
|
return;
|
|
3292
3285
|
}
|
|
3293
3286
|
const qb = db.entityManager.createQueryBuilder(type);
|
|
3294
|
-
const rows = await qb.init(
|
|
3287
|
+
const rows = await qb.init(on?.[type] ?? typePopulate).addSelect(`${qb.alias}.${idColumn.referencedColumn}`).where({ [idColumn.referencedColumn]: ids }).execute({ mapResults: false });
|
|
3295
3288
|
map[type] = ___default.default.groupBy(idColumn.referencedColumn)(rows);
|
|
3296
3289
|
}
|
|
3297
3290
|
results.forEach((result) => {
|
|
@@ -3843,15 +3836,15 @@ const transactionCtx = {
|
|
|
3843
3836
|
},
|
|
3844
3837
|
get() {
|
|
3845
3838
|
const store = storage.getStore();
|
|
3846
|
-
return store
|
|
3839
|
+
return store?.trx;
|
|
3847
3840
|
},
|
|
3848
3841
|
async commit(trx) {
|
|
3849
3842
|
const store = storage.getStore();
|
|
3850
|
-
if (store
|
|
3843
|
+
if (store?.trx) {
|
|
3851
3844
|
store.trx = null;
|
|
3852
3845
|
}
|
|
3853
3846
|
await trx.commit();
|
|
3854
|
-
if (!
|
|
3847
|
+
if (!store?.commitCallbacks.length) {
|
|
3855
3848
|
return;
|
|
3856
3849
|
}
|
|
3857
3850
|
store.commitCallbacks.forEach((cb) => cb());
|
|
@@ -3859,11 +3852,11 @@ const transactionCtx = {
|
|
|
3859
3852
|
},
|
|
3860
3853
|
async rollback(trx) {
|
|
3861
3854
|
const store = storage.getStore();
|
|
3862
|
-
if (store
|
|
3855
|
+
if (store?.trx) {
|
|
3863
3856
|
store.trx = null;
|
|
3864
3857
|
}
|
|
3865
3858
|
await trx.rollback();
|
|
3866
|
-
if (!
|
|
3859
|
+
if (!store?.rollbackCallbacks.length) {
|
|
3867
3860
|
return;
|
|
3868
3861
|
}
|
|
3869
3862
|
store.rollbackCallbacks.forEach((cb) => cb());
|
|
@@ -3871,13 +3864,13 @@ const transactionCtx = {
|
|
|
3871
3864
|
},
|
|
3872
3865
|
onCommit(cb) {
|
|
3873
3866
|
const store = storage.getStore();
|
|
3874
|
-
if (store
|
|
3867
|
+
if (store?.commitCallbacks) {
|
|
3875
3868
|
store.commitCallbacks.push(cb);
|
|
3876
3869
|
}
|
|
3877
3870
|
},
|
|
3878
3871
|
onRollback(cb) {
|
|
3879
3872
|
const store = storage.getStore();
|
|
3880
|
-
if (store
|
|
3873
|
+
if (store?.rollbackCallbacks) {
|
|
3881
3874
|
store.rollbackCallbacks.push(cb);
|
|
3882
3875
|
}
|
|
3883
3876
|
}
|
|
@@ -4416,7 +4409,7 @@ const getMorphToManyRowsLinkedToMorphOne = (rows, {
|
|
|
4416
4409
|
const relatedType = row[typeColumn.name];
|
|
4417
4410
|
const field = row.field;
|
|
4418
4411
|
const targetAttribute = db.metadata.get(relatedType).attributes[field];
|
|
4419
|
-
return
|
|
4412
|
+
return targetAttribute?.target === uid && targetAttribute?.morphBy === attributeName && targetAttribute?.relation === "morphOne";
|
|
4420
4413
|
});
|
|
4421
4414
|
const deleteRelatedMorphOneRelationsAfterMorphToManyUpdate = async (rows, {
|
|
4422
4415
|
uid,
|
|
@@ -4508,7 +4501,6 @@ const deleteRelations = async ({
|
|
|
4508
4501
|
relIdsToDelete = [],
|
|
4509
4502
|
transaction: trx
|
|
4510
4503
|
}) => {
|
|
4511
|
-
var _a;
|
|
4512
4504
|
const { joinTable } = attribute;
|
|
4513
4505
|
const { joinColumn, inverseJoinColumn } = joinTable;
|
|
4514
4506
|
const all = relIdsToDelete === "all";
|
|
@@ -4524,7 +4516,7 @@ const deleteRelations = async ({
|
|
|
4524
4516
|
...all ? {} : { [inverseJoinColumn.name]: { $in: relIdsToDelete } }
|
|
4525
4517
|
}).where(joinTable.on || {}).orderBy("id").limit(batchSize).transacting(trx).execute();
|
|
4526
4518
|
done = batchToDelete.length < batchSize;
|
|
4527
|
-
lastId =
|
|
4519
|
+
lastId = batchToDelete[batchToDelete.length - 1]?.id || 0;
|
|
4528
4520
|
const batchIds = _.map(inverseJoinColumn.name, batchToDelete);
|
|
4529
4521
|
await createQueryBuilder(joinTable.name, db).delete().where({
|
|
4530
4522
|
[joinColumn.name]: id,
|
|
@@ -4711,8 +4703,7 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
|
|
|
4711
4703
|
{}
|
|
4712
4704
|
);
|
|
4713
4705
|
const mappedRelations = connectArr.reduce((mapper, relation) => {
|
|
4714
|
-
|
|
4715
|
-
const adjacentRelId = ((_a = relation.position) == null ? void 0 : _a.before) || ((_b = relation.position) == null ? void 0 : _b.after);
|
|
4706
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
4716
4707
|
if (!adjacentRelId || !relationInInitialArray[adjacentRelId] && !mapper[adjacentRelId]) {
|
|
4717
4708
|
needsSorting = true;
|
|
4718
4709
|
}
|
|
@@ -4729,15 +4720,14 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
|
|
|
4729
4720
|
if (!needsSorting)
|
|
4730
4721
|
return connectArr;
|
|
4731
4722
|
const computeRelation = (relation, relationsSeenInBranch) => {
|
|
4732
|
-
|
|
4733
|
-
const adjacentRelId = ((_a = relation.position) == null ? void 0 : _a.before) || ((_b = relation.position) == null ? void 0 : _b.after);
|
|
4723
|
+
const adjacentRelId = relation.position?.before || relation.position?.after;
|
|
4734
4724
|
const adjacentRelation = mappedRelations[adjacentRelId];
|
|
4735
4725
|
if (adjacentRelId && relationsSeenInBranch[adjacentRelId]) {
|
|
4736
4726
|
throw new InvalidRelationError(
|
|
4737
4727
|
"A circular reference was found in the connect array. One relation is trying to connect before/after another one that is trying to connect before/after it"
|
|
4738
4728
|
);
|
|
4739
4729
|
}
|
|
4740
|
-
if (
|
|
4730
|
+
if (mappedRelations[relation.id]?.computed) {
|
|
4741
4731
|
return;
|
|
4742
4732
|
}
|
|
4743
4733
|
mappedRelations[relation.id].computed = true;
|
|
@@ -4762,13 +4752,12 @@ const sortConnectArray = (connectArr, initialArr = [], strictSort = true) => {
|
|
|
4762
4752
|
return sortedConnect;
|
|
4763
4753
|
};
|
|
4764
4754
|
const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
4765
|
-
var _a;
|
|
4766
4755
|
const computedRelations = _.castArray(initArr ?? []).map((r) => ({
|
|
4767
4756
|
init: true,
|
|
4768
4757
|
id: r[idColumn],
|
|
4769
4758
|
order: Number(r[orderColumn]) || 1
|
|
4770
4759
|
}));
|
|
4771
|
-
const maxOrder =
|
|
4760
|
+
const maxOrder = _.maxBy("order", computedRelations)?.order || 0;
|
|
4772
4761
|
const findRelation = (id) => {
|
|
4773
4762
|
const idx = computedRelations.findIndex((r) => r.id === id);
|
|
4774
4763
|
return { idx, relation: computedRelations[idx] };
|
|
@@ -4780,9 +4769,8 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
|
4780
4769
|
}
|
|
4781
4770
|
};
|
|
4782
4771
|
const insertRelation = (r) => {
|
|
4783
|
-
var _a2, _b, _c;
|
|
4784
4772
|
let idx;
|
|
4785
|
-
if (
|
|
4773
|
+
if (r.position?.before) {
|
|
4786
4774
|
const { idx: _idx, relation } = findRelation(r.position.before);
|
|
4787
4775
|
if (relation.init) {
|
|
4788
4776
|
r.order = relation.order - 0.5;
|
|
@@ -4790,7 +4778,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
|
4790
4778
|
r.order = relation.order;
|
|
4791
4779
|
}
|
|
4792
4780
|
idx = _idx;
|
|
4793
|
-
} else if (
|
|
4781
|
+
} else if (r.position?.after) {
|
|
4794
4782
|
const { idx: _idx, relation } = findRelation(r.position.after);
|
|
4795
4783
|
if (relation.init) {
|
|
4796
4784
|
r.order = relation.order + 0.5;
|
|
@@ -4798,7 +4786,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
|
4798
4786
|
r.order = relation.order;
|
|
4799
4787
|
}
|
|
4800
4788
|
idx = _idx + 1;
|
|
4801
|
-
} else if (
|
|
4789
|
+
} else if (r.position?.start) {
|
|
4802
4790
|
r.order = 0.5;
|
|
4803
4791
|
idx = 0;
|
|
4804
4792
|
} else {
|
|
@@ -4837,8 +4825,7 @@ const relationsOrderer = (initArr, idColumn, orderColumn, strict) => {
|
|
|
4837
4825
|
*/
|
|
4838
4826
|
getOrderMap() {
|
|
4839
4827
|
return ___default$1.default(computedRelations).groupBy("order").reduce((acc, relations) => {
|
|
4840
|
-
|
|
4841
|
-
if ((_a2 = relations[0]) == null ? void 0 : _a2.init)
|
|
4828
|
+
if (relations[0]?.init)
|
|
4842
4829
|
return acc;
|
|
4843
4830
|
relations.forEach((relation, idx) => {
|
|
4844
4831
|
acc[relation.id] = Math.floor(relation.order) + (idx + 1) / (relations.length + 1);
|
|
@@ -4923,27 +4910,26 @@ const toIdArray = (data) => {
|
|
|
4923
4910
|
return _.uniqWith(_.isEqual, array);
|
|
4924
4911
|
};
|
|
4925
4912
|
const toAssocs = (data) => {
|
|
4926
|
-
var _a;
|
|
4927
4913
|
if (_.isArray(data) || _.isString(data) || _.isNumber(data) || _.isNull(data) || isRecord(data) && "id" in data) {
|
|
4928
4914
|
return {
|
|
4929
4915
|
set: _.isNull(data) ? data : toIdArray(data)
|
|
4930
4916
|
};
|
|
4931
4917
|
}
|
|
4932
|
-
if (data
|
|
4918
|
+
if (data?.set) {
|
|
4933
4919
|
return {
|
|
4934
4920
|
set: _.isNull(data.set) ? data.set : toIdArray(data.set)
|
|
4935
4921
|
};
|
|
4936
4922
|
}
|
|
4937
4923
|
return {
|
|
4938
4924
|
options: {
|
|
4939
|
-
strict:
|
|
4925
|
+
strict: data?.options?.strict
|
|
4940
4926
|
},
|
|
4941
|
-
connect: toIdArray(data
|
|
4927
|
+
connect: toIdArray(data?.connect).map((elm) => ({
|
|
4942
4928
|
id: elm.id,
|
|
4943
4929
|
position: elm.position ? elm.position : { end: true },
|
|
4944
4930
|
__pivot: elm.__pivot ?? {}
|
|
4945
4931
|
})),
|
|
4946
|
-
disconnect: toIdArray(data
|
|
4932
|
+
disconnect: toIdArray(data?.disconnect)
|
|
4947
4933
|
};
|
|
4948
4934
|
};
|
|
4949
4935
|
const processData = (metadata, data = {}, { withDefaults = false } = {}) => {
|
|
@@ -5069,7 +5055,7 @@ const createEntityManager = (db) => {
|
|
|
5069
5055
|
const createdEntries = await this.createQueryBuilder(uid).insert(dataToInsert).execute();
|
|
5070
5056
|
const result = {
|
|
5071
5057
|
count: data.length,
|
|
5072
|
-
ids: createdEntries.map((entry) => typeof entry === "object" ? entry
|
|
5058
|
+
ids: createdEntries.map((entry) => typeof entry === "object" ? entry?.id : entry)
|
|
5073
5059
|
};
|
|
5074
5060
|
await db.lifecycles.run("afterCreateMany", uid, { params, result }, states);
|
|
5075
5061
|
return result;
|
|
@@ -5208,7 +5194,6 @@ const createEntityManager = (db) => {
|
|
|
5208
5194
|
* Attach relations to a new entity
|
|
5209
5195
|
*/
|
|
5210
5196
|
async attachRelations(uid, id, data, options) {
|
|
5211
|
-
var _a, _b, _c;
|
|
5212
5197
|
const { attributes } = db.metadata.get(uid);
|
|
5213
5198
|
const { transaction: trx } = options ?? {};
|
|
5214
5199
|
for (const attributeName of Object.keys(attributes)) {
|
|
@@ -5228,7 +5213,7 @@ const createEntityManager = (db) => {
|
|
|
5228
5213
|
}
|
|
5229
5214
|
if (targetAttribute.relation === "morphToOne") {
|
|
5230
5215
|
const { idColumn, typeColumn } = targetAttribute.morphColumn;
|
|
5231
|
-
const relId = toId(
|
|
5216
|
+
const relId = toId(cleanRelationData.set?.[0]);
|
|
5232
5217
|
await this.createQueryBuilder(target).update({ [idColumn.name]: id, [typeColumn.name]: uid }).where({ id: relId }).transacting(trx).execute();
|
|
5233
5218
|
} else if (targetAttribute.relation === "morphToMany") {
|
|
5234
5219
|
const { joinTable } = targetAttribute;
|
|
@@ -5237,7 +5222,7 @@ const createEntityManager = (db) => {
|
|
|
5237
5222
|
if (_.isEmpty(cleanRelationData.set)) {
|
|
5238
5223
|
continue;
|
|
5239
5224
|
}
|
|
5240
|
-
const rows =
|
|
5225
|
+
const rows = cleanRelationData.set?.map((data2, idx) => {
|
|
5241
5226
|
return {
|
|
5242
5227
|
[joinColumn.name]: data2.id,
|
|
5243
5228
|
[idColumn.name]: id,
|
|
@@ -5247,7 +5232,7 @@ const createEntityManager = (db) => {
|
|
|
5247
5232
|
order: idx + 1,
|
|
5248
5233
|
field: attributeName
|
|
5249
5234
|
};
|
|
5250
|
-
})
|
|
5235
|
+
}) ?? [];
|
|
5251
5236
|
await this.createQueryBuilder(joinTable.name).insert(rows).transacting(trx).execute();
|
|
5252
5237
|
}
|
|
5253
5238
|
continue;
|
|
@@ -5260,14 +5245,14 @@ const createEntityManager = (db) => {
|
|
|
5260
5245
|
if (_.isEmpty(cleanRelationData.set)) {
|
|
5261
5246
|
continue;
|
|
5262
5247
|
}
|
|
5263
|
-
const rows =
|
|
5248
|
+
const rows = cleanRelationData.set?.map((data2, idx) => ({
|
|
5264
5249
|
[joinColumn.name]: id,
|
|
5265
5250
|
[idColumn.name]: data2.id,
|
|
5266
5251
|
[typeColumn.name]: data2[typeField],
|
|
5267
5252
|
..."on" in joinTable && joinTable.on || {},
|
|
5268
5253
|
...data2.__pivot || {},
|
|
5269
5254
|
order: idx + 1
|
|
5270
|
-
}))
|
|
5255
|
+
})) ?? [];
|
|
5271
5256
|
await deleteRelatedMorphOneRelationsAfterMorphToManyUpdate(rows, {
|
|
5272
5257
|
uid,
|
|
5273
5258
|
attributeName,
|
|
@@ -5351,7 +5336,6 @@ const createEntityManager = (db) => {
|
|
|
5351
5336
|
*/
|
|
5352
5337
|
// TODO: check relation exists (handled by FKs except for polymorphics)
|
|
5353
5338
|
async updateRelations(uid, id, data, options) {
|
|
5354
|
-
var _a, _b, _c, _d, _e, _f;
|
|
5355
5339
|
const { attributes } = db.metadata.get(uid);
|
|
5356
5340
|
const { transaction: trx } = options ?? {};
|
|
5357
5341
|
for (const attributeName of Object.keys(attributes)) {
|
|
@@ -5367,7 +5351,7 @@ const createEntityManager = (db) => {
|
|
|
5367
5351
|
const { idColumn, typeColumn } = targetAttribute.morphColumn;
|
|
5368
5352
|
await this.createQueryBuilder(target).update({ [idColumn.name]: null, [typeColumn.name]: null }).where({ [idColumn.name]: id, [typeColumn.name]: uid }).transacting(trx).execute();
|
|
5369
5353
|
if (!_.isNull(cleanRelationData.set)) {
|
|
5370
|
-
const relId = toIds(
|
|
5354
|
+
const relId = toIds(cleanRelationData.set?.[0]);
|
|
5371
5355
|
await this.createQueryBuilder(target).update({ [idColumn.name]: id, [typeColumn.name]: uid }).where({ id: relId }).transacting(trx).execute();
|
|
5372
5356
|
}
|
|
5373
5357
|
} else if (targetAttribute.type === "relation" && targetAttribute.relation === "morphToMany") {
|
|
@@ -5383,7 +5367,7 @@ const createEntityManager = (db) => {
|
|
|
5383
5367
|
if (_.isEmpty(cleanRelationData.set)) {
|
|
5384
5368
|
continue;
|
|
5385
5369
|
}
|
|
5386
|
-
const rows =
|
|
5370
|
+
const rows = cleanRelationData.set?.map((data2, idx) => ({
|
|
5387
5371
|
[joinColumn.name]: data2.id,
|
|
5388
5372
|
[idColumn.name]: id,
|
|
5389
5373
|
[typeColumn.name]: uid,
|
|
@@ -5456,7 +5440,7 @@ const createEntityManager = (db) => {
|
|
|
5456
5440
|
let relIdsToaddOrMove;
|
|
5457
5441
|
if (isPartialUpdate) {
|
|
5458
5442
|
if (isAnyToOne(attribute)) {
|
|
5459
|
-
cleanRelationData.connect =
|
|
5443
|
+
cleanRelationData.connect = cleanRelationData.connect?.slice(-1);
|
|
5460
5444
|
}
|
|
5461
5445
|
relIdsToaddOrMove = toIds(cleanRelationData.connect);
|
|
5462
5446
|
const relIdsToDelete = toIds(
|
|
@@ -5492,11 +5476,8 @@ const createEntityManager = (db) => {
|
|
|
5492
5476
|
[joinColumn.name]: id,
|
|
5493
5477
|
[inverseJoinColumn.name]: {
|
|
5494
5478
|
$in: _.compact(
|
|
5495
|
-
|
|
5496
|
-
(r) =>
|
|
5497
|
-
var _a2, _b2;
|
|
5498
|
-
return ((_a2 = r.position) == null ? void 0 : _a2.after) || ((_b2 = r.position) == null ? void 0 : _b2.before);
|
|
5499
|
-
}
|
|
5479
|
+
cleanRelationData.connect?.map(
|
|
5480
|
+
(r) => r.position?.after || r.position?.before
|
|
5500
5481
|
)
|
|
5501
5482
|
)
|
|
5502
5483
|
}
|
|
@@ -5511,7 +5492,7 @@ const createEntityManager = (db) => {
|
|
|
5511
5492
|
adjacentRelations,
|
|
5512
5493
|
inverseJoinColumn.name,
|
|
5513
5494
|
joinTable.orderColumnName,
|
|
5514
|
-
|
|
5495
|
+
cleanRelationData.options?.strict
|
|
5515
5496
|
).connect(cleanRelationData.connect ?? []).getOrderMap();
|
|
5516
5497
|
insert.forEach((row) => {
|
|
5517
5498
|
row[orderColumnName] = orderMap[row[inverseJoinColumn.name]];
|
|
@@ -5541,7 +5522,7 @@ const createEntityManager = (db) => {
|
|
|
5541
5522
|
await cleanOrderColumns({ attribute, db, id, transaction: trx });
|
|
5542
5523
|
} else {
|
|
5543
5524
|
if (isAnyToOne(attribute)) {
|
|
5544
|
-
cleanRelationData.set =
|
|
5525
|
+
cleanRelationData.set = cleanRelationData.set?.slice(-1);
|
|
5545
5526
|
}
|
|
5546
5527
|
relIdsToaddOrMove = toIds(cleanRelationData.set);
|
|
5547
5528
|
await deleteRelations({
|
|
@@ -5858,9 +5839,8 @@ const createMigrationsProvider = (db) => {
|
|
|
5858
5839
|
const migrations = createUmzugProvider(db);
|
|
5859
5840
|
return {
|
|
5860
5841
|
async shouldRun() {
|
|
5861
|
-
var _a, _b;
|
|
5862
5842
|
const pending = await migrations.pending();
|
|
5863
|
-
return pending.length > 0 &&
|
|
5843
|
+
return pending.length > 0 && db.config?.settings?.runMigrations === true;
|
|
5864
5844
|
},
|
|
5865
5845
|
async up() {
|
|
5866
5846
|
await migrations.up();
|
|
@@ -5871,10 +5851,9 @@ const createMigrationsProvider = (db) => {
|
|
|
5871
5851
|
};
|
|
5872
5852
|
};
|
|
5873
5853
|
const modelsLifecyclesSubscriber = async (event) => {
|
|
5874
|
-
var _a, _b;
|
|
5875
5854
|
const { model } = event;
|
|
5876
5855
|
if (model.lifecycles && event.action in model.lifecycles) {
|
|
5877
|
-
await
|
|
5856
|
+
await model.lifecycles[event.action]?.(event);
|
|
5878
5857
|
}
|
|
5879
5858
|
};
|
|
5880
5859
|
const timestampsLifecyclesSubscriber = {
|
|
@@ -5954,7 +5933,6 @@ const createLifecyclesProvider = (db) => {
|
|
|
5954
5933
|
* @param {Map<any, any>} states
|
|
5955
5934
|
*/
|
|
5956
5935
|
async run(action, uid, properties, states = /* @__PURE__ */ new Map()) {
|
|
5957
|
-
var _a;
|
|
5958
5936
|
for (let i = 0; i < subscribers.length; i += 1) {
|
|
5959
5937
|
const subscriber = subscribers[i];
|
|
5960
5938
|
if (typeof subscriber === "function") {
|
|
@@ -5971,7 +5949,7 @@ const createLifecyclesProvider = (db) => {
|
|
|
5971
5949
|
if (hasAction && hasModel) {
|
|
5972
5950
|
const state = states.get(subscriber) || {};
|
|
5973
5951
|
const event = this.createEvent(action, uid, properties, state);
|
|
5974
|
-
await
|
|
5952
|
+
await subscriber[action]?.(event);
|
|
5975
5953
|
if (event.state) {
|
|
5976
5954
|
states.set(subscriber, event.state);
|
|
5977
5955
|
}
|