-
-
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: loading tables with fk in sqlite query runner (#9875)
Closes: #9266
- Loading branch information
Showing
3 changed files
with
49 additions
and
1 deletion.
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,33 @@ | ||
import { expect } from "chai" | ||
import "reflect-metadata" | ||
import { DataSource } from "../../../src/data-source/DataSource" | ||
import { | ||
closeTestingConnections, | ||
createTestingConnections, | ||
reloadTestingDatabases, | ||
} from "../../utils/test-utils" | ||
|
||
describe("github issues > #9266 queryRunner.getTable() fails if Foreign Key is set in target table", () => { | ||
let connections: DataSource[] | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
migrations: [__dirname + "/migrations/*{.js,.ts}"], | ||
enabledDrivers: ["sqlite", "better-sqlite3"], | ||
}) | ||
}) | ||
beforeEach(() => reloadTestingDatabases(connections)) | ||
after(() => closeTestingConnections(connections)) | ||
|
||
it("should be able to load tables", () => | ||
Promise.all( | ||
connections.map(async (connection) => { | ||
await connection.runMigrations() | ||
const queryRunner = connection.createQueryRunner() | ||
const tables = await queryRunner.getTables() | ||
const tableNames = tables.map((table) => table.name) | ||
expect(tableNames).to.include("author") | ||
expect(tableNames).to.include("post") | ||
await queryRunner.release() | ||
}), | ||
)) | ||
}) |
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 { MigrationInterface, QueryRunner } from "../../../../src" | ||
|
||
export class CreateDatabase implements MigrationInterface { | ||
name = "CreateDatabase1623518107000" | ||
async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`CREATE TABLE "author" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar NOT NULL)`, | ||
) | ||
await queryRunner.query( | ||
`CREATE TABLE "post" ("id" integer PRIMARY KEY AUTOINCREMENT NOT NULL, "text" varchar NOT NULL, "authorId" integer NOT NULL REFERENCES author(id) ON DELETE CASCADE ON UPDATE NO ACTION)`, | ||
) | ||
} | ||
|
||
async down(queryRunner: QueryRunner): Promise<void> {} | ||
} |