-
-
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:
MATERIALIZED VIEW
is treated as a regular VIEW
which causes …
…issues on sync (#7592) * improved materialized view support in Postgres; * improved materialized view support in Oracle; * fixed falling test;
- Loading branch information
1 parent
3f2a02c
commit f85f436
Showing
7 changed files
with
212 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { View } from "../../../src/schema-builder/view/View"; | ||
import { expect } from "chai"; | ||
|
||
describe("query runner > create view", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [__dirname + "/view/*{.js,.ts}"], | ||
enabledDrivers: ["postgres", "oracle"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should correctly create VIEW and revert creation", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
const view = new View({ | ||
name: "new_post_view", | ||
expression: `SELECT * from "post"` | ||
}); | ||
await queryRunner.createView(view); | ||
|
||
let postView = await queryRunner.getView("new_post_view"); | ||
expect(postView).to.be.exist; | ||
|
||
await queryRunner.executeMemoryDownSql(); | ||
|
||
postView = await queryRunner.getView("new_post_view"); | ||
expect(postView).to.be.not.exist; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
|
||
it("should correctly create MATERIALIZED VIEW and revert creation", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
const view = new View({ | ||
name: "new_post_materialized_view", | ||
expression: `SELECT * from "post"`, | ||
materialized: true | ||
}); | ||
await queryRunner.createView(view); | ||
|
||
let postMatView = await queryRunner.getView("new_post_materialized_view"); | ||
expect(postMatView).to.be.exist; | ||
expect(postMatView!.materialized).to.be.true | ||
|
||
await queryRunner.executeMemoryDownSql(); | ||
|
||
postMatView = await queryRunner.getView("new_post_materialized_view"); | ||
expect(postMatView).to.be.not.exist; | ||
|
||
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,54 @@ | ||
import "reflect-metadata"; | ||
import { Connection } from "../../../src"; | ||
import { closeTestingConnections, createTestingConnections, reloadTestingDatabases } from "../../utils/test-utils"; | ||
import { expect } from "chai"; | ||
|
||
describe("query runner > drop view", () => { | ||
|
||
let connections: Connection[]; | ||
before(async () => { | ||
connections = await createTestingConnections({ | ||
entities: [__dirname + "/view/*{.js,.ts}"], | ||
enabledDrivers: ["postgres", "oracle"], | ||
schemaCreate: true, | ||
dropSchema: true, | ||
}); | ||
}); | ||
beforeEach(() => reloadTestingDatabases(connections)); | ||
after(() => closeTestingConnections(connections)); | ||
|
||
it("should correctly drop VIEW and revert dropping", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
let postView = await queryRunner.getView("post_view"); | ||
await queryRunner.dropView(postView!); | ||
|
||
postView = await queryRunner.getView("post_view"); | ||
expect(postView).to.be.not.exist; | ||
|
||
await queryRunner.executeMemoryDownSql(); | ||
|
||
postView = await queryRunner.getView("post_view"); | ||
expect(postView).to.be.exist; | ||
|
||
await queryRunner.release(); | ||
}))); | ||
|
||
it("should correctly drop MATERIALIZED VIEW and revert dropping", () => Promise.all(connections.map(async connection => { | ||
const queryRunner = connection.createQueryRunner(); | ||
|
||
let postMatView = await queryRunner.getView("post_materialized_view"); | ||
await queryRunner.dropView(postMatView!); | ||
|
||
postMatView = await queryRunner.getView("post_materialized_view"); | ||
expect(postMatView).to.be.not.exist; | ||
|
||
await queryRunner.executeMemoryDownSql(); | ||
|
||
postMatView = await queryRunner.getView("post_materialized_view"); | ||
expect(postMatView).to.be.exist; | ||
|
||
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,21 @@ | ||
import {Column, Entity, PrimaryColumn} from "../../../../src"; | ||
|
||
@Entity() | ||
export class Post { | ||
|
||
@PrimaryColumn() | ||
id: number; | ||
|
||
@Column({ unique: true }) | ||
version: number; | ||
|
||
@Column({ default: "My post" }) | ||
name: string; | ||
|
||
@Column() | ||
text: string; | ||
|
||
@Column() | ||
tag: 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,13 @@ | ||
import {ViewColumn, ViewEntity} from "../../../../src"; | ||
|
||
@ViewEntity({ | ||
expression: `SELECT * FROM "post"`, | ||
materialized: true, | ||
}) | ||
export class PostMaterializedView { | ||
@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,12 @@ | ||
import {ViewColumn, ViewEntity} from "../../../../src"; | ||
|
||
@ViewEntity({ | ||
expression: `SELECT * FROM "post"` | ||
}) | ||
export class PostView { | ||
@ViewColumn() | ||
id: number | ||
|
||
@ViewColumn() | ||
type: string; | ||
} |