-
-
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.
- Loading branch information
1 parent
b91a725
commit 234d287
Showing
7 changed files
with
115 additions
and
5 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
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,15 @@ | ||
import {Index, PrimaryGeneratedColumn} from "../../../../src"; | ||
import {Column} from "../../../../src"; | ||
import {Entity} from "../../../../src"; | ||
|
||
@Index("name_index", ["name"]) | ||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryGeneratedColumn() | ||
id: number; | ||
|
||
@Column() | ||
name: 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,83 @@ | ||
import "reflect-metadata"; | ||
import {MysqlDriver} from "../../../src/driver/mysql/MysqlDriver"; | ||
import {PostgresDriver} from "../../../src/driver/postgres/PostgresDriver"; | ||
import {AbstractSqliteDriver} from "../../../src/driver/sqlite-abstract/AbstractSqliteDriver"; | ||
import {SqlServerDriver} from "../../../src/driver/sqlserver/SqlServerDriver"; | ||
import {createTestingConnections, closeTestingConnections, reloadTestingDatabases} from "../../utils/test-utils"; | ||
import {Connection, Table} from "../../../src"; | ||
|
||
describe("github issues > #3379 Migration will keep create and drop indexes if index name is the same across tables", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"] | ||
})); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should not recreate indices", () => Promise.all(connections.map(async connection => { | ||
|
||
const queryRunner = connection.createQueryRunner(); | ||
|
||
let postTableName: string = "post"; | ||
|
||
if (connection.driver instanceof SqlServerDriver) { | ||
postTableName = "testDB.testSchema.post"; | ||
await queryRunner.createDatabase("testDB", true); | ||
await queryRunner.createSchema("testDB.testSchema", true); | ||
|
||
} else if (connection.driver instanceof PostgresDriver) { | ||
postTableName = "testSchema.post"; | ||
await queryRunner.createSchema("testSchema", true); | ||
|
||
} else if (connection.driver instanceof MysqlDriver) { | ||
postTableName = "testDB.post"; | ||
await queryRunner.createDatabase("testDB", true); | ||
} | ||
|
||
await queryRunner.createTable(new Table({ | ||
name: postTableName, | ||
columns: [ | ||
{ | ||
name: "id", | ||
type: connection.driver instanceof AbstractSqliteDriver ? "integer" : "int", | ||
isPrimary: true, | ||
isGenerated: true, | ||
generationStrategy: "increment" | ||
}, | ||
{ | ||
name: "name", | ||
type: "varchar", | ||
} | ||
], | ||
indices: [{ name: "name_index", columnNames: ["name"] }] | ||
}), true); | ||
|
||
// Only MySQL and SQLServer allows non unique index names | ||
if (connection.driver instanceof MysqlDriver || connection.driver instanceof SqlServerDriver) { | ||
await queryRunner.createTable(new Table({ | ||
name: "category", | ||
columns: [ | ||
{ | ||
name: "id", | ||
type: "int", | ||
isPrimary: true, | ||
isGenerated: true, | ||
generationStrategy: "increment" | ||
}, | ||
{ | ||
name: "name", | ||
type: "varchar", | ||
} | ||
], | ||
indices: [{ name: "name_index", columnNames: ["name"] }] | ||
}), true); | ||
} | ||
|
||
await queryRunner.release(); | ||
|
||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
sqlInMemory.upQueries.length.should.be.equal(0); | ||
}))); | ||
|
||
}); |