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

Default of -1 (minus 1) generates useless migrations #5132

Closed
anodynos opened this issue Nov 22, 2019 · 0 comments · Fixed by #7681
Closed

Default of -1 (minus 1) generates useless migrations #5132

anodynos opened this issue Nov 22, 2019 · 0 comments · Fixed by #7681

Comments

@anodynos
Copy link

anodynos commented Nov 22, 2019

Issue 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:

[X] latest
[ ] @next
[X] 0.2.20 (or put your version here)

Steps to reproduce or a small repository showing the problem:

See repo at https://github.com/anodynos/typeorm-bug-migrations-default-minus-1
Execute ╰─$ scripts/migration-generate.sh to reproduce the issue.

Assuming an Entity :

@Entity('foo')
export class Foo {
  ...
  @Column({ default: 1, type: 'bigint' })
  bar_default_plus_1_is_fine: number;
  
  @Column({ default: -1, type: 'bigint' })
  bar_default_minus_1_is_creating_repeated_migrations: number;
}

after the initial migration is added, every time we generate a migration (without any schema changes), we get a new migration like:

...
    public async up(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "bar_default_minus_1_is_creating_repeated_migrations" SET DEFAULT -1`, undefined);
    }

    public async down(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "bar_default_minus_1_is_creating_repeated_migrations" SET DEFAULT '-1'`, undefined);
    }
...
kauz added a commit to kauz/typeorm that referenced this issue May 30, 2021
kauz added a commit to kauz/typeorm that referenced this issue May 30, 2021
kauz added a commit to kauz/typeorm that referenced this issue May 30, 2021
kauz added a commit to kauz/typeorm that referenced this issue May 30, 2021
kauz added a commit to kauz/typeorm that referenced this issue May 30, 2021
AlexMesser pushed a commit that referenced this issue May 30, 2021
…7681)

* fix: correctly strip type conversion in postgres for default values

Use better regex to remove only type conversion, not the whole string to the end

Closes: 7110

* fix: better regex

* fix: modify postgres default regex to not break #1532

* fix: modify postgres default regex to support user-defined types

This makes sure updated regex does not break migrations chnages introduced in #7647

* test: add test case for #5132
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants