From 7e808f05f5ed6041451522529cb9852ab26bee1c Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Mon, 20 Dec 2021 15:33:22 +0100 Subject: [PATCH] Fixed auto generated migration for a new enum value fails because SQL compiler branch is not implemented --- IHP/IDE/SchemaDesigner/Compiler.hs | 1 + Test/IDE/SchemaDesigner/CompilerSpec.hs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/IHP/IDE/SchemaDesigner/Compiler.hs b/IHP/IDE/SchemaDesigner/Compiler.hs index 8772ca284..e5463818d 100644 --- a/IHP/IDE/SchemaDesigner/Compiler.hs +++ b/IHP/IDE/SchemaDesigner/Compiler.hs @@ -46,6 +46,7 @@ compileStatement RenameTable { from, to } = "ALTER TABLE " <> compileIdentifier compileStatement DropPolicy { tableName, policyName } = "DROP POLICY " <> compileIdentifier policyName <> " ON " <> compileIdentifier tableName <> ";" compileStatement SetDefaultValue { tableName, columnName, value } = "ALTER TABLE " <> compileIdentifier tableName <> " ALTER COLUMN " <> compileIdentifier columnName <> " SET DEFAULT " <> compileExpression value <> ";" compileStatement DropDefaultValue { tableName, columnName } = "ALTER TABLE " <> compileIdentifier tableName <> " ALTER COLUMN " <> compileIdentifier columnName <> " DROP DEFAULT;" +compileStatement AddValueToEnumType { enumName, newValue } = "ALTER TYPE " <> compileIdentifier enumName <> " ADD VALUE " <> compileExpression (TextExpression newValue) <> ";" compileStatement UnknownStatement { raw } = raw <> ";" -- | Emit a PRIMARY KEY constraint when there are multiple primary key columns diff --git a/Test/IDE/SchemaDesigner/CompilerSpec.hs b/Test/IDE/SchemaDesigner/CompilerSpec.hs index f5f590510..7f92e1b0b 100644 --- a/Test/IDE/SchemaDesigner/CompilerSpec.hs +++ b/Test/IDE/SchemaDesigner/CompilerSpec.hs @@ -604,3 +604,8 @@ tests = do } ] compileSql statements `shouldBe` sql + + it "should compile 'ALTER TYPE .. ADD VALUE ..;' statements" do + let sql = "ALTER TYPE colors ADD VALUE 'blue';\n" + let statements = [ AddValueToEnumType { enumName = "colors", newValue = "blue" } ] + compileSql statements `shouldBe` sql