Skip to content

Incorrect enum default value when table name contains dash character #9684

@KhaledSMQ

Description

@KhaledSMQ

Issue description

typeorm not able to load proper default value of enum column type when the table name has a dash

Expected Behavior

While generating a migration script, if the enum column hasn't changed, Typeorm should not create any migration script for that enum column.

Actual Behavior

On every migration:generate typescript will recognize the enum default value changed and keep adding up, down scripts to drop enum default value and set again

Steps to reproduce

  1. Create a table with a name containing a dash like @Entity('module-payment_approval_requests')
  2. Create the first migration file. yarn typeorm --dataSource ./ds.ts migration:generate migrations/intial
  3. Try to run the migration again, yarn typeorm --dataSource ./ds.ts migration:generate migrations/update without any changes
import { BaseEntity, Column, Entity, PrimaryGeneratedColumn } from 'typeorm';

export enum ApprovalStatus {
  APPROVED = 'APPROVED',
  REJECTED = 'REJECTED',
  PENDING = 'PENDING',
}

@Entity('module-payment_approval_requests')
export class ApprovalRequests extends BaseEntity {
  @PrimaryGeneratedColumn('uuid')
  id: string;

  @Column({
    type: 'enum',
    enum: ApprovalStatus,
    default: ApprovalStatus.PENDING,
  })
  status: ApprovalStatus;
}

My Environment

Dependency Version
Operating System macOs 13.1 (22C65)
Node.js version v18.12.1
Typescript version 4.5.2
TypeORM version 0.3.11

Additional Context

The problem when trying to regex replace the table name from the default value

].replace(/::[\w\s\.\[\]\"]+/g, "")

parsing 'UNPAID'::module-payment_order_entity_enum results 'UNPAID'-payment_order_entity_enum" where is supposed to be only UNPAID

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, and I know how to start.

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