@mikro-orm/knex 6.0.0-dev.168 → 6.0.0-dev.169
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
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.0.0-dev.
|
|
3
|
+
"version": "6.0.0-dev.169",
|
|
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,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^5.9.2"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.0.0-dev.
|
|
69
|
+
"@mikro-orm/core": "6.0.0-dev.169"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -17,12 +17,12 @@ export declare class SchemaComparator {
|
|
|
17
17
|
* operations to change the schema stored in fromSchema to the schema that is
|
|
18
18
|
* stored in toSchema.
|
|
19
19
|
*/
|
|
20
|
-
compare(fromSchema: DatabaseSchema, toSchema: DatabaseSchema): SchemaDifference;
|
|
20
|
+
compare(fromSchema: DatabaseSchema, toSchema: DatabaseSchema, inverseDiff?: SchemaDifference): SchemaDifference;
|
|
21
21
|
/**
|
|
22
22
|
* Returns the difference between the tables fromTable and toTable.
|
|
23
23
|
* If there are no differences this method returns the boolean false.
|
|
24
24
|
*/
|
|
25
|
-
diffTable(fromTable: DatabaseTable, toTable: DatabaseTable): TableDifference | false;
|
|
25
|
+
diffTable(fromTable: DatabaseTable, toTable: DatabaseTable, inverseTableDiff?: TableDifference): TableDifference | false;
|
|
26
26
|
/**
|
|
27
27
|
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
|
|
28
28
|
* however ambiguities between different possibilities should not lead to renaming at all.
|
|
@@ -22,7 +22,7 @@ class SchemaComparator {
|
|
|
22
22
|
* operations to change the schema stored in fromSchema to the schema that is
|
|
23
23
|
* stored in toSchema.
|
|
24
24
|
*/
|
|
25
|
-
compare(fromSchema, toSchema) {
|
|
25
|
+
compare(fromSchema, toSchema, inverseDiff) {
|
|
26
26
|
const diff = { newTables: {}, removedTables: {}, changedTables: {}, orphanedForeignKeys: [], newNamespaces: new Set(), removedNamespaces: new Set(), fromSchema };
|
|
27
27
|
const foreignKeysToTable = {};
|
|
28
28
|
for (const namespace of toSchema.getNamespaces()) {
|
|
@@ -43,7 +43,7 @@ class SchemaComparator {
|
|
|
43
43
|
diff.newTables[tableName] = toSchema.getTable(tableName);
|
|
44
44
|
}
|
|
45
45
|
else {
|
|
46
|
-
const tableDifferences = this.diffTable(fromSchema.getTable(tableName), toSchema.getTable(tableName));
|
|
46
|
+
const tableDifferences = this.diffTable(fromSchema.getTable(tableName), toSchema.getTable(tableName), inverseDiff?.changedTables[tableName]);
|
|
47
47
|
if (tableDifferences !== false) {
|
|
48
48
|
diff.changedTables[tableName] = tableDifferences;
|
|
49
49
|
}
|
|
@@ -91,7 +91,7 @@ class SchemaComparator {
|
|
|
91
91
|
* Returns the difference between the tables fromTable and toTable.
|
|
92
92
|
* If there are no differences this method returns the boolean false.
|
|
93
93
|
*/
|
|
94
|
-
diffTable(fromTable, toTable) {
|
|
94
|
+
diffTable(fromTable, toTable, inverseTableDiff) {
|
|
95
95
|
let changes = 0;
|
|
96
96
|
const tableDifferences = {
|
|
97
97
|
name: fromTable.getShortestName(),
|
|
@@ -157,7 +157,7 @@ class SchemaComparator {
|
|
|
157
157
|
this.log(`column ${tableDifferences.name}.${column.name} changed`, { changedProperties });
|
|
158
158
|
changes++;
|
|
159
159
|
}
|
|
160
|
-
this.detectColumnRenamings(tableDifferences);
|
|
160
|
+
this.detectColumnRenamings(tableDifferences, inverseTableDiff);
|
|
161
161
|
const fromTableIndexes = fromTable.getIndexes();
|
|
162
162
|
const toTableIndexes = toTable.getIndexes();
|
|
163
163
|
// See if all the indexes in "from" table exist in "to" table
|
|
@@ -249,7 +249,7 @@ class SchemaComparator {
|
|
|
249
249
|
* Try to find columns that only changed their name, rename operations maybe cheaper than add/drop
|
|
250
250
|
* however ambiguities between different possibilities should not lead to renaming at all.
|
|
251
251
|
*/
|
|
252
|
-
detectColumnRenamings(tableDifferences) {
|
|
252
|
+
detectColumnRenamings(tableDifferences, inverseTableDiff) {
|
|
253
253
|
const renameCandidates = {};
|
|
254
254
|
for (const addedColumn of Object.values(tableDifferences.addedColumns)) {
|
|
255
255
|
for (const removedColumn of Object.values(tableDifferences.removedColumns)) {
|
|
@@ -257,6 +257,10 @@ class SchemaComparator {
|
|
|
257
257
|
if (diff.size !== 0) {
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
|
+
const renamedColumn = inverseTableDiff?.renamedColumns[addedColumn.name];
|
|
261
|
+
if (renamedColumn && renamedColumn?.name !== removedColumn.name) {
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
260
264
|
renameCandidates[addedColumn.name] = renameCandidates[addedColumn.name] ?? [];
|
|
261
265
|
renameCandidates[addedColumn.name].push([removedColumn, addedColumn]);
|
|
262
266
|
}
|
|
@@ -143,7 +143,7 @@ class SqlSchemaGenerator extends core_1.AbstractSchemaGenerator {
|
|
|
143
143
|
const { fromSchema, toSchema } = await this.prepareSchemaForComparison(options);
|
|
144
144
|
const comparator = new SchemaComparator_1.SchemaComparator(this.platform);
|
|
145
145
|
const diffUp = comparator.compare(fromSchema, toSchema);
|
|
146
|
-
const diffDown = comparator.compare(toSchema, fromSchema);
|
|
146
|
+
const diffDown = comparator.compare(toSchema, fromSchema, diffUp);
|
|
147
147
|
return {
|
|
148
148
|
up: await this.diffToSQL(diffUp, options),
|
|
149
149
|
down: this.platform.supportsDownMigrations() ? await this.diffToSQL(diffDown, options) : '',
|