Skip to content
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

Add a migration for outstanding differences detected by TypeORM migration:generate #1513

Closed
pbn4 opened this issue Jul 14, 2021 · 0 comments
Closed
Assignees
Labels
tech debt Long-term required changes that has been push down the road

Comments

@pbn4
Copy link
Contributor

pbn4 commented Jul 14, 2021

When generating a new migration TypeORM recreates some foreign key constraints and a missing listing name column NOT NULL constraint:

import {MigrationInterface, QueryRunner} from "typeorm";

export class recreateForeignKeyConstraints1626268250228 implements MigrationInterface {
    name = 'recreateForeignKeyConstraints1626268250228'

    public async up(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" DROP CONSTRAINT "FK_bbae218ba0eff977157fad5ea31"`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" DROP CONSTRAINT "FK_93f583f2d43fb21c5d7ceac57e7"`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" DROP CONSTRAINT "FK_de53131bc8a08f824a5d3dd51e3"`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" DROP CONSTRAINT "FK_f7b22af2c421e823f60c5f7d28b"`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" DROP CONSTRAINT "FK_84e6a1949911510df0eff691f0d"`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" DROP CONSTRAINT "FK_c99e75ee805d56fea44bf2970f2"`);
        await queryRunner.query(`ALTER TABLE "listings" ALTER COLUMN "name" SET NOT NULL`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" ADD CONSTRAINT "FK_93f583f2d43fb21c5d7ceac57e7" FOREIGN KEY ("application_flagged_set_id") REFERENCES "application_flagged_set"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" ADD CONSTRAINT "FK_bbae218ba0eff977157fad5ea31" FOREIGN KEY ("applications_id") REFERENCES "applications"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" ADD CONSTRAINT "FK_f7b22af2c421e823f60c5f7d28b" FOREIGN KEY ("listings_id") REFERENCES "listings"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" ADD CONSTRAINT "FK_de53131bc8a08f824a5d3dd51e3" FOREIGN KEY ("user_accounts_id") REFERENCES "user_accounts"("id") ON DELETE NO ACTION ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" ADD CONSTRAINT "FK_84e6a1949911510df0eff691f0d" FOREIGN KEY ("property_group_id") REFERENCES "property_group"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" ADD CONSTRAINT "FK_c99e75ee805d56fea44bf2970f2" FOREIGN KEY ("property_id") REFERENCES "property"("id") ON DELETE CASCADE ON UPDATE CASCADE`);
    }

    public async down(queryRunner: QueryRunner): Promise<void> {
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" DROP CONSTRAINT "FK_c99e75ee805d56fea44bf2970f2"`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" DROP CONSTRAINT "FK_84e6a1949911510df0eff691f0d"`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" DROP CONSTRAINT "FK_de53131bc8a08f824a5d3dd51e3"`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" DROP CONSTRAINT "FK_f7b22af2c421e823f60c5f7d28b"`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" DROP CONSTRAINT "FK_bbae218ba0eff977157fad5ea31"`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" DROP CONSTRAINT "FK_93f583f2d43fb21c5d7ceac57e7"`);
        await queryRunner.query(`ALTER TABLE "listings" ALTER COLUMN "name" DROP NOT NULL`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" ADD CONSTRAINT "FK_c99e75ee805d56fea44bf2970f2" FOREIGN KEY ("property_id") REFERENCES "property"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "property_group_properties_property" ADD CONSTRAINT "FK_84e6a1949911510df0eff691f0d" FOREIGN KEY ("property_group_id") REFERENCES "property_group"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" ADD CONSTRAINT "FK_f7b22af2c421e823f60c5f7d28b" FOREIGN KEY ("listings_id") REFERENCES "listings"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "listings_leasing_agents_user_accounts" ADD CONSTRAINT "FK_de53131bc8a08f824a5d3dd51e3" FOREIGN KEY ("user_accounts_id") REFERENCES "user_accounts"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" ADD CONSTRAINT "FK_93f583f2d43fb21c5d7ceac57e7" FOREIGN KEY ("application_flagged_set_id") REFERENCES "application_flagged_set"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
        await queryRunner.query(`ALTER TABLE "application_flagged_set_applications_applications" ADD CONSTRAINT "FK_bbae218ba0eff977157fad5ea31" FOREIGN KEY ("applications_id") REFERENCES "applications"("id") ON DELETE CASCADE ON UPDATE NO ACTION`);
    }

}
  1. NOT NULL on name is probably because someone missed adding a migration for it
  2. Foreign key constraints recreation I'm not sure
@pbn4 pbn4 added the tech debt Long-term required changes that has been push down the road label Jul 14, 2021
@pbn4 pbn4 self-assigned this Jul 14, 2021
@pbn4 pbn4 changed the title Add a migration for outstandingdifferences detected by TypeORM migration:generate Add a migration for outstanding differences detected by TypeORM migration:generate Jul 14, 2021
@pbn4 pbn4 closed this as completed Jul 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech debt Long-term required changes that has been push down the road
Projects
None yet
Development

No branches or pull requests

1 participant