Manually created constraint is dropped (and not recreated) by "typeorm migration:generate"
See original GitHub issueIssue type:
[ ] question [x] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[x] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ ] latest
[ ] @next
[x] 0.2.15
(or put your version here)
Steps to reproduce or a small repository showing the problem:
Here is first migration created by me manually (adding a constraint to a table - not index):
import { MigrationInterface, QueryRunner } from 'typeorm';
export class officeHoursNoOverlappingUserSessions1552041979708
implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query('create extension if not exists btree_gist');
await queryRunner.query(
`alter table office_hours add constraint no_overlapping_user_time_ranges EXCLUDE USING GIST (user_id WITH =, time_range WITH &&)`,
);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(
`alter table office_hours drop constraint no_overlapping_user_time_ranges`,
);
}
}
Next I added new value/option to one of enums and ran typeorm migration:generate
. Here is the result:
import {MigrationInterface, QueryRunner} from "typeorm";
export class test1554716327860 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`ALTER TABLE "office_hours" DROP CONSTRAINT "no_overlapping_user_time_ranges"`);
await queryRunner.query(`ALTER TYPE "exchange_whales_type_enum" RENAME TO "exchange_whales_type_enum_old"`);
await queryRunner.query(`CREATE TYPE "exchange_whales_type_enum" AS ENUM('limitOrder', 'marketOrder', 'abc')`);
await queryRunner.query(`ALTER TABLE "exchange_whales" ALTER COLUMN "type" TYPE "exchange_whales_type_enum" USING "type"::"text"::"exchange_whales_type_enum"`);
await queryRunner.query(`DROP TYPE "exchange_whales_type_enum_old"`);
}
public async down(queryRunner: QueryRunner): Promise<any> {
await queryRunner.query(`CREATE TYPE "exchange_whales_type_enum_old" AS ENUM('limitOrder', 'marketOrder')`);
await queryRunner.query(`ALTER TABLE "exchange_whales" ALTER COLUMN "type" TYPE "exchange_whales_type_enum_old" USING "type"::"text"::"exchange_whales_type_enum_old"`);
await queryRunner.query(`DROP TYPE "exchange_whales_type_enum"`);
await queryRunner.query(`ALTER TYPE "exchange_whales_type_enum_old" RENAME TO "exchange_whales_type_enum"`);
await queryRunner.query(`ALTER TABLE "office_hours" ADD CONSTRAINT "no_overlapping_user_time_ranges" EXCLUDE USING gist (user_id WITH =, time_range WITH &&)`);
}
}
As you can see migration commands regarding enum are correct, but for some reason typeorm drops constraint created manually in previous migration and it does not recreate it at the end of the migration:
await queryRunner.query(`ALTER TABLE "office_hours" DROP CONSTRAINT "no_overlapping_user_time_ranges"`);
Typeorm should not drop manually created constraint or it should drop it and recreate at the end of migration.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (3 by maintainers)
Top GitHub Comments
#3904 defferable has been implemented recently(isn’t published yet) But I think I get what you’re asking for - you want to have ability to not synchronize specific checks. I will add a discussion label - maybe someone comes up with a idea how to do it nicely(add
synhronize:false
to specyfic decorators options, implement constraint decorator etc.). There are few ways how to implement it, we should find the best one.In this case it could work but I have other constraints which make use of postgres specific statements, for example
deferrable initially deferred
and also indexes/constraints on expressions likelower(column)
.