-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: @unique constraint is not created with specified name
- Loading branch information
1 parent
8edc634
commit beea2e1
Showing
3 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn, Unique} from "../../../../src"; | ||
|
||
@Entity() | ||
@Unique(["age"]) | ||
@Unique("unique-email", ["email"]) | ||
@Unique("unique-email-nickname", ["email", "nickname"]) | ||
export class User { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
email: string; | ||
|
||
@Column() | ||
nickname: string; | ||
|
||
@Column() | ||
age: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../src"; | ||
import {createTestingConnections, closeTestingConnections} from "../../utils/test-utils"; | ||
import {User} from "./entity/User"; | ||
import {expect} from "chai"; | ||
import {MysqlDriver} from "../../../src/driver/mysql/MysqlDriver"; | ||
|
||
describe("github issues > #2376 Naming single column unique constraint with decorator not working as expected", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
schemaCreate: true, | ||
dropSchema: true, | ||
entities: [User], | ||
})); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should keep user-specified Unique constraint name", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
const table = await queryRunner.getTable("user"); | ||
await queryRunner.release() | ||
|
||
let unique1 = table!.uniques.find(it => it.name === "unique-email"); | ||
let unique2 = table!.uniques.find(it => it.name === "unique-email-nickname"); | ||
|
||
if (connection.driver instanceof MysqlDriver) { | ||
unique1 = table!.indices.find(it => it.name === "unique-email"); | ||
unique2 = table!.indices.find(it => it.name === "unique-email-nickname"); | ||
} | ||
|
||
expect(unique1).to.be.not.undefined | ||
expect(unique2).to.be.not.undefined | ||
|
||
}))); | ||
}); |