You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As you can see, the generated migration script has identical index names, even though the order of columns in the entity definition is different for the two indices. This is causing a conflict and potentially invalid database operations due to duplicate index names.
Expected Behavior
The migration script should generate unique index names based on the column order specified in the entity definition, ensuring proper creation and deletion of indices in the database
Actual Behavior
When running yarn migration:generate in a TypeORM project, the generated migration script creates duplicate index names despite the entity file specifying two distinct indices with different column orders.
Entity Definition
Here is the relevant part of the entity definition that specifies two different indices:
However, the generated migration script shows two identical index names, despite the indices being defined with different orders:
import { MigrationInterface, QueryRunner } from "typeorm";
export class CreateTables1714372786425 implements MigrationInterface {
name = "CreateTables1714372786425";
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(
`CREATE TABLE \`table_a\` (
\`a\` binary(20) NOT NULL,
\`b\` binary(20) NOT NULL,
\`bCrc\` int UNSIGNED NOT NULL,
\`aCrc\` int UNSIGNED NOT NULL,
\`c\` double UNSIGNED NOT NULL,
INDEX \`IDX_636863777022eb2cd64c5407f2\` (\`bCrc\`, \`aCrc\`, \`c\`),
INDEX \`IDX_636863777022eb2cd64c5407f2\` (\`aCrc\`, \`bCrc\`, \`c\`),
PRIMARY KEY (\`a\`, \`b\`))
ENGINE=InnoDB`
);
}
public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DROP INDEX \`IDX_636863777022eb2cd64c5407f2\` ON \`table_a\``);
await queryRunner.query(`DROP INDEX \`IDX_636863777022eb2cd64c5407f2\` ON \`table_a\``);
await queryRunner.query(`DROP TABLE \`table_a\``);
}
}
Steps to reproduce
Steps to Reproduce
To reproduce the issue of duplicate index names in TypeORM migrations, follow these steps:
Create a New TypeORM Project
Initialize a new TypeORM project with the necessary setup for migrations.
Ensure you have a valid database connection configured in ormconfig.json or a similar configuration file.
Create an Entity with Two Different Indices
Create an entity that has at least two index definitions with different column orders. Here is an example entity:
import{Column,Entity,Index,PrimaryColumn}from"typeorm";
@Entity()
@Index(["aCrc","bCrc","c"])// First index
@Index(["bCrc","aCrc","c"])// Second indexexportclassTableA{
@PrimaryColumn({type: "binary",length: 20})a: Buffer;
@PrimaryColumn({type: "binary",length: 20})b: Buffer;
@Column({type: "int",unsigned: true})bCrc: number;
@Column({type: "int",unsigned: true})aCrc: number;
@Column({type: "double",unsigned: true})c: number;}
Generate a Migration Script
Run the migration generation command, typically yarn migration:generate --name=CreateTableA.
This will generate a migration script that creates the table with the defined indices.
Inspect the Generated Migration Script
Open the generated migration script (e.g., src/migration/1633020286482-CreateTableA.ts).
Check the index definitions in the migration script to see if they have the same name despite being defined with different column orders in the entity.
If the above steps are followed, you should see that the generated migration script has duplicate index names, indicating the issue with the migration generation process in TypeORM. This behavior might lead to database conflicts or unexpected results when running the migrations.
My Environment
Dependency
Version
Operating System
MAC
Node.js version
20.12.0
Typescript version
5.1.3
TypeORM version
0.3.17
nestjs/typeorm
10.0.0
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, but I don't know how to start. I would need guidance.
The text was updated successfully, but these errors were encountered:
Issue description
As you can see, the generated migration script has identical index names, even though the order of columns in the entity definition is different for the two indices. This is causing a conflict and potentially invalid database operations due to duplicate index names.
Expected Behavior
The migration script should generate unique index names based on the column order specified in the entity definition, ensuring proper creation and deletion of indices in the database
Actual Behavior
When running yarn migration:generate in a TypeORM project, the generated migration script creates duplicate index names despite the entity file specifying two distinct indices with different column orders.
Entity Definition
Here is the relevant part of the entity definition that specifies two different indices:
Generated Migration Script
However, the generated migration script shows two identical index names, despite the indices being defined with different orders:
Steps to reproduce
Steps to Reproduce
To reproduce the issue of duplicate index names in TypeORM migrations, follow these steps:
Create a New TypeORM Project
ormconfig.json
or a similar configuration file.Create an Entity with Two Different Indices
Create an entity that has at least two index definitions with different column orders. Here is an example entity:
Generate a Migration Script
yarn migration:generate --name=CreateTableA
.Inspect the Generated Migration Script
src/migration/1633020286482-CreateTableA.ts
).If the above steps are followed, you should see that the generated migration script has duplicate index names, indicating the issue with the migration generation process in TypeORM. This behavior might lead to database conflicts or unexpected results when running the migrations.
My Environment
Additional Context
No response
Relevant Database Driver(s)
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.
The text was updated successfully, but these errors were encountered: