diff --git a/IHP/IDE/CodeGen/MigrationGenerator.hs b/IHP/IDE/CodeGen/MigrationGenerator.hs index a6314f921..a83201eaf 100644 --- a/IHP/IDE/CodeGen/MigrationGenerator.hs +++ b/IHP/IDE/CodeGen/MigrationGenerator.hs @@ -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]) diff --git a/Test/IDE/CodeGeneration/MigrationGenerator.hs b/Test/IDE/CodeGeneration/MigrationGenerator.hs index e8a2aaa68..2ef9f2b1c 100644 --- a/Test/IDE/CodeGeneration/MigrationGenerator.hs +++ b/Test/IDE/CodeGeneration/MigrationGenerator.hs @@ -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