@strapi/database 4.9.2 → 4.10.0-beta.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.
|
@@ -22,12 +22,6 @@ class PostgresDialect extends Dialect {
|
|
|
22
22
|
'text',
|
|
23
23
|
(v) => v
|
|
24
24
|
);
|
|
25
|
-
// Don't parse JSONB automatically
|
|
26
|
-
this.db.connection.client.driver.types.setTypeParser(
|
|
27
|
-
this.db.connection.client.driver.types.builtins.JSONB,
|
|
28
|
-
'text',
|
|
29
|
-
(v) => v
|
|
30
|
-
);
|
|
31
25
|
this.db.connection.client.driver.types.setTypeParser(
|
|
32
26
|
this.db.connection.client.driver.types.builtins.NUMERIC,
|
|
33
27
|
'text',
|
|
@@ -96,8 +96,15 @@ const createRepository = (uid, db) => {
|
|
|
96
96
|
return db.entityManager.attachRelations(uid, id, data);
|
|
97
97
|
},
|
|
98
98
|
|
|
99
|
-
updateRelations(id, data) {
|
|
100
|
-
|
|
99
|
+
async updateRelations(id, data) {
|
|
100
|
+
const trx = await db.transaction();
|
|
101
|
+
try {
|
|
102
|
+
await db.entityManager.updateRelations(uid, id, data, { transaction: trx.get() });
|
|
103
|
+
return trx.commit();
|
|
104
|
+
} catch (e) {
|
|
105
|
+
await trx.rollback();
|
|
106
|
+
throw e;
|
|
107
|
+
}
|
|
101
108
|
},
|
|
102
109
|
|
|
103
110
|
deleteRelations(id) {
|
package/lib/fields/json.js
CHANGED
|
@@ -8,7 +8,12 @@ class JSONField extends Field {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
fromDB(value) {
|
|
11
|
-
|
|
11
|
+
try {
|
|
12
|
+
if (typeof value === 'string') return JSON.parse(value);
|
|
13
|
+
} catch (error) {
|
|
14
|
+
// Just return the value if it's not a valid JSON string
|
|
15
|
+
return value;
|
|
16
|
+
}
|
|
12
17
|
return value;
|
|
13
18
|
}
|
|
14
19
|
}
|
package/lib/schema/diff.js
CHANGED
|
@@ -344,6 +344,13 @@ module.exports = (db) => {
|
|
|
344
344
|
}
|
|
345
345
|
}
|
|
346
346
|
|
|
347
|
+
const parsePersistedTable = (persistedTable) => {
|
|
348
|
+
if (typeof persistedTable === 'string') {
|
|
349
|
+
return persistedTable;
|
|
350
|
+
}
|
|
351
|
+
return persistedTable.name;
|
|
352
|
+
};
|
|
353
|
+
|
|
347
354
|
const persistedTables = helpers.hasTable(srcSchema, 'strapi_core_store_settings')
|
|
348
355
|
? (await strapi.store.get({
|
|
349
356
|
type: 'core',
|
|
@@ -351,12 +358,19 @@ module.exports = (db) => {
|
|
|
351
358
|
})) ?? []
|
|
352
359
|
: [];
|
|
353
360
|
|
|
361
|
+
const reservedTables = [...RESERVED_TABLE_NAMES, ...persistedTables.map(parsePersistedTable)];
|
|
362
|
+
|
|
354
363
|
for (const srcTable of srcSchema.tables) {
|
|
355
|
-
if (
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
364
|
+
if (!helpers.hasTable(destSchema, srcTable.name) && !reservedTables.includes(srcTable.name)) {
|
|
365
|
+
const dependencies = persistedTables
|
|
366
|
+
.filter((table) => {
|
|
367
|
+
return table?.dependsOn?.some((table) => table.name === srcTable.name);
|
|
368
|
+
})
|
|
369
|
+
.map((dependsOnTable) => {
|
|
370
|
+
return srcSchema.tables.find((srcTable) => srcTable.name === dependsOnTable.name);
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
removedTables.push(srcTable, ...dependencies);
|
|
360
374
|
}
|
|
361
375
|
}
|
|
362
376
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@strapi/database",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.10.0-beta.1",
|
|
4
4
|
"description": "Strapi's database layer",
|
|
5
5
|
"homepage": "https://strapi.io",
|
|
6
6
|
"bugs": {
|
|
@@ -45,5 +45,5 @@
|
|
|
45
45
|
"node": ">=14.19.1 <=18.x.x",
|
|
46
46
|
"npm": ">=6.0.0"
|
|
47
47
|
},
|
|
48
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "95d581b31bee464af42e5d8db408fa578d8532c7"
|
|
49
49
|
}
|