mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
fix: loading tables with fk in sqlite query runner (#9875)
Closes: #9266
This commit is contained in:
parent
0619aca174
commit
4997da054b
@ -1570,7 +1570,7 @@ export abstract class AbstractSqliteQueryRunner
|
||||
)
|
||||
|
||||
return new TableForeignKey({
|
||||
name: fkMapping!.name,
|
||||
name: fkMapping?.name,
|
||||
columnNames: columnNames,
|
||||
referencedTableName: foreignKey["table"],
|
||||
referencedColumnNames: referencedColumnNames,
|
||||
|
||||
33
test/github-issues/9266/issue-9266.ts
Normal file
33
test/github-issues/9266/issue-9266.ts
Normal file
@ -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()
|
||||
}),
|
||||
))
|
||||
})
|
||||
15
test/github-issues/9266/migrations/init.ts
Normal file
15
test/github-issues/9266/migrations/init.ts
Normal file
@ -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> {}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user