-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Description
Issue type:
[ x ] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ x ] sqlite
[ x ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[ x ] latest
[ ] @next
[ ] 0.x.x (or put your version here)
Steps to reproduce or a small repository showing the problem:
Given the following entity:
@Entity()
export class Test {
@PrimaryColumn()
id: number;
@Column({ nullable: true, precision: 6 })
startedAt?: Date;
@Column({ type: 'decimal', precision: 5, scale: 2 })
value: number;
}Running a migration on a newly-synced SQLite/sql.js DB results in the following uneccessary migration commands:
[
{
query: 'CREATE TABLE "temporary_test" ("id" integer PRIMARY KEY NOT NULL, "startedAt" datetime(6), "value" decimal(5,2) NOT NULL)',
parameters: undefined
},
{
query: 'INSERT INTO "temporary_test"("id", "startedAt", "value") SELECT "id", "startedAt", "value" FROM "test"',
parameters: undefined
},
{query: 'DROP TABLE "test"', parameters: undefined},
{
query: 'ALTER TABLE "temporary_test" RENAME TO "test"',
parameters: undefined
}
]This is caused by a false positive in the findChangedColumns() method:
typeorm/src/driver/sqlite-abstract/AbstractSqliteDriver.ts
Lines 553 to 554 in d1ed572
| || tableColumn.precision !== columnMetadata.precision | |
| || tableColumn.scale !== columnMetadata.scale |
because the precision and scale arguments are not correctly inferred when reading the table. Then length property, however, is correctly inferred:
typeorm/src/driver/sqlite-abstract/AbstractSqliteQueryRunner.ts
Lines 829 to 839 in d1ed572
| let pos = tableColumn.type.indexOf("("); | |
| if (pos !== -1) { | |
| let dataType = tableColumn.type.substr(0, pos); | |
| if (!!this.driver.withLengthColumnTypes.find(col => col === dataType)) { | |
| let len = parseInt(tableColumn.type.substring(pos + 1, tableColumn.type.length - 1)); | |
| if (len) { | |
| tableColumn.length = len.toString(); | |
| tableColumn.type = dataType; // remove the length part from the datatype | |
| } | |
| } | |
| } |
All that is missing is to do the same for precision & scale.
I intend to submit a PR shortly.