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

postgres: Inappropiate migration generated for 'default: null' #6950

Closed
brahn opened this issue Oct 21, 2020 · 5 comments · Fixed by #7356
Closed

postgres: Inappropiate migration generated for 'default: null' #6950

brahn opened this issue Oct 21, 2020 · 5 comments · Fixed by #7356

Comments

@brahn
Copy link

brahn commented Oct 21, 2020

Issue type:

[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.28

Steps to reproduce or a small repository showing the problem:

This issue appears very similar to #5509 but for postgres.

Minimal entity declaration:

import { Entity, Column, PrimaryGeneratedColumn } from "typeorm";

@Entity()
export class Foo {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  requiredString: string;

  @Column({ type: "text", nullable: true })
  optionalString: string | null;

  @Column({ type: "text", nullable: true, default: null })
  optionalStringWithExplicitDefault: string | null;
}

Even after syncing the schema, generating a migration still results in the lines

// from `up` method
await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "optionalstringwithexplicitdefault" SET DEFAULT null`);

// in `down` method
await queryRunner.query(`ALTER TABLE "foo" ALTER COLUMN "optionalstringwithexplicitdefault" DROP DEFAULT`);

Expected behavior: the migration should not include these lines.

@vegerot
Copy link
Contributor

vegerot commented Oct 30, 2020

@brahn I have the same issue. Looking at #150 (comment) , it appears as a temporary workaround we can do

@Column({ type: "text", nullable: true, default: () => "NULL" })

Let me know if this works for you

@brahn
Copy link
Author

brahn commented Nov 2, 2020

@vegerot that doesn't seem to have changed anything for me -- thanks for the suggestion, though!

@vegerot
Copy link
Contributor

vegerot commented Nov 3, 2020

Sorry to hear that. Me neither. Hopefully we can get a response from a maintainer soon

@IAL32
Copy link

IAL32 commented Nov 14, 2020

Having the same weird behavior, same TypeORM setup and version.
Also using Postgres.

@vegerot
Copy link
Contributor

vegerot commented Jan 12, 2021

To be more specific, when you generate multiple new migrations, each time the case of null gets flipped.

For example, at first it will say

query: ALTER TABLE "air_refuels" ALTER COLUMN "missionId" SET DEFAULT null

then after I run that migration, and gen a new one, the next migration will say

query: ALTER TABLE "air_refuels" ALTER COLUMN "missionId" SET DEFAULT NULL

After you run the next migration, generating yet another migration produces

query: ALTER TABLE "air_refuels" ALTER COLUMN "missionId" SET DEFAULT null

I don't think @brahn noticed this when writing the issue.

This certainly seems like a TypeORM bug. Please let me know what I can do to help resolve it

vegerot added a commit to vegerot/typeorm that referenced this issue Jan 12, 2021
This commit adds tests to demonstrate the bug found in typeorm#6950
vegerot added a commit to vegerot/typeorm that referenced this issue Jan 12, 2021
This commit adds tests to demonstrate the bug found in typeorm#6950
@vegerot vegerot mentioned this issue Jan 12, 2021
7 tasks
AlexMesser pushed a commit that referenced this issue Feb 8, 2021
This commit adds tests to demonstrate the bug found in #6950
AlexMesser added a commit that referenced this issue Feb 8, 2021
AlexMesser added a commit that referenced this issue Feb 9, 2021
…ull #6950 (#7356)

* fix: #6950;

* removed single driver in test;

* fixed issues with column `comment` change detection;
removed `schema` from test due to SqlServer error;

* fixed `default` normalization in oracle;

* commented debug logs;

* removed log;
@thefat32 thefat32 mentioned this issue Apr 19, 2021
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.

4 participants