Skip to content

Commit

Permalink
removed foreignkeys query from migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
li0nbelenky committed Feb 27, 2022
1 parent 7c70ebf commit 92b1c49
Showing 1 changed file with 20 additions and 20 deletions.
40 changes: 20 additions & 20 deletions src/driver/mysql/MysqlQueryRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1566,26 +1566,26 @@ export class MysqlQueryRunner extends BaseQueryRunner implements QueryRunner {
});

// find foreign key constraints of table, group them by constraint name and build TableForeignKey.
const tableForeignKeyConstraints = OrmUtils.uniq(dbForeignKeys.filter(dbForeignKey => {
return this.driver.buildTableName(dbForeignKey["TABLE_NAME"], undefined, dbForeignKey["TABLE_SCHEMA"]) === tableFullName;
}), dbForeignKey => dbForeignKey["CONSTRAINT_NAME"]);

table.foreignKeys = tableForeignKeyConstraints.map(dbForeignKey => {
const foreignKeys = dbForeignKeys.filter(dbFk => dbFk["CONSTRAINT_NAME"] === dbForeignKey["CONSTRAINT_NAME"]);

// if referenced table located in currently used db, we don't need to concat db name to table name.
const database = dbForeignKey["REFERENCED_TABLE_SCHEMA"] === currentDatabase ? undefined : dbForeignKey["REFERENCED_TABLE_SCHEMA"];
const referencedTableName = this.driver.buildTableName(dbForeignKey["REFERENCED_TABLE_NAME"], undefined, database);

return new TableForeignKey({
name: dbForeignKey["CONSTRAINT_NAME"],
columnNames: foreignKeys.map(dbFk => dbFk["COLUMN_NAME"]),
referencedTableName: referencedTableName,
referencedColumnNames: foreignKeys.map(dbFk => dbFk["REFERENCED_COLUMN_NAME"]),
onDelete: dbForeignKey["ON_DELETE"],
onUpdate: dbForeignKey["ON_UPDATE"]
});
});
// const tableForeignKeyConstraints = OrmUtils.uniq(dbForeignKeys.filter(dbForeignKey => {
// return this.driver.buildTableName(dbForeignKey["TABLE_NAME"], undefined, dbForeignKey["TABLE_SCHEMA"]) === tableFullName;
// }), dbForeignKey => dbForeignKey["CONSTRAINT_NAME"]);
//
// table.foreignKeys = tableForeignKeyConstraints.map(dbForeignKey => {
// const foreignKeys = dbForeignKeys.filter(dbFk => dbFk["CONSTRAINT_NAME"] === dbForeignKey["CONSTRAINT_NAME"]);
//
// // if referenced table located in currently used db, we don't need to concat db name to table name.
// const database = dbForeignKey["REFERENCED_TABLE_SCHEMA"] === currentDatabase ? undefined : dbForeignKey["REFERENCED_TABLE_SCHEMA"];
// const referencedTableName = this.driver.buildTableName(dbForeignKey["REFERENCED_TABLE_NAME"], undefined, database);
//
// return new TableForeignKey({
// name: dbForeignKey["CONSTRAINT_NAME"],
// columnNames: foreignKeys.map(dbFk => dbFk["COLUMN_NAME"]),
// referencedTableName: referencedTableName,
// referencedColumnNames: foreignKeys.map(dbFk => dbFk["REFERENCED_COLUMN_NAME"]),
// onDelete: dbForeignKey["ON_DELETE"],
// onUpdate: dbForeignKey["ON_UPDATE"]
// });
// });

// find index constraints of table, group them by constraint name and build TableIndex.
const tableIndexConstraints = OrmUtils.uniq(dbIndices.filter(dbIndex => {
Expand Down

0 comments on commit 92b1c49

Please sign in to comment.