From 540106bb24a84294a3828dd4a574682b343806b5 Mon Sep 17 00:00:00 2001 From: Marc Scholten Date: Sun, 5 Feb 2023 14:50:04 +0100 Subject: [PATCH] Added support for 'CREATE UNLOGGED TABLE' syntax in sql files --- IHP/IDE/SchemaDesigner/Compiler.hs | 2 +- IHP/IDE/SchemaDesigner/Parser.hs | 3 +- IHP/IDE/SchemaDesigner/SchemaOperations.hs | 1 + IHP/IDE/SchemaDesigner/Types.hs | 1 + .../IDE/CodeGeneration/ControllerGenerator.hs | 2 ++ Test/IDE/CodeGeneration/MailGenerator.hs | 1 + Test/IDE/CodeGeneration/ViewGenerator.hs | 1 + Test/IDE/SchemaDesigner/CompilerSpec.hs | 35 ++++++++++++++++--- .../SchemaDesigner/Controller/HelperSpec.hs | 4 +-- Test/IDE/SchemaDesigner/ParserSpec.hs | 34 ++++++++++++++---- .../SchemaDesigner/SchemaOperationsSpec.hs | 23 ++++++++++-- Test/SchemaCompilerSpec.hs | 7 +++- 12 files changed, 96 insertions(+), 18 deletions(-) diff --git a/IHP/IDE/SchemaDesigner/Compiler.hs b/IHP/IDE/SchemaDesigner/Compiler.hs index c562077eb..5235fc2ce 100644 --- a/IHP/IDE/SchemaDesigner/Compiler.hs +++ b/IHP/IDE/SchemaDesigner/Compiler.hs @@ -22,7 +22,7 @@ compileSql statements = statements |> unlines compileStatement :: Statement -> Text -compileStatement (StatementCreateTable CreateTable { name, columns, primaryKeyConstraint, constraints }) = "CREATE TABLE " <> compileIdentifier name <> " (\n" <> intercalate ",\n" (map (\col -> " " <> compileColumn primaryKeyConstraint col) columns <> maybe [] ((:[]) . indent) (compilePrimaryKeyConstraint primaryKeyConstraint) <> map (indent . compileConstraint) constraints) <> "\n);" +compileStatement (StatementCreateTable CreateTable { name, columns, primaryKeyConstraint, constraints, unlogged }) = "CREATE" <> (if unlogged then " UNLOGGED" else "") <> " TABLE " <> compileIdentifier name <> " (\n" <> intercalate ",\n" (map (\col -> " " <> compileColumn primaryKeyConstraint col) columns <> maybe [] ((:[]) . indent) (compilePrimaryKeyConstraint primaryKeyConstraint) <> map (indent . compileConstraint) constraints) <> "\n);" compileStatement CreateEnumType { name, values } = "CREATE TYPE " <> compileIdentifier name <> " AS ENUM (" <> intercalate ", " (values |> map TextExpression |> map compileExpression) <> ");" compileStatement CreateExtension { name, ifNotExists } = "CREATE EXTENSION " <> (if ifNotExists then "IF NOT EXISTS " else "") <> compileIdentifier name <> ";" compileStatement AddConstraint { tableName, constraint = UniqueConstraint { name = Nothing, columnNames } } = "ALTER TABLE " <> compileIdentifier tableName <> " ADD UNIQUE (" <> intercalate ", " columnNames <> ")" <> ";" diff --git a/IHP/IDE/SchemaDesigner/Parser.hs b/IHP/IDE/SchemaDesigner/Parser.hs index 3024e306f..d901e5bc8 100644 --- a/IHP/IDE/SchemaDesigner/Parser.hs +++ b/IHP/IDE/SchemaDesigner/Parser.hs @@ -88,6 +88,7 @@ createExtension = do createTable = do lexeme "CREATE" + unlogged <- isJust <$> optional (lexeme "UNLOGGED") lexeme "TABLE" name <- qualifiedIdentifier @@ -115,7 +116,7 @@ createTable = do _ -> Prelude.fail ("Primary key defined in both column and table constraints on table " <> cs name) _ -> Prelude.fail "Multiple columns with PRIMARY KEY constraint" - pure CreateTable { name, columns, primaryKeyConstraint, constraints } + pure CreateTable { name, columns, primaryKeyConstraint, constraints, unlogged } createEnumType = do lexeme "CREATE" diff --git a/IHP/IDE/SchemaDesigner/SchemaOperations.hs b/IHP/IDE/SchemaDesigner/SchemaOperations.hs index 93fdc964c..10bf06a60 100644 --- a/IHP/IDE/SchemaDesigner/SchemaOperations.hs +++ b/IHP/IDE/SchemaDesigner/SchemaOperations.hs @@ -29,6 +29,7 @@ addTable tableName list = list <> [StatementCreateTable CreateTable }] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False }] diff --git a/IHP/IDE/SchemaDesigner/Types.hs b/IHP/IDE/SchemaDesigner/Types.hs index 225ae2a8e..0a8dbca64 100644 --- a/IHP/IDE/SchemaDesigner/Types.hs +++ b/IHP/IDE/SchemaDesigner/Types.hs @@ -82,6 +82,7 @@ data CreateTable , columns :: [Column] , primaryKeyConstraint :: PrimaryKeyConstraint , constraints :: [Constraint] + , unlogged :: !Bool } deriving (Eq, Show) diff --git a/Test/IDE/CodeGeneration/ControllerGenerator.hs b/Test/IDE/CodeGeneration/ControllerGenerator.hs index 976bf7838..dc7c5d308 100644 --- a/Test/IDE/CodeGeneration/ControllerGenerator.hs +++ b/Test/IDE/CodeGeneration/ControllerGenerator.hs @@ -30,6 +30,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False }, StatementCreateTable CreateTable { name = "people" @@ -63,6 +64,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } ] it "should build a controller with name \"pages\"" do diff --git a/Test/IDE/CodeGeneration/MailGenerator.hs b/Test/IDE/CodeGeneration/MailGenerator.hs index 4e75ec615..cba2cd72d 100644 --- a/Test/IDE/CodeGeneration/MailGenerator.hs +++ b/Test/IDE/CodeGeneration/MailGenerator.hs @@ -31,6 +31,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } ] it "should build a mail with name \"PurchaseConfirmationMail\"" do diff --git a/Test/IDE/CodeGeneration/ViewGenerator.hs b/Test/IDE/CodeGeneration/ViewGenerator.hs index 5d84e3f2a..c229172f9 100644 --- a/Test/IDE/CodeGeneration/ViewGenerator.hs +++ b/Test/IDE/CodeGeneration/ViewGenerator.hs @@ -31,6 +31,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } ] it "should build a view with name \"EditView\"" do diff --git a/Test/IDE/SchemaDesigner/CompilerSpec.hs b/Test/IDE/SchemaDesigner/CompilerSpec.hs index 2486ee9b9..544e12ef5 100644 --- a/Test/IDE/SchemaDesigner/CompilerSpec.hs +++ b/Test/IDE/SchemaDesigner/CompilerSpec.hs @@ -15,7 +15,7 @@ import Test.IDE.SchemaDesigner.ParserSpec (col, parseSql) tests = do describe "The Schema.sql Compiler" do it "should compile an empty CREATE TABLE statement" do - compileSql [StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] }] `shouldBe` "CREATE TABLE users (\n\n);\n" + compileSql [StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False }] `shouldBe` "CREATE TABLE users (\n\n);\n" it "should compile a CREATE EXTENSION for the UUID extension" do compileSql [CreateExtension { name = "uuid-ossp", ifNotExists = True }] `shouldBe` "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";\n" @@ -108,11 +108,12 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql it "should compile a CREATE TABLE with quoted identifiers" do - compileSql [StatementCreateTable CreateTable { name = "quoted name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] }] `shouldBe` "CREATE TABLE \"quoted name\" (\n\n);\n" + compileSql [StatementCreateTable CreateTable { name = "quoted name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False }] `shouldBe` "CREATE TABLE \"quoted name\" (\n\n);\n" it "should compile ALTER TABLE .. ADD FOREIGN KEY .. ON DELETE CASCADE" do let statement = AddConstraint @@ -476,6 +477,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -527,6 +529,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -541,6 +544,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [ UniqueConstraint { name = Nothing, columnNames = [ "user_id", "follower_id" ] } ] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -551,6 +555,7 @@ tests = do , columns = [ col { name = "id", columnType = PSerial, notNull = True} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -561,6 +566,7 @@ tests = do , columns = [ col { name = "id", columnType = PBigserial, notNull = True} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -574,6 +580,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["order_id", "truck_id"] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -584,6 +591,7 @@ tests = do , columns = [ col { name = "pay_by_quarter", columnType = PArray PInt } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -594,6 +602,7 @@ tests = do , columns = [ col { name = "pos", columnType = PPoint } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -604,6 +613,7 @@ tests = do , columns = [ col { name = "poly", columnType = PPolygon } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } compileSql [statement] `shouldBe` sql @@ -777,12 +787,12 @@ tests = do it "should compile a decimal default value with a type-cast" do let sql = "CREATE TABLE a (\n electricity_unit_price DOUBLE PRECISION DEFAULT 0.17::DOUBLE PRECISION NOT NULL\n);\n" - let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } compileSql [statement] `shouldBe` sql it "should compile a integer default value" do let sql = "CREATE TABLE a (\n electricity_unit_price INT DEFAULT 0 NOT NULL\n);\n" - let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PInt, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PInt, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } compileSql [statement] `shouldBe` sql it "should compile a partial index" do @@ -1019,6 +1029,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } ] compileSql statements `shouldBe` sql @@ -1026,3 +1037,19 @@ tests = do let sql = "DROP FUNCTION my_function;\n" let statements = [ DropFunction { functionName = "my_function" } ] compileSql statements `shouldBe` sql + it "should compile 'CREATE UNLOGGED TABLE' statements" do + let sql = [trimming| + CREATE UNLOGGED TABLE pg_large_notifications ( + + ); + |] <> "\n" + let statements = [ + StatementCreateTable CreateTable + { name = "pg_large_notifications" + , columns = [] + , constraints = [] + , unlogged = True + , primaryKeyConstraint = PrimaryKeyConstraint [] + } + ] + compileSql statements `shouldBe` sql \ No newline at end of file diff --git a/Test/IDE/SchemaDesigner/Controller/HelperSpec.hs b/Test/IDE/SchemaDesigner/Controller/HelperSpec.hs index 943426d91..f9d9c05d0 100644 --- a/Test/IDE/SchemaDesigner/Controller/HelperSpec.hs +++ b/Test/IDE/SchemaDesigner/Controller/HelperSpec.hs @@ -14,14 +14,14 @@ tests = do getAllObjectNames [ CreateExtension { name ="a", ifNotExists = True } ] `shouldBe` [] getAllObjectNames [ CreateEnumType { name = "first_enum", values=["a", "b", "c"] }] `shouldBe` ["first_enum"] getAllObjectNames [ StatementCreateTable CreateTable - { name = "table_name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints=[]} + { name = "table_name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints=[], unlogged = False } ] `shouldBe` ["table_name"] getAllObjectNames [ CreateEnumType {name = "first_enum", values = ["a", "b"]} , CreateExtension {name = "extension", ifNotExists = True} , StatementCreateTable CreateTable - { name = "table_name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints=[]} + { name = "table_name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints=[], unlogged = False } , CreateEnumType {name = "second_enum", values = []} ] `shouldBe` ["first_enum","table_name","second_enum"] diff --git a/Test/IDE/SchemaDesigner/ParserSpec.hs b/Test/IDE/SchemaDesigner/ParserSpec.hs index 2ff8b8756..e7b558022 100644 --- a/Test/IDE/SchemaDesigner/ParserSpec.hs +++ b/Test/IDE/SchemaDesigner/ParserSpec.hs @@ -15,7 +15,7 @@ import GHC.IO (evaluate) tests = do describe "The Schema.sql Parser" do it "should parse an empty CREATE TABLE statement" do - parseSql "CREATE TABLE users ();" `shouldBe` StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + parseSql "CREATE TABLE users ();" `shouldBe` StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } it "should parse an CREATE EXTENSION for the UUID extension" do parseSql "CREATE EXTENSION IF NOT EXISTS \"uuid-ossp\";" `shouldBe` CreateExtension { name = "uuid-ossp", ifNotExists = True } @@ -113,6 +113,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with a generated column" do @@ -144,13 +145,14 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with quoted identifiers" do - parseSql "CREATE TABLE \"quoted name\" ();" `shouldBe` StatementCreateTable CreateTable { name = "quoted name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + parseSql "CREATE TABLE \"quoted name\" ();" `shouldBe` StatementCreateTable CreateTable { name = "quoted name", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } it "should parse a CREATE TABLE with public schema prefix" do - parseSql "CREATE TABLE public.users ();" `shouldBe` StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + parseSql "CREATE TABLE public.users ();" `shouldBe` StatementCreateTable CreateTable { name = "users", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } it "should parse ALTER TABLE .. ADD FOREIGN KEY .. ON DELETE CASCADE" do parseSql "ALTER TABLE users ADD CONSTRAINT users_ref_company_id FOREIGN KEY (company_id) REFERENCES companies (id) ON DELETE CASCADE;" `shouldBe` AddConstraint @@ -510,6 +512,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with TIMESTAMP WITH TIMEZONE / TIMESTAMPZ columns" do @@ -521,6 +524,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with BOOLEAN / BOOL columns" do @@ -532,6 +536,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with REAL, FLOAT4, DOUBLE, FLOAT8 columns" do @@ -545,6 +550,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE with (deprecated) NUMERIC, NUMERIC(x), NUMERIC (x,y), VARYING(n) columns" do @@ -558,6 +564,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE statement with a multi-column UNIQUE (a, b) constraint" do @@ -570,6 +577,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [ UniqueConstraint { name = Nothing, columnNames = [ "user_id", "follower_id" ] } ] + , unlogged = False } it "should fail to parse a CREATE TABLE statement with an empty UNIQUE () constraint" do @@ -585,6 +593,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [ "user_id", "follower_id" ] , constraints = [] + , unlogged = False } it "should fail to parse a CREATE TABLE statement with PRIMARY KEY column and table constraints" do @@ -601,6 +610,7 @@ tests = do , columns = [ col { name = "id", columnType = PSerial, notNull = True} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE statement with a bigserial id" do @@ -609,6 +619,7 @@ tests = do , columns = [ col { name = "id", columnType = PBigserial, notNull = True} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE statement with an array column" do @@ -617,6 +628,7 @@ tests = do , columns = [ col { name = "pay_by_quarter", columnType = PArray PInt } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE statement with a point column" do @@ -625,6 +637,7 @@ tests = do , columns = [ col { name = "pos", columnType = PPoint } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE TABLE statement with a polygon column" do @@ -633,6 +646,7 @@ tests = do , columns = [ col { name = "poly", columnType = PPolygon } ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } it "should parse a CREATE INDEX statement" do @@ -791,14 +805,14 @@ $$; it "should parse a decimal default value with a type-cast" do let sql = "CREATE TABLE a(electricity_unit_price DOUBLE PRECISION DEFAULT 0.17::double precision NOT NULL);" let statements = - [ StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + [ StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } ] parseSqlStatements sql `shouldBe` statements it "should parse a integer default value" do let sql = "CREATE TABLE a(electricity_unit_price INT DEFAULT 0 NOT NULL);" let statements = - [ StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PInt, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + [ StatementCreateTable CreateTable { name = "a", columns = [Column {name = "electricity_unit_price", columnType = PInt, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } ] parseSqlStatements sql `shouldBe` statements @@ -886,7 +900,7 @@ $$; let sql = cs [plain| CREATE TABLE a(id UUID DEFAULT public.uuid_generate_v4() NOT NULL); |] - let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "id", columnType = PUUID, defaultValue = Just (CallExpression "uuid_generate_v4" []), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + let statement = StatementCreateTable CreateTable { name = "a", columns = [Column {name = "id", columnType = PUUID, defaultValue = Just (CallExpression "uuid_generate_v4" []), notNull = True, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } parseSql sql `shouldBe` statement @@ -909,6 +923,7 @@ $$; ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } parseSql sql `shouldBe` statement @@ -931,6 +946,7 @@ $$; ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } parseSql sql `shouldBe` statement it "should parse a pg_dump header" do @@ -1118,7 +1134,11 @@ COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UU it "should parse 'CREATE TABLE ..' statements when the table name starts with public" do let sql = cs [plain|CREATE TABLE public_variables (id UUID);|] - parseSql sql `shouldBe` StatementCreateTable {unsafeGetCreateTable = CreateTable {name = "public_variables", columns = [Column {name = "id", columnType = PUUID, defaultValue = Nothing, notNull = False, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint {primaryKeyColumnNames = []}, constraints = []}} + parseSql sql `shouldBe` StatementCreateTable {unsafeGetCreateTable = CreateTable {name = "public_variables", columns = [Column {name = "id", columnType = PUUID, defaultValue = Nothing, notNull = False, isUnique = False, generator = Nothing}], primaryKeyConstraint = PrimaryKeyConstraint {primaryKeyColumnNames = []}, constraints = [], unlogged = False}} + + it "should parse an 'CREATE UNLOGGED TABLE' statement" do + parseSql "CREATE UNLOGGED TABLE pg_large_notifications ();" `shouldBe` StatementCreateTable CreateTable { name = "pg_large_notifications", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = True } + col :: Column col = Column diff --git a/Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs b/Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs index de9ed7c59..b4eff8b7b 100644 --- a/Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs +++ b/Test/IDE/SchemaDesigner/SchemaOperationsSpec.hs @@ -9,8 +9,8 @@ import qualified Text.Megaparsec as Megaparsec tests = do describe "IHP.IDE.SchemaDesigner.SchemaOperations" do - let tableA = StatementCreateTable CreateTable { name = "a", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } - let tableB = StatementCreateTable CreateTable { name = "b", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [] } + let tableA = StatementCreateTable CreateTable { name = "a", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } + let tableB = StatementCreateTable CreateTable { name = "b", columns = [], primaryKeyConstraint = PrimaryKeyConstraint [], constraints = [], unlogged = False } let enumA = CreateEnumType { name = "enumA", values = [] } let enumB = CreateEnumType { name = "enumB", values = [] } let comment = Comment { content = "comment" } @@ -111,6 +111,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let schema = [table] let expectedPolicy = CreatePolicy @@ -132,6 +133,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let schema = [table] let expectedPolicy = CreatePolicy @@ -152,6 +154,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let taskListsTable = StatementCreateTable CreateTable { name = "task_lists" @@ -160,6 +163,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let schema = [ tasksTable @@ -193,6 +197,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let index = CreateIndex { indexName = "a_created_at_index", unique = False, tableName = "a", columns = [IndexColumn { column = VarExpression "created_at", columnOrder = [] }], whereClause = Nothing, indexType = Nothing } @@ -232,6 +237,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let function = CreateFunction @@ -289,6 +295,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let index = CreateIndex @@ -349,6 +356,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let index = CreateIndex { indexName = "a_created_at_index", unique = False, tableName = "a", columns = [IndexColumn { column = VarExpression "created_at", columnOrder = [] }], whereClause = Nothing, indexType = Nothing } @@ -378,6 +386,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let function = CreateFunction @@ -425,6 +434,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let policy = CreatePolicy { name = "a_policy", tableName = "a", action = Nothing, using = Just (EqExpression (VarExpression "user_id") (CallExpression "ihp_user_id" [])), check = Nothing } @@ -454,6 +464,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let tableAWithUpdatedColumn = StatementCreateTable CreateTable @@ -470,6 +481,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let inputSchema = [tableAWithCreatedAt] @@ -503,6 +515,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } let tableWithoutPK = StatementCreateTable CreateTable @@ -519,6 +532,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let inputSchema = [tableWithoutPK] @@ -545,6 +559,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let taskListsTable = StatementCreateTable CreateTable { name = "task_lists" @@ -553,6 +568,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let inputSchema = [ tasksTable @@ -567,6 +583,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let expectedSchema = [ tasksTable' @@ -602,6 +619,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let index = CreateIndex { indexName = "a_updated_at_index", unique = False, tableName = "a", columns = [IndexColumn { column = VarExpression "updated_at", columnOrder = [] }], whereClause = Nothing, indexType = Nothing } @@ -619,6 +637,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] + , unlogged = False } let indexUpdated = CreateIndex { indexName = "a_created_at_index", unique = False, tableName = "a", columns = [IndexColumn { column = VarExpression "created_at", columnOrder = [] }], whereClause = Nothing, indexType = Nothing } diff --git a/Test/SchemaCompilerSpec.hs b/Test/SchemaCompilerSpec.hs index ccbecd532..57f4fce86 100644 --- a/Test/SchemaCompilerSpec.hs +++ b/Test/SchemaCompilerSpec.hs @@ -122,7 +122,8 @@ tests = do name = "users", columns = [ Column "id" PUUID Nothing False False Nothing ], primaryKeyConstraint = PrimaryKeyConstraint ["id"], - constraints = [] + constraints = [], + unlogged = False } let compileOutput = compileStatementPreview [statement] statement |> Text.strip @@ -149,6 +150,7 @@ tests = do columns = [ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing], primaryKeyConstraint = PrimaryKeyConstraint ["id"], constraints = [] + , unlogged = False } let compileOutput = compileStatementPreview [statement] statement |> Text.strip @@ -166,6 +168,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } let compileOutput = compileStatementPreview [statement] statement |> Text.strip @@ -225,6 +228,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } let compileOutput = compileStatementPreview [statement] statement |> Text.strip @@ -284,6 +288,7 @@ tests = do ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] , constraints = [] + , unlogged = False } let compileOutput = compileStatementPreview [statement] statement |> Text.strip