New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generated migrations are very noisy with lots of duplicated or otherwise useless queries #4577
Comments
Please provide schema before and after changes which this migration was made from. |
@Kononnable I don't quite understand your question. Do you want me to post the before/after of the model classes? |
This is happening to me too. Here's an example with check constraints. I don't change anything about my models at all, I just call ModelsHelpers: export function einDbType(
options: Omit<ColumnOptions, "type" | "transformer">
): ColumnOptions {
return {
...options,
type: "character varying",
transformer: {
from: ein => normalizeEin(ein),
// Outstanding bug in TypeORM: transformer may receive a FindOperator
// instead of the actual value of the class member.
// https://github.com/typeorm/typeorm/issues/2390
// eslint-disable-next-line @typescript-eslint/no-explicit-any
to: (entityValue: string | FindOperator<any>) => {
if (typeof entityValue !== "string") {
return entityValue;
}
const normalizedEin = normalizeEin(entityValue);
if (!normalizedEin) {
throw new Error(
`ein provided to transformer was not a valid EIN: "${entityValue}"`
);
}
return normalizedEin;
}
}
};
}
export function einCheckConstraint(colName: string) {
return `"${colName}" ~* '${EIN_REGEX_STR}'`;
} Nonprofit: @Entity()
@Check(einCheckConstraint("ein"))
export class Nonprofit {
// ...
@Column(einDbType({ unique: true, nullable: false }))
public ein!: string;
} Same code exists in a few other entities, whose tables are Generated Migrationsclass MyMigration implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "nonprofit" DROP CONSTRAINT "CHK_b3f7d9090dbcc5276b6548c9f3"`);
await queryRunner.query(`ALTER TABLE "nonprofit_metadata" DROP CONSTRAINT "CHK_68b699c8dea84bf62767bfe15a"`);
await queryRunner.query(`ALTER TABLE "nonprofit_public_metadata" DROP CONSTRAINT "CHK_a1cb07d86769c652bbd748b9c9"`);
await queryRunner.query(`ALTER TABLE "nonprofit" ADD CONSTRAINT "CHK_41a3bddb38534fda1bca83276b" CHECK ("ein" ~* '^[0-9]{9}$')`);
await queryRunner.query(`ALTER TABLE "nonprofit_metadata" ADD CONSTRAINT "CHK_9d267bc1175b85f906c79b94dc" CHECK ("ein" ~* '^[0-9]{9}$')`);
await queryRunner.query(`ALTER TABLE "nonprofit_public_metadata" ADD CONSTRAINT "CHK_d612fd06767fd686f649b89409" CHECK ("ein" ~* '^[0-9]{9}$')`);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "nonprofit_public_metadata" DROP CONSTRAINT "CHK_d612fd06767fd686f649b89409"`);
await queryRunner.query(`ALTER TABLE "nonprofit_metadata" DROP CONSTRAINT "CHK_9d267bc1175b85f906c79b94dc"`);
await queryRunner.query(`ALTER TABLE "nonprofit" DROP CONSTRAINT "CHK_41a3bddb38534fda1bca83276b"`);
await queryRunner.query(`ALTER TABLE "nonprofit_public_metadata" ADD CONSTRAINT "CHK_a1cb07d86769c652bbd748b9c9" CHECK (((ein)::text ~* '^[0-9]{9}$'::text))`);
await queryRunner.query(`ALTER TABLE "nonprofit_metadata" ADD CONSTRAINT "CHK_68b699c8dea84bf62767bfe15a" CHECK (((ein)::text ~* '^[0-9]{9}$'::text))`);
await queryRunner.query(`ALTER TABLE "nonprofit" ADD CONSTRAINT "CHK_b3f7d9090dbcc5276b6548c9f3" CHECK (((ein)::text ~* '^[0-9]{9}$'::text))`);
}
} In reality all of this is noise and useless and I just have to keep deleting them. EDIT: |
Maybe related to #3280 ? |
And also looks like this is related too, but was closed even though the problem wasn't actually fixed for a number of people: #1686 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Closing this as a duplicate of #3280 |
Issue type:
Database system/driver:
cordova
mongodb
mssql
mysql
/mariadb
oracle
postgres
cockroachdb
sqlite
sqljs
react-native
expo
TypeORM version:
latest
@next
0.2.18
(or put your version here)Steps to reproduce or a small repository showing the problem:
I previously had a many to many join between two tables. I am replacing this with a join entity in order to add additional columns to it.
From there, if I run
orm migration:generate
typeorm generates the following migration with loads of create/drop indexes, columns etc. inThe text was updated successfully, but these errors were encountered: