Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(postgres): postgres query runner to create materialized view #4877

Merged
merged 1 commit into from
Oct 18, 2019
Merged

fix(postgres): postgres query runner to create materialized view #4877

merged 1 commit into from
Oct 18, 2019

Conversation

JackCuthbert
Copy link
Contributor

@JackCuthbert JackCuthbert commented Oct 9, 2019

We've just started using a materialized view in our project (postgres DB) and noticed that the schema sync task during our tests was not creating a materialized version of the view when passing { materialized: true } in the entity definition.

Looks like a few things were missed in #4478:

  1. materialized SQL logic left out of PostgresQueryRunner.ts.
  2. materialized condition logic was backwards and always adding MATERIALIZED to the create view SQL
  3. The materialized option in the entity definition was always being set to false due to not being passed through
  4. Materialized views are not supported in cockroachdb so I've disabled the cockroach driver for the postgres test (this was causing tests to fail without a meaningful reason). I'm happy to add some boilerplate tests for cockroach but I'm not experienced with it so I'm not certain how much value I could add to that suite.

We're using my fork internally in production and the new materialized views are working great. Would be awesome to have someone take a look at this 😄

if (typeof view.expression === "string") {
return new Query(`CREATE VIEW ${this.escapePath(view)} AS ${view.expression}`);
return new Query(`CREATE ${materializedClause}VIEW "${view.name}" AS ${view.expression}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is the point of removing this.escapePath here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, didn't notice that! Will amend, good catch 😄

(I'll be honest, it was copy pasta from the previous PR 😉)

@pleerock
Copy link
Member

Not sure what you did in the last commit, but looks like its still not using this.escapePath

@JackCuthbert
Copy link
Contributor Author

@pleerock It’s pulled out to a const on line 1743 of the PostgresQueryRunner class as viewName.

@pleerock
Copy link
Member

pleerock commented Oct 18, 2019

oh okay. Let's merge it.

@pleerock pleerock merged commit d744966 into typeorm:master Oct 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants