Skip to content

Commit

Permalink
normalize newlines in sql functions before diffing for migration
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed May 5, 2022
1 parent 6891072 commit a3833fd
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion IHP/IDE/CodeGen/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ normalizeStatement AddConstraint { tableName, constraint, deferrable, deferrable
normalizeStatement CreateEnumType { name, values } = [ CreateEnumType { name = Text.toLower name, values = map Text.toLower values } ]
normalizeStatement CreatePolicy { name, action, tableName, using, check } = [ CreatePolicy { name, tableName, using = normalizeExpression <$> using, check = normalizeExpression <$> check, action = normalizePolicyAction action } ]
normalizeStatement CreateIndex { columns, indexType, .. } = [ CreateIndex { columns = map normalizeIndexColumn columns, indexType = normalizeIndexType indexType, .. } ]
normalizeStatement CreateFunction { .. } = [ CreateFunction { orReplace = False, language = Text.toUpper language, .. } ]
normalizeStatement CreateFunction { .. } = [ CreateFunction { orReplace = False, language = Text.toUpper language, functionBody = normalizeNewLines functionBody, .. } ]
normalizeStatement otherwise = [otherwise]

normalizePolicyAction (Just PolicyForAll) = Nothing
Expand Down Expand Up @@ -625,3 +625,9 @@ normalizeIndexColumn IndexColumn { column, columnOrder } =

normalizeIndexColumnOrder :: [IndexColumnOrder] -> [IndexColumnOrder]
normalizeIndexColumnOrder columnOrder = columnOrder |> filter (/=Asc)

normalizeNewLines :: Text -> Text
normalizeNewLines text =
text
|> Text.replace "\r\n" "\n"
|> Text.replace "\r" "\n"

0 comments on commit a3833fd

Please sign in to comment.