Skip to content

Models with simple-enum column type will cause TypeORM to drop and recreate the table #6376

@hsharghi

Description

@hsharghi

Issue type:

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

Database system/driver:

[ ] cordova
[ ] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ x] sqlite
[ ] 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:
Create an entity with enum column type:

export enum Department {
    OFFICE = "office",
    WORKSHOP = "workshop",
}

@Entity('employees')
export class Employee {

    @PrimaryGeneratedColumn()
    id!: number;

    @Column({ nullable: true })
    employeeNumber?: string;

    @Column()
    name!: string;

    @Column({
      type: 'simple-enum',
      enum: Department,
    })
    department!: Department
}

enable logging in connection properties

{
...
  logging: 'all',
...
}

run the app, database and employees table will be created.
stop the app and re-run it.

in logs you can see

renaming column "department" in to "department"
platformTools.js:197 query: CREATE TABLE "temporary_employees" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "employeeNumber" varchar, "name" varchar NOT NULL, "department" varchar CHECK( department IN ('office','workshop') ) NOT NULL)
platformTools.js:197 query: INSERT INTO "temporary_employees"("id", "employeeNumber", "name", "department") SELECT "id", "employeeNumber", "name", "department" FROM "employees"
platformTools.js:197 query: DROP TABLE "employees"
platformTools.js:197 query: ALTER TABLE "temporary_employees" RENAME TO "employees"
platformTools.js:206 columns changed in "employees". updating: department
platformTools.js:197 query: CREATE TABLE "temporary_employees" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "employeeNumber" varchar, "name" varchar NOT NULL, "department" varchar CHECK( department IN ('office','workshop') ) NOT NULL)
platformTools.js:197 query: INSERT INTO "temporary_employees"("id", "employeeNumber", "name", "department") SELECT "id", "employeeNumber", "name", "department" FROM "employees"
platformTools.js:197 query: DROP TABLE "employees"
platformTools.js:197 query: ALTER TABLE "temporary_employees" RENAME TO "employees"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions