-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: resolve MySQL unique index check when bigNumberStrings is false
Part of fix for #2737
- Loading branch information
1 parent
d2fa245
commit f67ba15
Showing
4 changed files
with
71 additions
and
6 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
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,14 @@ | ||
import { Entity } from "../../../../src/decorator/entity/Entity"; | ||
import { Column } from "../../../../src/decorator/columns/Column"; | ||
import { PrimaryGeneratedColumn } from "../../../../src/decorator/columns/PrimaryGeneratedColumn"; | ||
@Entity() | ||
export class TestEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column({ type: "varchar", length: 100, nullable: true, unique: true }) | ||
unique_column: string; | ||
|
||
@Column({ type: "varchar", length: 100, nullable: true, unique: false }) | ||
nonunique_column: string; | ||
} |
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,43 @@ | ||
import {expect} from "chai"; | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../src/connection/Connection"; | ||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
|
||
describe.only("github issues > #2737 MySQLDriver findChangedColumns (fields: width, precision)", () => { | ||
let connections: Connection[]; | ||
|
||
before(async () => connections = await createTestingConnections({ | ||
dropSchema: false, | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
enabledDrivers: ["mysql", "aurora-data-api"], | ||
schemaCreate: false, | ||
cache: false, | ||
driverSpecific: { | ||
bigNumberStrings: false, | ||
}, | ||
})); | ||
|
||
beforeEach(() => reloadTestingDatabases(connections)); | ||
|
||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not create migrations for an existing unique index when bigNumberStrings is false", () => ( | ||
Promise.all(connections.map(async connection => { | ||
const entityMetadata = connection.entityMetadatas.find(x => x.name === "TestEntity"); | ||
const indexMetadata = entityMetadata!.indices.find(index => ( | ||
index.columns.some(column => column.propertyName === "unique_column"))); | ||
|
||
// Ensure the setup is correct | ||
expect(indexMetadata).to.exist; | ||
expect(indexMetadata!.isUnique).to.be.true; | ||
|
||
await connection.synchronize(false); | ||
|
||
const schemaBuilder = connection.driver.createSchemaBuilder(); | ||
const syncQueries = await schemaBuilder.log(); | ||
|
||
expect(syncQueries.downQueries).to.be.an("array").that.is.empty; | ||
expect(syncQueries.upQueries).to.be.an("array").that.is.empty; | ||
}) | ||
))); | ||
}); |