|
| 1 | +import "reflect-metadata"; |
| 2 | +import {Connection} from "../../../src"; |
| 3 | +import {closeTestingConnections, createTestingConnections} from "../../utils/test-utils"; |
| 4 | +import {TestEntity} from "./entity/Test"; |
| 5 | +import {ViewA} from "./entity/ViewA"; |
| 6 | +import {ViewB} from "./entity/ViewB"; |
| 7 | +import {ViewC} from "./entity/ViewC"; |
| 8 | + |
| 9 | +describe("github issues > #7586 Oddly indexed views are not dropped in migration", () => { |
| 10 | + let connections: Connection[]; |
| 11 | + before(async () => connections = await createTestingConnections({ |
| 12 | + enabledDrivers: ["postgres"], |
| 13 | + schemaCreate: true, |
| 14 | + dropSchema: true, |
| 15 | + entities: [TestEntity, ViewA, ViewB, ViewC], |
| 16 | + })); |
| 17 | + after(() => closeTestingConnections(connections)); |
| 18 | + |
| 19 | + it("should generate drop queries for all views", () => Promise.all(connections.map(async connection => { |
| 20 | + const expectedDrops: RegExp[] = []; |
| 21 | + for(const view of [ViewA, ViewB, ViewC]){ |
| 22 | + const metadata = connection.getMetadata(view); |
| 23 | + metadata.expression = (metadata.expression as string)?.replace('V1', 'V2') |
| 24 | + expectedDrops.push(new RegExp(`^DROP\\s+VIEW.*"${metadata.tableName}"`)) |
| 25 | + } |
| 26 | + const sqlInMemory = await connection.driver.createSchemaBuilder().log(); |
| 27 | + sqlInMemory.downQueries.filter(q => expectedDrops.find(expected => q.query.match(expected))).length.should.be.equal(expectedDrops.length); |
| 28 | + sqlInMemory.upQueries.filter(q => expectedDrops.find(expected => q.query.match(expected))).length.should.be.equal(expectedDrops.length); |
| 29 | + }))); |
| 30 | +}); |
0 commit comments