Skip to content

Commit

Permalink
DataSync: fixed crash when the table name has a space
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Oct 24, 2024
1 parent a5bcb83 commit c37be20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions IHP/DataSync/ChangeNotifications.hs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ createNotificationFunction :: RLS.TableWithRLS -> PG.Query
createNotificationFunction table = [i|
DO $$
BEGIN
CREATE FUNCTION #{functionName}() RETURNS TRIGGER AS $BODY$
CREATE FUNCTION "#{functionName}"() RETURNS TRIGGER AS $BODY$
DECLARE
payload TEXT;
large_pg_notification_id UUID;
Expand Down Expand Up @@ -86,14 +86,14 @@ createNotificationFunction table = [i|
RETURN new;
END;
$BODY$ language plpgsql;
DROP TRIGGER IF EXISTS #{insertTriggerName} ON #{tableName};
DROP TRIGGER IF EXISTS #{updateTriggerName} ON #{tableName};
DROP TRIGGER IF EXISTS #{deleteTriggerName} ON #{tableName};
DROP TRIGGER IF EXISTS "#{insertTriggerName}" ON "#{tableName}";
DROP TRIGGER IF EXISTS "#{updateTriggerName}" ON "#{tableName}";
DROP TRIGGER IF EXISTS "#{deleteTriggerName}" ON "#{tableName}";


CREATE TRIGGER #{insertTriggerName} AFTER INSERT ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE #{functionName}();
CREATE TRIGGER #{updateTriggerName} AFTER UPDATE ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE #{functionName}();
CREATE TRIGGER #{deleteTriggerName} AFTER DELETE ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE #{functionName}();
CREATE TRIGGER "#{insertTriggerName}" AFTER INSERT ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE "#{functionName}"();
CREATE TRIGGER "#{updateTriggerName}" AFTER UPDATE ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE "#{functionName}"();
CREATE TRIGGER "#{deleteTriggerName}" AFTER DELETE ON "#{tableName}" FOR EACH ROW EXECUTE PROCEDURE "#{functionName}"();
EXCEPTION
WHEN duplicate_function THEN
null;
Expand Down
2 changes: 1 addition & 1 deletion IHP/DataSync/RowLevelSecurity.hs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ makeCachedEnsureRLSEnabled = do
-- >>> hasRLSEnabled "my_table"
-- True
hasRLSEnabled :: (?modelContext :: ModelContext) => Text -> IO Bool
hasRLSEnabled table = sqlQueryScalar "SELECT relrowsecurity FROM pg_class WHERE oid = ?::regclass" [table]
hasRLSEnabled table = sqlQueryScalar "SELECT relrowsecurity FROM pg_class WHERE oid = quote_ident(?)::regclass" [table]

-- | Can be constructed using 'ensureRLSEnabled'
--
Expand Down

0 comments on commit c37be20

Please sign in to comment.