From f57f892ea051c4034d284e7d3834d3a23be07a72 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Thu, 13 Jan 2022 15:23:59 +0100 Subject: [PATCH] Fixed migration generator detecting a difference between custom sql functions when the difference is only CREATE / CREATE OR REPLACE --- IHP/IDE/CodeGen/MigrationGenerator.hs | 1 + Test/IDE/CodeGeneration/MigrationGenerator.hs | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/IHP/IDE/CodeGen/MigrationGenerator.hs b/IHP/IDE/CodeGen/MigrationGenerator.hs index a83201eaf..b3ceb05ef 100644 --- a/IHP/IDE/CodeGen/MigrationGenerator.hs +++ b/IHP/IDE/CodeGen/MigrationGenerator.hs @@ -340,6 +340,7 @@ normalizeStatement AddConstraint { tableName, constraint } = [ AddConstraint { t normalizeStatement CreateEnumType { name, values } = [ CreateEnumType { name = Text.toLower name, values = map Text.toLower values } ] normalizeStatement CreatePolicy { name, tableName, using, check } = [ CreatePolicy { name, tableName, using = normalizeExpression <$> using, check = normalizeExpression <$> check } ] normalizeStatement CreateIndex { expressions, .. } = [ CreateIndex { expressions = map normalizeExpression expressions, .. } ] +normalizeStatement CreateFunction { .. } = [ CreateFunction { orReplace = False, .. } ] normalizeStatement otherwise = [otherwise] normalizeTable :: CreateTable -> (CreateTable, [Statement]) diff --git a/Test/IDE/CodeGeneration/MigrationGenerator.hs b/Test/IDE/CodeGeneration/MigrationGenerator.hs index 2ef9f2b1c..02e4ed8e6 100644 --- a/Test/IDE/CodeGeneration/MigrationGenerator.hs +++ b/Test/IDE/CodeGeneration/MigrationGenerator.hs @@ -788,6 +788,28 @@ tests = do diffSchemas targetSchema actualSchema `shouldBe` [] + it "should not detect a difference between two functions when the only difference is between 'CREATE' and 'CREATE OR REPLACE'" do + let targetSchema = sql [i| + CREATE OR REPLACE FUNCTION notify_did_insert_webrtc_connection() RETURNS TRIGGER AS $$ + BEGIN + PERFORM pg_notify('did_insert_webrtc_connection', json_build_object('id', NEW.id, 'floor_id', NEW.floor_id, 'source_user_id', NEW.source_user_id, 'target_user_id', NEW.target_user_id)::text); + RETURN NEW; + END; + $$ language plpgsql; + |] + let actualSchema = sql [i| + CREATE FUNCTION public.notify_did_insert_webrtc_connection() RETURNS trigger + LANGUAGE plpgsql + AS $$ + BEGIN + PERFORM pg_notify('did_insert_webrtc_connection', json_build_object('id', NEW.id, 'floor_id', NEW.floor_id, 'source_user_id', NEW.source_user_id, 'target_user_id', NEW.target_user_id)::text); + RETURN NEW; + END; + $$; + |] + + diffSchemas targetSchema actualSchema `shouldBe` [] + sql :: Text -> [Statement] sql code = case Megaparsec.runParser Parser.parseDDL "" code of