@strapi/database 5.0.0-rc.22 → 5.0.0-rc.23
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 +18 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/dist/metadata/metadata.d.ts.map +1 -1
- package/dist/metadata/relations.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +5 -5
package/dist/index.mjs
CHANGED
|
@@ -2261,7 +2261,7 @@ const createOneToOne = (attributeName, attribute, meta, metadata) => {
|
|
|
2261
2261
|
}
|
|
2262
2262
|
};
|
|
2263
2263
|
const createOneToMany = (attributeName, attribute, meta, metadata) => {
|
|
2264
|
-
if (!isBidirectional(attribute)) {
|
|
2264
|
+
if (shouldUseJoinTable(attribute) && !isBidirectional(attribute)) {
|
|
2265
2265
|
createJoinTable(metadata, {
|
|
2266
2266
|
attribute,
|
|
2267
2267
|
attributeName,
|
|
@@ -2290,7 +2290,7 @@ const createManyToOne = (attributeName, attribute, meta, metadata) => {
|
|
|
2290
2290
|
}
|
|
2291
2291
|
};
|
|
2292
2292
|
const createManyToMany = (attributeName, attribute, meta, metadata) => {
|
|
2293
|
-
if (!isBidirectional(attribute) || isOwner(attribute)) {
|
|
2293
|
+
if (shouldUseJoinTable(attribute) && (!isBidirectional(attribute) || isOwner(attribute))) {
|
|
2294
2294
|
createJoinTable(metadata, {
|
|
2295
2295
|
attribute,
|
|
2296
2296
|
attributeName,
|
|
@@ -2451,6 +2451,9 @@ const createJoinColumn = (metadata, { attribute, attributeName }) => {
|
|
|
2451
2451
|
}
|
|
2452
2452
|
};
|
|
2453
2453
|
const createJoinTable = (metadata, { attributeName, attribute, meta }) => {
|
|
2454
|
+
if (!shouldUseJoinTable(attribute)) {
|
|
2455
|
+
throw new Error("Attempted to create join table when useJoinTable is false");
|
|
2456
|
+
}
|
|
2454
2457
|
const targetMeta = metadata.get(attribute.target);
|
|
2455
2458
|
if (!targetMeta) {
|
|
2456
2459
|
throw new Error(`Unknown target ${attribute.target}`);
|
|
@@ -2685,6 +2688,9 @@ class Metadata extends Map {
|
|
|
2685
2688
|
for (const meta of this.values()) {
|
|
2686
2689
|
for (const [attributeName, attribute] of Object.entries(meta.attributes)) {
|
|
2687
2690
|
try {
|
|
2691
|
+
if (attribute.unstable_virtual) {
|
|
2692
|
+
continue;
|
|
2693
|
+
}
|
|
2688
2694
|
if (isRelationalAttribute(attribute)) {
|
|
2689
2695
|
createRelation(attributeName, attribute, meta, this);
|
|
2690
2696
|
continue;
|
|
@@ -6258,21 +6264,24 @@ const renameIndex = async (knex2, db, diff) => {
|
|
|
6258
6264
|
debug(`not renaming index ${full.indexName} because name hasn't changed`);
|
|
6259
6265
|
return;
|
|
6260
6266
|
}
|
|
6261
|
-
if (short.indexName.
|
|
6267
|
+
if (short.indexName.endsWith("fk") || full.indexName.endsWith("fk")) {
|
|
6262
6268
|
return;
|
|
6263
6269
|
}
|
|
6264
6270
|
debug(`renaming index from ${full.indexName} to ${short.indexName}`);
|
|
6265
6271
|
try {
|
|
6266
6272
|
await knex2.transaction(async (trx) => {
|
|
6267
6273
|
if (client === "mysql" || client === "mariadb") {
|
|
6268
|
-
await knex2.raw(
|
|
6269
|
-
|
|
6270
|
-
|
|
6274
|
+
await knex2.raw("ALTER TABLE ?? RENAME INDEX ?? TO ??", [
|
|
6275
|
+
full.tableName,
|
|
6276
|
+
full.indexName,
|
|
6277
|
+
short.indexName
|
|
6278
|
+
]).transacting(trx);
|
|
6271
6279
|
} else if (client === "pg" || client === "postgres") {
|
|
6272
|
-
await knex2.raw(
|
|
6273
|
-
} else if (
|
|
6280
|
+
await knex2.raw("ALTER INDEX ?? RENAME TO ??", [full.indexName, short.indexName]).transacting(trx);
|
|
6281
|
+
} else if (["sqlite", "sqlite3", "better-sqlite3"].includes(client)) {
|
|
6282
|
+
debug(`SQLite does not support index renaming, not renaming index ${full.indexName}`);
|
|
6274
6283
|
} else {
|
|
6275
|
-
debug(
|
|
6284
|
+
debug(`No db client name matches, not renaming index ${full.indexName}`);
|
|
6276
6285
|
}
|
|
6277
6286
|
});
|
|
6278
6287
|
} catch (err) {
|