Skip to content

migration:generate generates migration queries when nothing has changed #8167

Closed

Description

@resistdesign

Issue Description

With no changes to any entities, typeorm is generating migration query statements when running migration:generate.

Expected Behavior

With no changes to an entity, typeorm should not be generating any migration query statements when running migration:generate.

Actual Behavior

With no changes to any entities, typeorm is generating migration query statements when running migration:generate.

// EXAMPLE OUTPUT:
import { MigrationInterface, QueryRunner } from 'typeorm';

export class AddressRefactor1631155178620 implements MigrationInterface {
  name = 'AddressRefactor1631155178620';

  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` DROP FOREIGN KEY \`FK_53c83b83f4e367eb4349fe04029\``
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` DROP PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` ADD \`id\` char(36) NOT NULL PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP FOREIGN KEY \`FK_738760be7585aee2b59abcfb523\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP FOREIGN KEY \`FK_81f288cfe50872d55c40c7d4c32\``
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` DROP PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` ADD \`id\` char(36) NOT NULL PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` CHANGE \`label\` \`label\` text NULL`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` DROP FOREIGN KEY \`FK_e0fcffa1693ff731d49753e6d03\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP FOREIGN KEY \`FK_c6a0b53ff561e1617f4ba97dee1\``
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` DROP PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` ADD \`id\` char(36) NOT NULL PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP FOREIGN KEY \`FK_c39a002aa35cb07fc3900e7638e\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP FOREIGN KEY \`FK_28e9f06f4b7afe099bfc403e6f7\``
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` ADD \`id\` char(36) NOT NULL PRIMARY KEY`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` CHANGE \`salary\` \`salary\` int NULL`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` CHANGE \`yearsOfExperience\` \`yearsOfExperience\` int NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`positionId\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` ADD \`positionId\` char(36) NULL`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`addressId\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` ADD \`addressId\` char(36) NULL`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`firstName\` \`firstName\` varchar(255) NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`lastName\` \`lastName\` varchar(255) NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile\` CHANGE \`email\` \`email\` varchar(255) NULL`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`regionsOfInterest\` \`regionsOfInterest\` text NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`yearsOfExperience\` \`yearsOfExperience\` int NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`youtubeVideoLink\` \`youtubeVideoLink\` varchar(255) NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`linkedInLink\` \`linkedInLink\` varchar(255) NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`profileSummary\` \`profileSummary\` text NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile\` CHANGE \`salary\` \`salary\` int NULL`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`phoneNumber\` \`phoneNumber\` varchar(255) NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`designationId\`)`
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_c39a002aa35cb07fc3900e7638\` ON \`database_name\`.\`work_role_designations_designation\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP COLUMN \`workRoleId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD \`workRoleId\` char(36) NOT NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`designationId\`, \`workRoleId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`workRoleId\`)`
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_738760be7585aee2b59abcfb52\` ON \`database_name\`.\`work_role_designations_designation\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP COLUMN \`designationId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD \`designationId\` char(36) NOT NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`workRoleId\`, \`designationId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP PRIMARY KEY`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_c6a0b53ff561e1617f4ba97dee\` ON \`database_name\`.\`profile_positions_of_interest_position\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP COLUMN \`positionId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD \`positionId\` char(36) NOT NULL`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP PRIMARY KEY`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD PRIMARY KEY (\`profileId\`, \`positionId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_28e9f06f4b7afe099bfc403e6f\` ON \`database_name\`.\`profile_selected_work_roles_work_role\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP COLUMN \`workRoleId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD \`workRoleId\` char(36) NOT NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD PRIMARY KEY (\`profileId\`, \`workRoleId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_81f288cfe50872d55c40c7d4c3\` ON \`database_name\`.\`profile_designations_designation\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP COLUMN \`designationId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD \`designationId\` char(36) NOT NULL`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD PRIMARY KEY (\`profileId\`, \`designationId\`)`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_c39a002aa35cb07fc3900e7638\` ON \`database_name\`.\`work_role_designations_designation\` (\`workRoleId\`)`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_738760be7585aee2b59abcfb52\` ON \`database_name\`.\`work_role_designations_designation\` (\`designationId\`)`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_c6a0b53ff561e1617f4ba97dee\` ON \`database_name\`.\`profile_positions_of_interest_position\` (\`positionId\`)`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_28e9f06f4b7afe099bfc403e6f\` ON \`database_name\`.\`profile_selected_work_roles_work_role\` (\`workRoleId\`)`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_81f288cfe50872d55c40c7d4c3\` ON \`database_name\`.\`profile_designations_designation\` (\`designationId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD CONSTRAINT \`FK_e0fcffa1693ff731d49753e6d03\` FOREIGN KEY (\`positionId\`) REFERENCES \`database_name\`.\`position\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD CONSTRAINT \`FK_53c83b83f4e367eb4349fe04029\` FOREIGN KEY (\`addressId\`) REFERENCES \`database_name\`.\`address\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD CONSTRAINT \`FK_c39a002aa35cb07fc3900e7638e\` FOREIGN KEY (\`workRoleId\`) REFERENCES \`database_name\`.\`work_role\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD CONSTRAINT \`FK_738760be7585aee2b59abcfb523\` FOREIGN KEY (\`designationId\`) REFERENCES \`database_name\`.\`designation\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD CONSTRAINT \`FK_c6a0b53ff561e1617f4ba97dee1\` FOREIGN KEY (\`positionId\`) REFERENCES \`database_name\`.\`position\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD CONSTRAINT \`FK_28e9f06f4b7afe099bfc403e6f7\` FOREIGN KEY (\`workRoleId\`) REFERENCES \`database_name\`.\`work_role\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD CONSTRAINT \`FK_81f288cfe50872d55c40c7d4c32\` FOREIGN KEY (\`designationId\`) REFERENCES \`database_name\`.\`designation\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP FOREIGN KEY \`FK_81f288cfe50872d55c40c7d4c32\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP FOREIGN KEY \`FK_28e9f06f4b7afe099bfc403e6f7\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP FOREIGN KEY \`FK_c6a0b53ff561e1617f4ba97dee1\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP FOREIGN KEY \`FK_738760be7585aee2b59abcfb523\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP FOREIGN KEY \`FK_c39a002aa35cb07fc3900e7638e\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` DROP FOREIGN KEY \`FK_53c83b83f4e367eb4349fe04029\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` DROP FOREIGN KEY \`FK_e0fcffa1693ff731d49753e6d03\``
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_81f288cfe50872d55c40c7d4c3\` ON \`database_name\`.\`profile_designations_designation\``
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_28e9f06f4b7afe099bfc403e6f\` ON \`database_name\`.\`profile_selected_work_roles_work_role\``
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_c6a0b53ff561e1617f4ba97dee\` ON \`database_name\`.\`profile_positions_of_interest_position\``
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_738760be7585aee2b59abcfb52\` ON \`database_name\`.\`work_role_designations_designation\``
    );
    await queryRunner.query(
      `DROP INDEX \`IDX_c39a002aa35cb07fc3900e7638\` ON \`database_name\`.\`work_role_designations_designation\``
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP COLUMN \`designationId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD \`designationId\` varchar(36) NOT NULL`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_81f288cfe50872d55c40c7d4c3\` ON \`database_name\`.\`profile_designations_designation\` (\`designationId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD PRIMARY KEY (\`profileId\`, \`designationId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP COLUMN \`workRoleId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD \`workRoleId\` varchar(36) NOT NULL`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_28e9f06f4b7afe099bfc403e6f\` ON \`database_name\`.\`profile_selected_work_roles_work_role\` (\`workRoleId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD PRIMARY KEY (\`profileId\`, \`workRoleId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP PRIMARY KEY`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD PRIMARY KEY (\`profileId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP COLUMN \`positionId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD \`positionId\` varchar(36) NOT NULL`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_c6a0b53ff561e1617f4ba97dee\` ON \`database_name\`.\`profile_positions_of_interest_position\` (\`positionId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` DROP PRIMARY KEY`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD PRIMARY KEY (\`profileId\`, \`positionId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`workRoleId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP COLUMN \`designationId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD \`designationId\` varchar(36) NOT NULL`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_738760be7585aee2b59abcfb52\` ON \`database_name\`.\`work_role_designations_designation\` (\`designationId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`designationId\`, \`workRoleId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`designationId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP COLUMN \`workRoleId\``
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD \`workRoleId\` varchar(36) NOT NULL`
    );
    await queryRunner.query(
      `CREATE INDEX \`IDX_c39a002aa35cb07fc3900e7638\` ON \`database_name\`.\`work_role_designations_designation\` (\`workRoleId\`)`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role_designations_designation\` DROP PRIMARY KEY`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD PRIMARY KEY (\`workRoleId\`, \`designationId\`)`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`phoneNumber\` \`phoneNumber\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`salary\` \`salary\` int NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`profileSummary\` \`profileSummary\` text NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`linkedInLink\` \`linkedInLink\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`youtubeVideoLink\` \`youtubeVideoLink\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`yearsOfExperience\` \`yearsOfExperience\` int NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`regionsOfInterest\` \`regionsOfInterest\` text NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`email\` \`email\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`lastName\` \`lastName\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile\` CHANGE \`firstName\` \`firstName\` varchar(255) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`addressId\``);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD \`addressId\` varchar(36) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`positionId\``);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD \`positionId\` varchar(36) NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` CHANGE \`yearsOfExperience\` \`yearsOfExperience\` int NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` CHANGE \`salary\` \`salary\` int NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` ADD \`id\` varchar(36) NOT NULL`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`work_role\` ADD PRIMARY KEY (\`id\`)`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_selected_work_roles_work_role\` ADD CONSTRAINT \`FK_28e9f06f4b7afe099bfc403e6f7\` FOREIGN KEY (\`workRoleId\`) REFERENCES \`database_name\`.\`work_role\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD CONSTRAINT \`FK_c39a002aa35cb07fc3900e7638e\` FOREIGN KEY (\`workRoleId\`) REFERENCES \`database_name\`.\`work_role\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` ADD \`id\` varchar(36) NOT NULL`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`position\` ADD PRIMARY KEY (\`id\`)`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_positions_of_interest_position\` ADD CONSTRAINT \`FK_c6a0b53ff561e1617f4ba97dee1\` FOREIGN KEY (\`positionId\`) REFERENCES \`database_name\`.\`position\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD CONSTRAINT \`FK_e0fcffa1693ff731d49753e6d03\` FOREIGN KEY (\`positionId\`) REFERENCES \`database_name\`.\`position\`(\`id\`) ON DELETE NO ACTION ON UPDATE NO ACTION`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`designation\` CHANGE \`label\` \`label\` text NULL DEFAULT 'NULL'`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` ADD \`id\` varchar(36) NOT NULL`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`designation\` ADD PRIMARY KEY (\`id\`)`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`profile_designations_designation\` ADD CONSTRAINT \`FK_81f288cfe50872d55c40c7d4c32\` FOREIGN KEY (\`designationId\`) REFERENCES \`database_name\`.\`designation\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role_designations_designation\` ADD CONSTRAINT \`FK_738760be7585aee2b59abcfb523\` FOREIGN KEY (\`designationId\`) REFERENCES \`database_name\`.\`designation\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` DROP COLUMN \`id\``);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` ADD \`id\` varchar(36) NOT NULL`);
    await queryRunner.query(`ALTER TABLE \`database_name\`.\`address\` ADD PRIMARY KEY (\`id\`)`);
    await queryRunner.query(
      `ALTER TABLE \`database_name\`.\`work_role\` ADD CONSTRAINT \`FK_53c83b83f4e367eb4349fe04029\` FOREIGN KEY (\`addressId\`) REFERENCES \`database_name\`.\`address\`(\`id\`) ON DELETE CASCADE ON UPDATE CASCADE`
    );
  }
}

Steps to Reproduce

  1. Configure typeorm, add some types and run schema:sync
  2. Run migration:generate
typeorm schema:sync
typeorm migration:generate

My Environment

Dependency Version
Operating System any/mac os/linux
Node.js version 12.18.3
Typescript version 4.0.2
TypeORM version 0.2.37

Additional Context

Relevant Database Driver(s)

MySQL driver connecting to MariaDB in AWS RDS.

DB Type Reproducible
aurora-data-api no
aurora-data-api-pg no
better-sqlite3 no
cockroachdb no
cordova no
expo no
mongodb no
mysql YES
nativescript no
oracle no
postgres no
react-native no
sap no
sqlite no
sqlite-abstract no
sqljs no
sqlserver no

Are you willing to resolve this issue by submitting a Pull Request?

  • ✖️ Yes, I have the time, and I know how to start.
  • ✖️ Yes, I have the time, but I don't know how to start. I would need guidance.
  • ✖️ No, I don’t have the time, but I can support (using donations) development.
  • ✅ No, I don’t have the time and I’m okay to wait for the community / maintainers to resolve this issue.

Activity

  1. Kage0x3B commented on Sep 9, 2021

    @Kage0x3B

    Just a guess as I had the same issue earlier, but do you use a custom naming strategy?
    In the example output, you replaced the actual database name so I can't see it from there.

    If you do, that might be the issue, if you didn't configure the typeorm cli correctly, to use the same naming strategy as the connection in your actual program.
    The cli then searches for existing tables/keys/etc. with the default naming strategy, finds none, as the names are different and assumes the tables don't exist yet and generates this big migration.

  2. resistdesign commented on Sep 9, 2021

    @resistdesign
    Author

    @Kage0x3B hmm interesting... I didn't add table names to my entity classes. Is that what you mean?

    One thing I noticed was, if I do add a property to an entity class, it does put the query for that column first, like it seems to know that it's new.

  3. Kage0x3B commented on Sep 10, 2021

    @Kage0x3B

    No, doesn't seem like the same problem then. I meant naming strategies, https://typeorm.io/#/naming-strategy/.
    But after having fixed my issue with naming strategies, I have noticed something similar on the production database, which should be up-to-date, everything works, but typeorms sync still wants to recreate some primary keys and indexes.

    Output from typeorm schema:log:

    ALTER TABLE `database-name`.`order_product` DROP FOREIGN KEY `FK_073c85ed133e05241040bd70f02`;
    ALTER TABLE `database-name`.`order_product` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`order_product` ADD PRIMARY KEY (`orderId`);
    ALTER TABLE `database-name`.`order_product` DROP COLUMN `productId`;
    ALTER TABLE `database-name`.`order_product` ADD `productId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`order_product` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`order_product` ADD PRIMARY KEY (`orderId`, `productId`);
    ALTER TABLE `database-name`.`stored_product` DROP FOREIGN KEY `FK_a2e4f85748cc0aa9265ab5ad2d9`;
    ALTER TABLE `database-name`.`stored_product` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`stored_product` ADD PRIMARY KEY (`storageId`);
    ALTER TABLE `database-name`.`stored_product` DROP COLUMN `productId`;
    ALTER TABLE `database-name`.`stored_product` ADD `productId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`stored_product` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`stored_product` ADD PRIMARY KEY (`storageId`, `productId`);
    ALTER TABLE `database-name`.`order_packet_content` DROP FOREIGN KEY `FK_e1ced39d64c6dea53d576f3741b`;
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP FOREIGN KEY `FK_cb774b7c07631841941dc143d86`;
    ALTER TABLE `database-name`.`product` DROP FOREIGN KEY `FK_1c4b1934c3e8c5b69b3d3d311d6`;
    ALTER TABLE `database-name`.`product` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`product` DROP COLUMN `id`;
    ALTER TABLE `database-name`.`product` ADD `id` char(36) NOT NULL PRIMARY KEY;
    ALTER TABLE `database-name`.`product` DROP COLUMN `shopId`;
    ALTER TABLE `database-name`.`product` ADD `shopId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`order` DROP FOREIGN KEY `FK_318cc4bdeb61d336e3a01f4b767`;
    ALTER TABLE `database-name`.`incoming_stock` DROP FOREIGN KEY `FK_5caa8827445711bec7913eb1760`;
    ALTER TABLE `database-name`.`shop` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`shop` DROP COLUMN `id`;
    ALTER TABLE `database-name`.`shop` ADD `id` char(36) NOT NULL PRIMARY KEY;
    ALTER TABLE `database-name`.`order_packet_content` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`order_packet_content` ADD PRIMARY KEY (`packetId`);
    ALTER TABLE `database-name`.`order_packet_content` DROP COLUMN `productId`;
    ALTER TABLE `database-name`.`order_packet_content` ADD `productId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`order_packet_content` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`order_packet_content` ADD PRIMARY KEY (`packetId`, `productId`);
    ALTER TABLE `database-name`.`order` DROP COLUMN `shopId`;
    ALTER TABLE `database-name`.`order` ADD `shopId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP FOREIGN KEY `FK_2343e86ad3ca49457b1816c9ba8`;
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD PRIMARY KEY (`productId`);
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP COLUMN `incomingStockId`;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD `incomingStockId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD PRIMARY KEY (`productId`, `incomingStockId`);
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD PRIMARY KEY (`incomingStockId`);
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP COLUMN `productId`;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD `productId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`incoming_stock_line_item` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD PRIMARY KEY (`incomingStockId`, `productId`);
    ALTER TABLE `database-name`.`incoming_stock` DROP PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock` DROP COLUMN `id`;
    ALTER TABLE `database-name`.`incoming_stock` ADD `id` char(36) NOT NULL PRIMARY KEY;
    ALTER TABLE `database-name`.`incoming_stock` DROP COLUMN `shopId`;
    ALTER TABLE `database-name`.`incoming_stock` ADD `shopId` char(36) NOT NULL;
    ALTER TABLE `database-name`.`refresh_token` DROP COLUMN `token`;
    ALTER TABLE `database-name`.`refresh_token` ADD `token` char(36) NOT NULL;
    ALTER TABLE `database-name`.`order_product` ADD CONSTRAINT `FK_073c85ed133e05241040bd70f02` FOREIGN KEY (`productId`) REFERENCES `database-name`.`product`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`stored_product` ADD CONSTRAINT `FK_a2e4f85748cc0aa9265ab5ad2d9` FOREIGN KEY (`productId`) REFERENCES `database-name`.`product`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`product` ADD CONSTRAINT `FK_1c4b1934c3e8c5b69b3d3d311d6` FOREIGN KEY (`shopId`) REFERENCES `database-name`.`shop`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`order_packet_content` ADD CONSTRAINT `FK_e1ced39d64c6dea53d576f3741b` FOREIGN KEY (`productId`) REFERENCES `database-name`.`product`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`order` ADD CONSTRAINT `FK_318cc4bdeb61d336e3a01f4b767` FOREIGN KEY (`shopId`) REFERENCES `database-name`.`shop`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD CONSTRAINT `FK_2343e86ad3ca49457b1816c9ba8` FOREIGN KEY (`incomingStockId`) REFERENCES `database-name`.`incoming_stock`(`id`) ON DELETE CASCADE ON UPDATE CASCADE;
    ALTER TABLE `database-name`.`incoming_stock_line_item` ADD CONSTRAINT `FK_cb774b7c07631841941dc143d86` FOREIGN KEY (`productId`) REFERENCES `database-name`.`product`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
    ALTER TABLE `database-name`.`incoming_stock` ADD CONSTRAINT `FK_5caa8827445711bec7913eb1760` FOREIGN KEY (`shopId`) REFERENCES `database-name`.`shop`(`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;
  4. meganoob1337 commented on Sep 10, 2021

    @meganoob1337

    Maybe it has something to do with this: #8173
    They changed the Implementation of the SnakeCase generator so some Entity Names might get resolved differently

  5. resistdesign commented on Sep 10, 2021

    @resistdesign
    Author

    @Kage0x3B Ok, based on that link, I definitely don't have a custom naming strategy. This is kind of weird 😛
    @meganoob1337 It doesn't seem like a snake case issue for me 🤷

  6. resistdesign commented on Sep 10, 2021

    @resistdesign
    Author

    Something interesting is that there are CHANGE lines, like this one:

    await queryRunner.query(
          `ALTER TABLE \`database_name\`.\`work_role\` CHANGE \`yearsOfExperience\` \`yearsOfExperience\` int NULL`
        );

    Why would it call it a change if it doesn't change anything?

  7. resistdesign commented on Sep 10, 2021

    @resistdesign
    Author

    It almost feels like it's generating those lines just to set the default value, as if schema:sync didn't do that or something.

    It does seem like the default value is NOT set:
    image

  8. fanch317 commented on Sep 14, 2021

    @fanch317

    Can you check that you use TYPEROM_TYPE = mariadb (instead mysql)?

    I had similar case, where the NULL wasn't correctly detected. You can check #6030 (comment) for my diag.
    I have abandoned and have rewrite manualy each migration, before find my mistake after many mounth in .env / ormconfig.json file.

  9. resistdesign commented on Sep 14, 2021

    @resistdesign
    Author

    @fanch317 Oh Dang! I never would have thought of that!
    image

  10. resistdesign commented on Sep 14, 2021

    @resistdesign
    Author

    I have to check to see if that solves the problem.

  11. resistdesign commented on Sep 14, 2021

    @resistdesign
    Author

    @fanch317 Oh man, I really thought you had found the issue, but after setting the type to mariadb and running the generation, it still generates the same thing 😦
    I even made sure to use mariadb as the protocol in the connection URI I used, just in case, but it didn't change it.

  12. sebdec commented on Sep 23, 2021

    @sebdec

    I have the same problem.

    My understanding:
    before: id and foreign keys were generated with type varchar(36)
    after: id and foreign keys are now generated with type char(36)

  13. resistdesign commented on Sep 24, 2021

    @resistdesign
    Author

    @sebdec YES! In the DB, the id field is varchar, but in the generated migration, it wants to recreate it as char.

    I wonder how this can be fixed???

  14. pleerock commented on Nov 9, 2021

    @pleerock
    Member

    Looks like this is duplicate of #8002

  15. pleerock commented on Nov 9, 2021

    @pleerock
    Member

    Fixed by #8343

  16. resistdesign commented on Nov 9, 2021

    @resistdesign
    Author

    For real!??? This will fix my problem!? 😲😲😲😁😁😁

  17. gagermaniac commented on Nov 17, 2021

    @gagermaniac

    Can you check that you use TYPEROM_TYPE = mariadb (instead mysql)?

    I had similar case, where the NULL wasn't correctly detected. You can check #6030 (comment) for my diag. I have abandoned and have rewrite manualy each migration, before find my mistake after many mounth in .env / ormconfig.json file.

    changing typeorm type to mariadb do fix my problem, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions