Skip to content

Commit

Permalink
Refresh materialized view concurrently for PostgreSQL (#5166)
Browse files Browse the repository at this point in the history
  • Loading branch information
skwee357 committed May 8, 2022
1 parent 3eec52e commit e2516cd
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/dialects/postgres/schema/pg-compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ class SchemaCompiler_PG extends SchemaCompiler {
);
}

refreshMaterializedView(viewName) {
refreshMaterializedView(viewName, concurrently = false) {
this.pushQuery({
sql: `refresh materialized view ${this.formatter.wrap(viewName)}`,
sql: `refresh materialized view${concurrently ? " concurrently" : ""} ${this.formatter.wrap(viewName)}`,
});
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/schema-builder/postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,18 @@ describe('PostgreSQL SchemaBuilder', function () {
'refresh materialized view "view_to_refresh"'
);
});


it('refresh view concurrently', function () {
tableSql = client
.schemaBuilder()
.refreshMaterializedView('view_to_refresh', true)
.toSQL();
equal(1, tableSql.length);
expect(tableSql[0].sql).to.equal(
'refresh materialized view concurrently "view_to_refresh"'
);
});
});

it('drop table with schema', function () {
Expand Down
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ export declare namespace Knex {
viewName: string,
callback: (viewBuilder: ViewBuilder) => any
): SchemaBuilder;
refreshMaterializedView(viewName: string): SchemaBuilder;
refreshMaterializedView(viewName: string, concurrently?: boolean): SchemaBuilder;
dropView(viewName: string): SchemaBuilder;
dropViewIfExists(viewName: string): SchemaBuilder;
dropMaterializedView(viewName: string): SchemaBuilder;
Expand Down

0 comments on commit e2516cd

Please sign in to comment.