My NestJS application utilizes TypeORM with a PostgreSQL database. Every time I attempt to create a migration to synchronize the database and apply changes, the generated migration file consistently contains the following queries (some irrelevant queries have been omitted for clarity):
export class portal1631976435381 implements MigrationInterface {
name = 'portal1631976435381'
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "isTransporter"`);
await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "crmId"`);
await queryRunner.query(`ALTER TABLE "organization" DROP COLUMN "telephoneNumber"`);
await queryRunner.query(`ALTER TABLE "organization" ADD "crmId" character varying`);
await queryRunner.query(`ALTER TABLE "organization" ADD "telephoneNumber" character varying`);
await queryRunner.query(`ALTER TABLE "organization" ADD "isTransporter" boolean NOT NULL DEFAULT false`);
await queryRunner.query(`CREATE VIEW "inventory_based_on_receipt_item_view" AS SELECT "ri"."id" AS "receiptItemId" from someTableC`);
await queryRunner.query(`INSERT INTO "typeorm_metadata"("type", "schema", "name", "value") VALUES ($1, $2, $3, $4)`, ["VIEW","public","inventory_based_on_receipt_item_view",]);
// More similar queries...
}
public async down(queryRunner: QueryRunner): Promise<void> { ... }
}
Regardless of application changes, all viewEntities are dropped and recreated every time.
An issue arises as the
inventory_based_on_receipt_item_view
is created twice in the query, even though there should only be one entity with that name. Additionally, the three columns (crmId
, telephoneNumber
, isTransporter
) in the organization table are consistently dropped and recreated with identical details.
I am seeking alternative methods or packages to optimize my workflow when migrating database tables, as regenerating the migration file each time there are entity changes proves cumbersome. Is there a more efficient workaround or tool available to streamline this process?