fix: migrations being generated for FK even if there are no changes (… · typeorm/typeorm@416e419
@@ -1424,7 +1424,6 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
14241424this.query(indicesSql),
14251425this.query(foreignKeysSql),
14261426]);
1427-14281427// if tables were not found in the db, no need to proceed
14291428if (!dbTables.length)
14301429return [];
@@ -1433,9 +1432,10 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
14331432return Promise.all(dbTables.map(async dbTable => {
14341433const table = new Table();
143514341435+const getSchemaFromKey = (dbObject: any, key: string) => dbObject[key] === currentSchema && !this.driver.options.schema ? undefined : dbObject[key];
14361436// We do not need to join schema name, when database is by default.
14371437// In this case we need local variable `tableFullName` for below comparision.
1438-const schema = dbTable["table_schema"] === currentSchema && !this.driver.options.schema ? undefined : dbTable["table_schema"];
1438+const schema = getSchemaFromKey(dbTable, "table_schema");
14391439table.name = this.driver.buildTableName(dbTable["table_name"], schema);
14401440const tableFullName = this.driver.buildTableName(dbTable["table_name"], dbTable["table_schema"]);
14411441@@ -1612,7 +1612,7 @@ export class PostgresQueryRunner extends BaseQueryRunner implements QueryRunner
16121612const foreignKeys = dbForeignKeys.filter(dbFk => dbFk["constraint_name"] === dbForeignKey["constraint_name"]);
1613161316141614// if referenced table located in currently used schema, we don't need to concat schema name to table name.
1615-const schema = dbForeignKey["referenced_table_schema"] === currentSchema ? undefined : dbForeignKey["referenced_table_schema"];
1615+const schema = getSchemaFromKey(dbForeignKey, "referenced_table_schema");
16161616const referencedTableName = this.driver.buildTableName(dbForeignKey["referenced_table_name"], schema);
1617161716181618return new TableForeignKey({