Skip to content

User-defined index name for Single Table Inheritance discriminator columns #10496

@gabrielkim13

Description

@gabrielkim13

Feature Description

Allow the user to explicitly define the name of the index for the discriminator column of a Single Table Inheritance (STI) table.


Currently, TypeORM automatically generates an index for the discriminator column of a STI table.

Attempting to explicitly define an index for the discriminator column will result in 2 indices for the same column being created, which leads to a database error when the migration is run.

The Solution

Automatically detect whether the user is already defining the discriminator column index explicitly, on the EntityMetadataBuilder#createKeysForTableInheritance method.

If so, the method should do an early exit. Otherwise, automatically generate the index as it is currently done.

Considered Alternatives

Currently, there is no workaround for those who wish to have their databases synced with TypeORM's entities while specifying the name of the discriminator column index.

Additional Context

No response

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