Skip to content

Database schema is not updated by sync/migration when "simple-enum" is changed. #9715

@Vista1nik

Description

@Vista1nik

Issue description

When I modify enum in column with simple-enum type to include some new values, they do not appear in database schema after I run sync or create a new migration.

Expected Behavior

If values of enum in column with type simple-enum was changed, sync/migration must add changed values to CHECK( "column_name" IN ('enumvalue1','enumvalue2','enumvalue3','enumvalue4') ) constraint of column definition in database schema.

Actual Behavior

Sync/migration ignores fact that enum values was changed and does not update CHECK constraint to include new values.

Steps to reproduce

  1. Create an Entity with column that have simple-enum type.
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

export enum ExampleEnum {
    EnumValue1 = 'enumvalue1',
    EnumValue2 = 'enumvalue2',
    EnumValue3 = 'enumvalue3',
}

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

    @Column({
        type: 'simple-enum',
        enum: ExampleEnum,
    })
    enumcolumn: ExampleEnum;

    @Column()
    name: string;
}
  1. Execute sync:
npm run typeorm schema:sync
  1. Add new enum value:
import { Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

export enum ExampleEnum {
    EnumValue1 = 'enumvalue1',
    EnumValue2 = 'enumvalue2',
    EnumValue3 = 'enumvalue3',
+   EnumValue4 = 'enumvalue4',
}

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

    @Column({
        type: 'simple-enum',
        enum: ExampleEnum,
    })
    enumcolumn: ExampleEnum;

    @Column()
    name: string;
}
  1. Execute DB sync again:
npm run typeorm schema:sync
  1. See that CHECK( "enumcolumn" IN ('enumvalue1','enumvalue2','enumvalue3') ) constraint in column definition of database schema does not include addition of enumvalue4.

My Environment

Dependency Version
Operating System macOS
Node.js version 18.12.1
Typescript version 4.7.4
TypeORM version 0.3.11

Additional Context

Similar issue but with MS SQL Server: #9457

Relevant Database Driver(s)

  • aurora-mysql
  • aurora-postgres
  • better-sqlite3
  • cockroachdb
  • cordova
  • expo
  • mongodb
  • mysql
  • nativescript
  • oracle
  • postgres
  • react-native
  • sap
  • spanner
  • sqlite
  • sqlite-abstract
  • sqljs
  • sqlserver

Are you willing to resolve this issue by submitting a Pull Request?

Yes, I have the time, but I don't know how to start. I would need guidance.

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