Skip to content

Commit

Permalink
improve schema watch revoke/grant
Browse files Browse the repository at this point in the history
  • Loading branch information
prostgles committed Feb 2, 2024
1 parent ee79eba commit cd0316a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 7 deletions.
7 changes: 4 additions & 3 deletions lib/DboBuilder/runSQL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ const onSQLResult = async function(this: DboBuilder, queryWithoutRLS: string, {
* Fallback for watchSchema in case of not a superuser (cannot add db event listener)
*/
export const watchSchemaFallback = async function(this: DboBuilder, { queryWithoutRLS, command }: { queryWithoutRLS: string; command: string; }){

const SCHEMA_ALTERING_COMMANDS = ["CREATE", "ALTER", "DROP", "REVOKE", "GRANT"];
const isNotPickedUpByDDLTrigger = ["REVOKE", "GRANT"].includes(command);
const { watchSchema, watchSchemaType } = this.prostgles?.opts || {};
if (
watchSchema &&
(!this.prostgles.isSuperUser || watchSchemaType === "prostgles_queries")
(!this.prostgles.isSuperUser || watchSchemaType === "prostgles_queries" || isNotPickedUpByDDLTrigger)
) {
if (["CREATE", "ALTER", "DROP", "REVOKE", "GRANT"].includes(command)) {
if (SCHEMA_ALTERING_COMMANDS.includes(command)) {
this.prostgles.onSchemaChange({ command, query: queryWithoutRLS })
} else if (queryWithoutRLS) {
const cleanedQuery = queryWithoutRLS.toLowerCase().replace(/\s\s+/g, ' ');
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "prostgles-server",
"version": "4.2.14",
"version": "4.2.15",
"description": "",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit cd0316a

Please sign in to comment.