Skip to content

Migration generation drops and creates columns instead of altering resulting in data loss #3357

@ryuuji3

Description

@ryuuji3

Issue type:

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

Database system/driver:

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

TypeORM version:

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

Steps to reproduce or a small repository showing the problem:

I apologize- I can't help but think I've seen a similar issue but I couldn't find it in opened or closed issues.

Let's say I have a varchar column with length of 50;

@Column({
   length: 50
})
public example: string;

Which results in this migration:

CREATE TABLE "bug" ("text" character varying(50))

And then I go ahead and change the length to 51;

@Column({
   length: 51
})
public example: string;

The resulting generated migration code is:

ALTER TABLE "bug" DROP COLUMN "example"
ALTER TABLE "bug" ADD "example" character varying(51)

Which obviously would result in data loss.
I would have expected;

ALTER TABLE "bug" ALTER COLUMN "example" character varying(51)

I did see something in #3352 which I think could be related? Although its for schema sync.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions