@strapi/database 4.5.0-beta.0 → 4.5.1
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/lib/entity-manager/index.js +1 -1
- package/lib/entity-manager/regular-relations.js +11 -15
- package/lib/index.d.ts +2 -2
- package/lib/metadata/index.js +16 -0
- package/lib/query/helpers/populate/process.js +7 -1
- package/lib/schema/index.d.ts +2 -2
- package/lib/tests/{knex-utils.test.e2e.js → knex-utils.test.api.js} +0 -0
- package/package.json +2 -2
|
@@ -982,7 +982,7 @@ const createEntityManager = (db) => {
|
|
|
982
982
|
}
|
|
983
983
|
|
|
984
984
|
// Delete the previous relations for anyToOne relations
|
|
985
|
-
if (
|
|
985
|
+
if (isAnyToOne(attribute)) {
|
|
986
986
|
await deletePreviousAnyToOneRelations({
|
|
987
987
|
id,
|
|
988
988
|
attribute,
|
|
@@ -65,10 +65,8 @@ const deletePreviousAnyToOneRelations = async ({
|
|
|
65
65
|
const { joinTable } = attribute;
|
|
66
66
|
const { joinColumn, inverseJoinColumn } = joinTable;
|
|
67
67
|
|
|
68
|
-
if (!
|
|
69
|
-
throw new Error(
|
|
70
|
-
'deletePreviousAnyToOneRelations can only be called for bidirectional anyToOne relations'
|
|
71
|
-
);
|
|
68
|
+
if (!isAnyToOne(attribute)) {
|
|
69
|
+
throw new Error('deletePreviousAnyToOneRelations can only be called for anyToOne relations');
|
|
72
70
|
}
|
|
73
71
|
// handling manyToOne
|
|
74
72
|
if (isManyToAny(attribute)) {
|
|
@@ -228,8 +226,7 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|
|
228
226
|
// https://github.com/knex/knex/issues/2504
|
|
229
227
|
switch (strapi.db.dialect.client) {
|
|
230
228
|
case 'mysql':
|
|
231
|
-
await db
|
|
232
|
-
.getConnection()
|
|
229
|
+
await db.connection
|
|
233
230
|
.raw(
|
|
234
231
|
`UPDATE
|
|
235
232
|
?? as a,
|
|
@@ -245,17 +242,16 @@ const cleanOrderColumns = async ({ id, attribute, db, inverseRelIds, transaction
|
|
|
245
242
|
.transacting(trx);
|
|
246
243
|
break;
|
|
247
244
|
default:
|
|
248
|
-
await db
|
|
249
|
-
.getConnection()
|
|
245
|
+
await db.connection
|
|
250
246
|
.raw(
|
|
251
247
|
`UPDATE ?? as a
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
248
|
+
SET ${update.join(', ')}
|
|
249
|
+
FROM (
|
|
250
|
+
SELECT ${select.join(', ')}
|
|
251
|
+
FROM ??
|
|
252
|
+
WHERE ${where.join(' OR ')}
|
|
253
|
+
) AS b
|
|
254
|
+
WHERE b.id = a.id`,
|
|
259
255
|
[joinTable.name, ...updateBinding, ...selectBinding, joinTable.name, ...whereBinding]
|
|
260
256
|
)
|
|
261
257
|
.transacting(trx);
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LifecycleProvider } from './lifecycles';
|
|
2
2
|
import { MigrationProvider } from './migrations';
|
|
3
|
-
import {
|
|
3
|
+
import { SchemaProvider } from './schema';
|
|
4
4
|
|
|
5
5
|
type LogicalOperators<T> = {
|
|
6
6
|
$and?: WhereParams<T>[];
|
|
@@ -154,7 +154,7 @@ interface DatabaseConfig {
|
|
|
154
154
|
models: ModelConfig[];
|
|
155
155
|
}
|
|
156
156
|
export interface Database {
|
|
157
|
-
schema:
|
|
157
|
+
schema: SchemaProvider;
|
|
158
158
|
lifecycles: LifecycleProvider;
|
|
159
159
|
migrations: MigrationProvider;
|
|
160
160
|
entityManager: EntityManager;
|
package/lib/metadata/index.js
CHANGED
|
@@ -9,6 +9,21 @@ class Metadata extends Map {
|
|
|
9
9
|
add(meta) {
|
|
10
10
|
return this.set(meta.uid, meta);
|
|
11
11
|
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Validate the DB metadata, throwing an error if a duplicate DB table name is detected
|
|
15
|
+
*/
|
|
16
|
+
validate() {
|
|
17
|
+
const seenTables = new Map();
|
|
18
|
+
for (const meta of this.values()) {
|
|
19
|
+
if (seenTables.get(meta.tableName)) {
|
|
20
|
+
throw new Error(
|
|
21
|
+
`DB table "${meta.tableName}" already exists. Change the collectionName of the related content type.`
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
seenTables.set(meta.tableName, true);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
12
27
|
}
|
|
13
28
|
|
|
14
29
|
// TODO: check if there isn't an attribute with an id already
|
|
@@ -81,6 +96,7 @@ const createMetadata = (models = []) => {
|
|
|
81
96
|
meta.columnToAttribute = columnToAttribute;
|
|
82
97
|
}
|
|
83
98
|
|
|
99
|
+
metadata.validate();
|
|
84
100
|
return metadata;
|
|
85
101
|
};
|
|
86
102
|
|
|
@@ -82,7 +82,13 @@ const processPopulate = (populate, ctx) => {
|
|
|
82
82
|
continue;
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
//
|
|
85
|
+
// Make sure to query the join column value if needed,
|
|
86
|
+
// so that we can apply the populate later on
|
|
87
|
+
if (attribute.joinColumn) {
|
|
88
|
+
qb.addSelect(attribute.joinColumn.name);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Make sure id is present for future populate queries
|
|
86
92
|
if (_.has('id', meta.attributes)) {
|
|
87
93
|
qb.addSelect('id');
|
|
88
94
|
}
|
package/lib/schema/index.d.ts
CHANGED
|
@@ -38,7 +38,7 @@ export interface Model {
|
|
|
38
38
|
};
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
export interface
|
|
41
|
+
export interface SchemaProvider {
|
|
42
42
|
sync(): Promise<void>;
|
|
43
43
|
syncSchema(): Promise<void>;
|
|
44
44
|
reset(): Promise<void>;
|
|
@@ -46,4 +46,4 @@ export interface SchemaProvideer {
|
|
|
46
46
|
drop(): Promise<void>;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export default function(db: Database):
|
|
49
|
+
export default function(db: Database): SchemaProvider;
|
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.1",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"node": ">=14.19.1 <=18.x.x",
|
|
43
43
|
"npm": ">=6.0.0"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "8c20ea2b5c5a115b78454086ea270dcd59b06004"
|
|
46
46
|
}
|