@strapi/database 5.0.0-beta.8 → 5.0.0-beta.9
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 +47 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -9
- package/dist/index.mjs.map +1 -1
- package/dist/migrations/internal-migrations/5.0.0-03-locale.d.ts +3 -0
- package/dist/migrations/internal-migrations/5.0.0-03-locale.d.ts.map +1 -0
- package/dist/migrations/internal-migrations/index.d.ts.map +1 -1
- package/dist/query/helpers/populate/apply.d.ts.map +1 -1
- package/dist/query/helpers/where.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -3180,6 +3180,7 @@ const processOrderBy = (orderBy, ctx) => {
|
|
|
3180
3180
|
}
|
|
3181
3181
|
throw new Error("Invalid orderBy syntax");
|
|
3182
3182
|
};
|
|
3183
|
+
const joinColPrefix = "__strapi";
|
|
3183
3184
|
const XtoOne = async (input, ctx) => {
|
|
3184
3185
|
const { attribute, attributeName, results, populateValue, targetMeta, isCount } = input;
|
|
3185
3186
|
const { db, qb } = ctx;
|
|
@@ -3208,6 +3209,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3208
3209
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3209
3210
|
const alias = qb2.getAlias();
|
|
3210
3211
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3212
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3213
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3211
3214
|
const referencedValues = _.uniq(
|
|
3212
3215
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
3213
3216
|
);
|
|
@@ -3252,8 +3255,8 @@ const XtoOne = async (input, ctx) => {
|
|
|
3252
3255
|
rootTable: qb2.alias,
|
|
3253
3256
|
on: joinTable.on,
|
|
3254
3257
|
orderBy: joinTable.orderBy
|
|
3255
|
-
}).addSelect(
|
|
3256
|
-
const map2 = _.groupBy(
|
|
3258
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3259
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3257
3260
|
results.forEach((result) => {
|
|
3258
3261
|
result[attributeName] = fromTargetRow(_.first(map2[result[referencedColumnName]]));
|
|
3259
3262
|
});
|
|
@@ -3287,6 +3290,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3287
3290
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3288
3291
|
const alias = qb2.getAlias();
|
|
3289
3292
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3293
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3294
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3290
3295
|
const referencedValues = _.uniq(
|
|
3291
3296
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
3292
3297
|
);
|
|
@@ -3304,10 +3309,10 @@ const oneToMany = async (input, ctx) => {
|
|
|
3304
3309
|
rootColumn: joinTable.inverseJoinColumn.referencedColumn,
|
|
3305
3310
|
rootTable: qb2.alias,
|
|
3306
3311
|
on: joinTable.on
|
|
3307
|
-
}).select([
|
|
3312
|
+
}).select([joinColSelect, qb2.raw("count(*) AS count")]).where({ [joinColAlias]: referencedValues }).groupBy(joinColAlias).execute({ mapResults: false });
|
|
3308
3313
|
const map22 = rows2.reduce(
|
|
3309
3314
|
(map3, row) => {
|
|
3310
|
-
map3[row[
|
|
3315
|
+
map3[row[joinColRenameAs]] = { count: Number(row.count) };
|
|
3311
3316
|
return map3;
|
|
3312
3317
|
},
|
|
3313
3318
|
{}
|
|
@@ -3331,8 +3336,8 @@ const oneToMany = async (input, ctx) => {
|
|
|
3331
3336
|
rootTable: qb2.alias,
|
|
3332
3337
|
on: joinTable.on,
|
|
3333
3338
|
orderBy: _.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3334
|
-
}).addSelect(
|
|
3335
|
-
const map2 = _.groupBy(
|
|
3339
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3340
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3336
3341
|
results.forEach((r) => {
|
|
3337
3342
|
r[attributeName] = fromTargetRow(map2[r[referencedColumnName]] || []);
|
|
3338
3343
|
});
|
|
@@ -3347,6 +3352,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3347
3352
|
const { name: joinColumnName, referencedColumn: referencedColumnName } = joinTable.joinColumn;
|
|
3348
3353
|
const alias = populateQb.getAlias();
|
|
3349
3354
|
const joinColAlias = `${alias}.${joinColumnName}`;
|
|
3355
|
+
const joinColRenameAs = `${joinColPrefix}${joinColumnName}`;
|
|
3356
|
+
const joinColSelect = `${joinColAlias} as ${joinColRenameAs}`;
|
|
3350
3357
|
const referencedValues = _.uniq(
|
|
3351
3358
|
results.map((r) => r[referencedColumnName]).filter((value) => !_.isNil(value))
|
|
3352
3359
|
);
|
|
@@ -3391,8 +3398,8 @@ const manyToMany = async (input, ctx) => {
|
|
|
3391
3398
|
rootTable: populateQb.alias,
|
|
3392
3399
|
on: joinTable.on,
|
|
3393
3400
|
orderBy: _.mapValues((v) => populateValue.ordering || v, joinTable.orderBy)
|
|
3394
|
-
}).addSelect(
|
|
3395
|
-
const map2 = _.groupBy(
|
|
3401
|
+
}).addSelect(joinColSelect).where({ [joinColAlias]: referencedValues }).execute({ mapResults: false });
|
|
3402
|
+
const map2 = _.groupBy(joinColRenameAs)(rows);
|
|
3396
3403
|
results.forEach((result) => {
|
|
3397
3404
|
result[attributeName] = fromTargetRow(map2[result[referencedColumnName]] || []);
|
|
3398
3405
|
});
|
|
@@ -3763,6 +3770,9 @@ const processRelationWhere = (where, ctx) => {
|
|
|
3763
3770
|
}
|
|
3764
3771
|
if (operatorKeys.length === 1) {
|
|
3765
3772
|
const operator = operatorKeys[0];
|
|
3773
|
+
if (isOperatorOfType("group", operator)) {
|
|
3774
|
+
return processWhere(where, ctx);
|
|
3775
|
+
}
|
|
3766
3776
|
return { [idAlias]: { [operator]: processNested(where[operator], ctx) } };
|
|
3767
3777
|
}
|
|
3768
3778
|
return processWhere(where, ctx);
|
|
@@ -6183,9 +6193,37 @@ const findDiffs = (shortMap) => {
|
|
|
6183
6193
|
});
|
|
6184
6194
|
return diffs;
|
|
6185
6195
|
};
|
|
6196
|
+
const createLocaleColumn = async (db, tableName) => {
|
|
6197
|
+
await db.schema.alterTable(tableName, (table) => {
|
|
6198
|
+
table.string("locale");
|
|
6199
|
+
});
|
|
6200
|
+
};
|
|
6201
|
+
const createdLocale = {
|
|
6202
|
+
name: "5.0.0-03-created-locale",
|
|
6203
|
+
async up(knex2, db) {
|
|
6204
|
+
for (const meta of db.metadata.values()) {
|
|
6205
|
+
const hasTable = await knex2.schema.hasTable(meta.tableName);
|
|
6206
|
+
if (!hasTable) {
|
|
6207
|
+
continue;
|
|
6208
|
+
}
|
|
6209
|
+
const uid = meta.uid;
|
|
6210
|
+
const model = strapi.getModel(uid);
|
|
6211
|
+
if (!model) {
|
|
6212
|
+
continue;
|
|
6213
|
+
}
|
|
6214
|
+
if (isNil(meta.attributes.locale)) {
|
|
6215
|
+
await createLocaleColumn(knex2, meta.tableName);
|
|
6216
|
+
}
|
|
6217
|
+
}
|
|
6218
|
+
},
|
|
6219
|
+
async down() {
|
|
6220
|
+
throw new Error("not implemented");
|
|
6221
|
+
}
|
|
6222
|
+
};
|
|
6186
6223
|
const internalMigrations = [
|
|
6187
6224
|
renameIdentifiersLongerThanMaxLength,
|
|
6188
|
-
createdDocumentId
|
|
6225
|
+
createdDocumentId,
|
|
6226
|
+
createdLocale
|
|
6189
6227
|
];
|
|
6190
6228
|
const createInternalMigrationProvider = (db) => {
|
|
6191
6229
|
const context = { db };
|