-
-
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: dropIndex now works when providing a tableIndex without name (#8937
- Loading branch information
Showing
12 changed files
with
119 additions
and
54 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
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,16 @@ | ||
import { Column, Entity, PrimaryColumn } from "../../../../src" | ||
|
||
@Entity() | ||
export class User { | ||
@PrimaryColumn({ nullable: false }) | ||
id: number | ||
|
||
@Column() | ||
firstName: string | ||
|
||
@Column() | ||
lastName: string | ||
|
||
@Column() | ||
github: 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,56 @@ | ||
import "../../utils/test-setup" | ||
import { | ||
QueryFailedError, | ||
QueryRunner, | ||
Repository, | ||
TableIndex, | ||
} from "../../../src" | ||
import { | ||
createTestingConnections, | ||
closeTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
import { Connection } from "../../../src/connection/Connection" | ||
import { User } from "./entity/User" | ||
|
||
describe("github issues > #8936 DropIndex with a TableIndex without name is not working", () => { | ||
let connections: Connection[] | ||
|
||
const tableIndex: TableIndex = new TableIndex({ | ||
columnNames: ["firstName", "lastName"], | ||
isUnique: true, | ||
}) | ||
|
||
before( | ||
async () => | ||
(connections = await createTestingConnections({ | ||
entities: [__dirname + "/entity/*{.js,.ts}"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
})), | ||
) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should drop the index as expected", () => { | ||
// Create a clone because the createIndex will set the name | ||
const dropTableIndex: TableIndex = tableIndex.clone() | ||
|
||
return Promise.all( | ||
connections.map(async (connection) => { | ||
const queryRunner: QueryRunner = connection.createQueryRunner() | ||
const userRepository: Repository<User> = | ||
connection.getRepository(User) | ||
const tableName: string = userRepository.metadata.tableName | ||
|
||
// Create the index so it exists when we delete it | ||
await queryRunner.createIndex(tableName, tableIndex) | ||
|
||
// Drop the index expecting it not to raise QueryFailed | ||
await queryRunner | ||
.dropIndex(tableName, dropTableIndex) | ||
.should.not.be.rejectedWith(QueryFailedError) | ||
}), | ||
) | ||
}) | ||
}) |