Skip to content

Commit

Permalink
Fixed migration generator detecting a difference between custom sql f…
Browse files Browse the repository at this point in the history
…unctions when the difference is only CREATE / CREATE OR REPLACE
  • Loading branch information
mpscholten committed Jan 13, 2022
1 parent 85ed706 commit f57f892
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions IHP/IDE/CodeGen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
22 changes: 22 additions & 0 deletions Test/IDE/CodeGeneration/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f57f892

Please sign in to comment.