Skip to content

AutoSync runs before Migrations #346

@rightisleft

Description

@rightisleft

Autosync doesn't always work on type safe database like postgres.

I have a TEXT column that was supposed to be a Boolean.

(node:67913) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): error: column "isUnclear" cannot be cast automatically to type boolean

I wrote a migration:


import {Connection, EntityManager, MigrationInterface, QueryRunner} from "typeorm";

export class TransformIsUnclear1489444496065 implements MigrationInterface {
  
  public async up(queryRunner: QueryRunner, connection: Connection, entityManager?: EntityManager): Promise<any> {
    try {
      let query1 = `ALTER TABLE d_t_o_modifier ALTER COLUMN "isUnclear" DROP DEFAULT;`
      let query2 = `ALTER TABLE d_t_o_modifier ALTER "isUnclear" TYPE bool USING CASE WHEN "isUnclear" = 'false' THEN FALSE ELSE TRUE END;`
      let query3 = `ALTER TABLE d_t_o_modifier ALTER COLUMN "isUnclear" SET DEFAULT FALSE;`
      let responsea = await queryRunner.query(query1);
      let responseb = await queryRunner.query(query2);
      let responsec = await queryRunner.query(query3);
    } catch (e) {
      console.log(e);
      throw e;
    }
  }
  
  public async down(queryRunner: QueryRunner, connection: Connection, entityManager?: EntityManager): Promise<any> {
  }
 
}

But the AutoSync error still occurs before the migration is run.

Expected Behavior: AutoSync should run AFTER migrations so edge cases can be handled.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions