-
-
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: Incorrect migration generated when multiple views are updated in…
… a single migration (#7587) * test: Add test for github issue 7586 * fix: Oddly indexed views are not dropped in migration (#7586) Co-authored-by: Svetlozar <ext-svetlozar@getitdone.co>
- Loading branch information
Showing
6 changed files
with
86 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,11 @@ | ||
import {Column, Entity, PrimaryGeneratedColumn} from "../../../../src"; | ||
|
||
|
||
@Entity() | ||
export class TestEntity { | ||
@PrimaryGeneratedColumn() | ||
id: number | ||
|
||
@Column("varchar") | ||
type: 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,14 @@ | ||
import {ViewColumn, ViewEntity} from "../../../../src"; | ||
|
||
@ViewEntity({ | ||
expression: ` | ||
select * from test_entity -- V1 simlate view change with comment | ||
` | ||
}) | ||
export class ViewA { | ||
@ViewColumn() | ||
id: number | ||
|
||
@ViewColumn() | ||
type: 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,14 @@ | ||
import {ViewColumn, ViewEntity} from "../../../../src"; | ||
|
||
@ViewEntity({ | ||
expression: ` | ||
select * from test_entity -- V1 simlate view change with comment | ||
` | ||
}) | ||
export class ViewB { | ||
@ViewColumn() | ||
id: number | ||
|
||
@ViewColumn() | ||
type: 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,14 @@ | ||
import {ViewColumn, ViewEntity} from "../../../../src"; | ||
|
||
@ViewEntity({ | ||
expression: ` | ||
select * from test_entity -- V1 simlate view change with comment | ||
` | ||
}) | ||
export class ViewC { | ||
@ViewColumn() | ||
id: number | ||
|
||
@ViewColumn() | ||
type: 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,30 @@ | ||
import "reflect-metadata"; | ||
import {Connection} from "../../../src"; | ||
import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils"; | ||
import {TestEntity} from "./entity/Test"; | ||
import {ViewA} from "./entity/ViewA"; | ||
import {ViewB} from "./entity/ViewB"; | ||
import {ViewC} from "./entity/ViewC"; | ||
|
||
describe("github issues > #7586 Oddly indexed views are not dropped in migration", () => { | ||
let connections: Connection[]; | ||
before(async () => connections = await createTestingConnections({ | ||
enabledDrivers: ["postgres"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
entities: [TestEntity, ViewA, ViewB, ViewC], | ||
})); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should generate drop queries for all views", () => Promise.all(connections.map(async connection => { | ||
const expectedDrops: RegExp[] = []; | ||
for(const view of [ViewA, ViewB, ViewC]){ | ||
const metadata = connection.getMetadata(view); | ||
metadata.expression = (metadata.expression as string)?.replace('V1', 'V2') | ||
expectedDrops.push(new RegExp(`^DROP\\s+VIEW.*"${metadata.tableName}"`)) | ||
} | ||
const sqlInMemory = await connection.driver.createSchemaBuilder().log(); | ||
sqlInMemory.downQueries.filter(q => expectedDrops.find(expected => q.query.match(expected))).length.should.be.equal(expectedDrops.length); | ||
sqlInMemory.upQueries.filter(q => expectedDrops.find(expected => q.query.match(expected))).length.should.be.equal(expectedDrops.length); | ||
}))); | ||
}); |