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

Wrong migration created because of default column value format #5407

Closed
ValiDraganescu opened this issue Jan 23, 2020 · 0 comments · Fixed by #6879
Closed

Wrong migration created because of default column value format #5407

ValiDraganescu opened this issue Jan 23, 2020 · 0 comments · Fixed by #6879

Comments

@ValiDraganescu
Copy link

ValiDraganescu commented Jan 23, 2020

Issue type:

[ ] question
[x] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[x] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.22 (or put your version here)

Steps to reproduce or a small repository showing the problem:

I have the following entity

@Entity({
  name: "poi"
})
export class Poi {

  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  normalizedNameEn: string;

  @Column({
    type: "decimal",
    precision: 11,
    scale: 8,
    default: 0
  })
  lat: number;

  @Column({
    type: "decimal",
    precision: 11,
    scale: 8,
    default: 0
  })
  lon: number;

  @Column()
  isActivated: Boolean;
}

lat and lon ware wrongly defined as int previously so I updated to decimal

when I run migrate:generate I it creates a migration file that (amongst others) contains the following lines

await queryRunner.query("ALTER TABLE `poi` CHANGE `lat` `lat` decimal(11,8) NOT NULL DEFAULT 0", undefined);
await queryRunner.query("ALTER TABLE `poi` CHANGE `lon` `lon` decimal(11,8) NOT NULL DEFAULT 0", undefined);

after I run the migration and later generate a new one I always get the following

public async up(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query("ALTER TABLE `poi` CHANGE `lat` `lat` decimal(11,8) NOT NULL DEFAULT 0", undefined);
        await queryRunner.query("ALTER TABLE `poi` CHANGE `lon` `lon` decimal(11,8) NOT NULL DEFAULT 0", undefined);
    }

public async down(queryRunner: QueryRunner): Promise<any> {
        await queryRunner.query("ALTER TABLE `poi` CHANGE `lon` `lon` decimal(11,8) NOT NULL DEFAULT '0.00000000'", undefined);
        await queryRunner.query("ALTER TABLE `poi` CHANGE `lat` `lat` decimal(11,8) NOT NULL DEFAULT '0.00000000'", undefined);
    }

However, I did some tests and I found that if I define lat and lon with default '0.00000000' typeorm will report no changes (as it should)

jeiea added a commit to jeiea/typeorm that referenced this issue Oct 9, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 9, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 10, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 10, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 11, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 11, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 11, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
jeiea added a commit to jeiea/typeorm that referenced this issue Oct 11, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
imnotjames pushed a commit that referenced this issue Oct 11, 2020
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close #6140
Close #5407
zaro pushed a commit to zaro/typeorm that referenced this issue Jan 12, 2021
MySQL/MariaDB decimal column is represented like '0.0'.
MysqlDriver.normalizeDefault didn't consider trailing zeros.
User can bypass this by passing default as string, but we
can't guide the zeros by type, so we should convert user input.

undefined scale was compared with defined scale. Skip this comparison.

Close typeorm#6140
Close typeorm#5407
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