Skip to content

Use alternative ADD VALUE syntax when adding a new value to enum #10955

Closed

Description

@janzipek

Feature Description

When changing a new enum value is added TypeORM currently generates lengthy migration that:

  • renames the current enum type
  • creates new enum type with new values
  • changes the type of column to the new enum type casting values to string then to the target enum type
  • drops the now old enum type

This is a valid way to change enum type but it's pretty dangerous on big tables. The type change locks the whole table and the type casing basically causes update on the whole table which can take a while so as the result this migration can lock up big tables.

The Solution

PostgreSQL actually has a special syntax (since v12): https://www.postgresql.org/docs/12/sql-altertype.html

You can add new values to enum type by simply running:

ALTER TYPE name ADD VALUE 'value'

TypeORM could detect that the new enum only contains new values and use this alternative way which doesn't cause any locking and is instant even on big tables.

Considered Alternatives

Not many alternatives to this, the current implementation is correct.

Additional Context

I have PR ready, coming soon

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.

Activity

  1. added 4 commits that reference this issue on Jul 2, 2024
    80c6aaf
    8445cc2
    c167fc4
    8101f37
  2. github-actions commented on Sep 18, 2025

    @github-actions

    TypeORM has returned to active development after recently transitioning to new leadership (see related announcement).

    As part of the new team's efforts to prioritise work on the project moving forward, it is necessary to clean up the backlog of stale issues.

    🧹 This issue is being automatically closed because it has had no activity in the last 6 months.
    If you believe this issue is still relevant, feel free to comment below and the maintainers may reopen it. Thank you for your contribution.

  3. bmbferreira commented on Sep 19, 2025

    @bmbferreira

    this is still relevant and should not be closed

  4. reopened this on Sep 19, 2025
  5. added this to the 1.0 milestone on Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions