Skip to content

Commit

Permalink
Fixed Migration generator not normalizing index expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jan 13, 2022
1 parent 7509768 commit 85ed706
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -339,6 +339,7 @@ normalizeStatement StatementCreateTable { unsafeGetCreateTable = table } = State
normalizeStatement AddConstraint { tableName, constraint } = [ AddConstraint { tableName, constraint = normalizeConstraint constraint } ]
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 otherwise = [otherwise]

normalizeTable :: CreateTable -> (CreateTable, [Statement])
Expand Down
11 changes: 11 additions & 0 deletions Test/IDE/CodeGeneration/MigrationGenerator.hs
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,17 @@ tests = do

diffSchemas targetSchema actualSchema `shouldBe` []


it "should normalize index expressions" do
let targetSchema = sql [i|
CREATE INDEX users_email_index ON users (LOWER(email));
|]
let actualSchema = sql [i|
CREATE INDEX users_email_index ON public.users USING btree (lower(email));
|]

diffSchemas targetSchema actualSchema `shouldBe` []


sql :: Text -> [Statement]
sql code = case Megaparsec.runParser Parser.parseDDL "" code of
Expand Down

0 comments on commit 85ed706

Please sign in to comment.