Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
fix: views generating broken Migrations (typeorm#4726)
Browse files Browse the repository at this point in the history
MigrationGenerateCommand didn't apply parameters to query and information about ViewTables couldn't be inserted into typeorm_metadata table. Also added code that creates typeorm_metadata table if ViewTables exists

Fixed issue typeorm#4123
  • Loading branch information
evgeniytar authored and pleerock committed Sep 13, 2019
1 parent 1d73a90 commit c52b3d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/commands/MigrationGenerateCommand.ts
Expand Up @@ -81,17 +81,17 @@ export class MigrationGenerateCommand implements yargs.CommandModule {
// we are using simple quoted string instead of template string syntax
if (connection.driver instanceof MysqlDriver) {
sqlInMemory.upQueries.forEach(upQuery => {
upSqls.push(" await queryRunner.query(\"" + upQuery.query.replace(new RegExp(`"`, "g"), `\\"`) + "\");");
upSqls.push(" await queryRunner.query(\"" + upQuery.query.replace(new RegExp(`"`, "g"), `\\"`) + "\", " + JSON.stringify(upQuery.parameters) + ");");
});
sqlInMemory.downQueries.forEach(downQuery => {
downSqls.push(" await queryRunner.query(\"" + downQuery.query.replace(new RegExp(`"`, "g"), `\\"`) + "\");");
downSqls.push(" await queryRunner.query(\"" + downQuery.query.replace(new RegExp(`"`, "g"), `\\"`) + "\", " + JSON.stringify(downQuery.parameters) + ");");
});
} else {
sqlInMemory.upQueries.forEach(upQuery => {
upSqls.push(" await queryRunner.query(`" + upQuery.query.replace(new RegExp("`", "g"), "\\`") + "`);");
upSqls.push(" await queryRunner.query(`" + upQuery.query.replace(new RegExp("`", "g"), "\\`") + "`, " + JSON.stringify(upQuery.parameters) + ");");
});
sqlInMemory.downQueries.forEach(downQuery => {
downSqls.push(" await queryRunner.query(`" + downQuery.query.replace(new RegExp("`", "g"), "\\`") + "`);");
downSqls.push(" await queryRunner.query(`" + downQuery.query.replace(new RegExp("`", "g"), "\\`") + "`, " + JSON.stringify(downQuery.parameters) + ");");
});
}

Expand Down
4 changes: 4 additions & 0 deletions src/schema-builder/RdbmsSchemaBuilder.ts
Expand Up @@ -104,6 +104,10 @@ export class RdbmsSchemaBuilder implements SchemaBuilder {
this.queryRunner = this.connection.createQueryRunner("master");
try {
const tablePaths = this.entityToSyncMetadatas.map(metadata => metadata.tablePath);
// TODO: typeorm_metadata table needs only for Views for now.
// Remove condition or add new conditions if necessary (for CHECK constraints for example).
if (this.viewEntityToSyncMetadatas.length > 0)
await this.createTypeormMetadataTable();
await this.queryRunner.getTables(tablePaths);
await this.queryRunner.getViews([]);
this.queryRunner.enableSqlMemory();
Expand Down

0 comments on commit c52b3d2

Please sign in to comment.