@mikro-orm/knex 6.5.8-dev.11 → 6.5.8-dev.12
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/package.json +2 -2
- package/schema/DatabaseTable.js +27 -26
- package/schema/SchemaComparator.js +1 -1
- package/schema/SchemaHelper.js +1 -1
- package/typings.d.ts +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.5.8-dev.
|
|
3
|
+
"version": "6.5.8-dev.12",
|
|
4
4
|
"description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.5.7"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.5.8-dev.
|
|
69
|
+
"@mikro-orm/core": "6.5.8-dev.12",
|
|
70
70
|
"better-sqlite3": "*",
|
|
71
71
|
"libsql": "*",
|
|
72
72
|
"mariadb": "*"
|
package/schema/DatabaseTable.js
CHANGED
|
@@ -109,33 +109,34 @@ class DatabaseTable {
|
|
|
109
109
|
if (prop.referencedTableName.includes('.')) {
|
|
110
110
|
schema = undefined;
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
constraintName
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
112
|
+
if (prop.createForeignKeyConstraint) {
|
|
113
|
+
this.foreignKeys[constraintName] = {
|
|
114
|
+
constraintName,
|
|
115
|
+
columnNames: prop.fieldNames,
|
|
116
|
+
localTableName: this.getShortestName(),
|
|
117
|
+
referencedColumnNames: prop.referencedColumnNames,
|
|
118
|
+
referencedTableName: schema ? `${schema}.${prop.referencedTableName}` : prop.referencedTableName,
|
|
119
|
+
};
|
|
120
|
+
const cascade = prop.cascade.includes(core_1.Cascade.REMOVE) || prop.cascade.includes(core_1.Cascade.ALL);
|
|
121
|
+
if (prop.deleteRule || cascade || prop.nullable) {
|
|
122
|
+
this.foreignKeys[constraintName].deleteRule = prop.deleteRule || (cascade ? 'cascade' : 'set null');
|
|
123
|
+
}
|
|
124
|
+
if (prop.updateRule) {
|
|
125
|
+
this.foreignKeys[constraintName].updateRule = prop.updateRule || 'cascade';
|
|
126
|
+
}
|
|
127
|
+
if ((prop.cascade.includes(core_1.Cascade.PERSIST) || prop.cascade.includes(core_1.Cascade.ALL))) {
|
|
128
|
+
const hasCascadePath = Object.values(this.foreignKeys).some(fk => {
|
|
129
|
+
return fk.constraintName !== constraintName
|
|
130
|
+
&& ((fk.updateRule && fk.updateRule !== 'no action') || (fk.deleteRule && fk.deleteRule !== 'no action'))
|
|
131
|
+
&& fk.referencedTableName === this.foreignKeys[constraintName].referencedTableName;
|
|
132
|
+
});
|
|
133
|
+
if (!hasCascadePath || this.platform.supportsMultipleCascadePaths()) {
|
|
134
|
+
this.foreignKeys[constraintName].updateRule ??= 'cascade';
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (prop.deferMode) {
|
|
138
|
+
this.foreignKeys[constraintName].deferMode = prop.deferMode;
|
|
135
139
|
}
|
|
136
|
-
}
|
|
137
|
-
if (prop.deferMode) {
|
|
138
|
-
this.foreignKeys[constraintName].deferMode = prop.deferMode;
|
|
139
140
|
}
|
|
140
141
|
}
|
|
141
142
|
if (prop.index) {
|
|
@@ -268,7 +268,7 @@ class SchemaComparator {
|
|
|
268
268
|
}
|
|
269
269
|
for (const toConstraint of Object.values(toForeignKeys)) {
|
|
270
270
|
tableDifferences.addedForeignKeys[toConstraint.constraintName] = toConstraint;
|
|
271
|
-
this.log(`FK constraint ${toConstraint.constraintName} added
|
|
271
|
+
this.log(`FK constraint ${toConstraint.constraintName} added to table ${tableDifferences.name}`, { constraint: toConstraint });
|
|
272
272
|
changes++;
|
|
273
273
|
}
|
|
274
274
|
return changes ? tableDifferences : false;
|
package/schema/SchemaHelper.js
CHANGED
|
@@ -321,7 +321,7 @@ class SchemaHelper {
|
|
|
321
321
|
});
|
|
322
322
|
}
|
|
323
323
|
createForeignKey(table, foreignKey, schema) {
|
|
324
|
-
if (!this.options.createForeignKeyConstraints
|
|
324
|
+
if (!this.options.createForeignKeyConstraints) {
|
|
325
325
|
return;
|
|
326
326
|
}
|
|
327
327
|
const builder = table
|