@@ -15,7 +15,7 @@ import Test.IDE.SchemaDesigner.ParserSpec (col, parseSql)
1515tests = do
1616 describe " The Schema.sql Compiler" do
1717 it " should compile an empty CREATE TABLE statement" do
18- compileSql [StatementCreateTable CreateTable { name = " users" , columns = [] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] }] `shouldBe` " CREATE TABLE users (\n\n );\n "
18+ compileSql [StatementCreateTable CreateTable { name = " users" , columns = [] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] , unlogged = False }] `shouldBe` " CREATE TABLE users (\n\n );\n "
1919
2020 it " should compile a CREATE EXTENSION for the UUID extension" do
2121 compileSql [CreateExtension { name = " uuid-ossp" , ifNotExists = True }] `shouldBe` " CREATE EXTENSION IF NOT EXISTS \" uuid-ossp\" ;\n "
@@ -108,11 +108,12 @@ tests = do
108108 ]
109109 , primaryKeyConstraint = PrimaryKeyConstraint [" id" ]
110110 , constraints = []
111+ , unlogged = False
111112 }
112113 compileSql [statement] `shouldBe` sql
113114
114115 it " should compile a CREATE TABLE with quoted identifiers" do
115- compileSql [StatementCreateTable CreateTable { name = " quoted name" , columns = [] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] }] `shouldBe` " CREATE TABLE \" quoted name\" (\n\n );\n "
116+ compileSql [StatementCreateTable CreateTable { name = " quoted name" , columns = [] , primaryKeyConstraint = PrimaryKeyConstraint [] , constraints = [] , unlogged = False }] `shouldBe` " CREATE TABLE \" quoted name\" (\n\n );\n "
116117
117118 it " should compile ALTER TABLE .. ADD FOREIGN KEY .. ON DELETE CASCADE" do
118119 let statement = AddConstraint
@@ -476,6 +477,7 @@ tests = do
476477 ]
477478 , primaryKeyConstraint = PrimaryKeyConstraint []
478479 , constraints = []
480+ , unlogged = False
479481 }
480482 compileSql [statement] `shouldBe` sql
481483
@@ -527,6 +529,7 @@ tests = do
527529 ]
528530 , primaryKeyConstraint = PrimaryKeyConstraint []
529531 , constraints = []
532+ , unlogged = False
530533 }
531534 compileSql [statement] `shouldBe` sql
532535
@@ -541,6 +544,7 @@ tests = do
541544 ]
542545 , primaryKeyConstraint = PrimaryKeyConstraint [" id" ]
543546 , constraints = [ UniqueConstraint { name = Nothing , columnNames = [ " user_id" , " follower_id" ] } ]
547+ , unlogged = False
544548 }
545549 compileSql [statement] `shouldBe` sql
546550
@@ -551,6 +555,7 @@ tests = do
551555 , columns = [ col { name = " id" , columnType = PSerial , notNull = True } ]
552556 , primaryKeyConstraint = PrimaryKeyConstraint [" id" ]
553557 , constraints = []
558+ , unlogged = False
554559 }
555560 compileSql [statement] `shouldBe` sql
556561
@@ -561,6 +566,7 @@ tests = do
561566 , columns = [ col { name = " id" , columnType = PBigserial , notNull = True } ]
562567 , primaryKeyConstraint = PrimaryKeyConstraint [" id" ]
563568 , constraints = []
569+ , unlogged = False
564570 }
565571 compileSql [statement] `shouldBe` sql
566572
@@ -574,6 +580,7 @@ tests = do
574580 ]
575581 , primaryKeyConstraint = PrimaryKeyConstraint [" order_id" , " truck_id" ]
576582 , constraints = []
583+ , unlogged = False
577584 }
578585 compileSql [statement] `shouldBe` sql
579586
@@ -584,6 +591,7 @@ tests = do
584591 , columns = [ col { name = " pay_by_quarter" , columnType = PArray PInt } ]
585592 , primaryKeyConstraint = PrimaryKeyConstraint []
586593 , constraints = []
594+ , unlogged = False
587595 }
588596 compileSql [statement] `shouldBe` sql
589597
@@ -594,6 +602,7 @@ tests = do
594602 , columns = [ col { name = " pos" , columnType = PPoint } ]
595603 , primaryKeyConstraint = PrimaryKeyConstraint []
596604 , constraints = []
605+ , unlogged = False
597606 }
598607 compileSql [statement] `shouldBe` sql
599608
@@ -604,6 +613,7 @@ tests = do
604613 , columns = [ col { name = " poly" , columnType = PPolygon } ]
605614 , primaryKeyConstraint = PrimaryKeyConstraint []
606615 , constraints = []
616+ , unlogged = False
607617 }
608618 compileSql [statement] `shouldBe` sql
609619
@@ -777,12 +787,12 @@ tests = do
777787
778788 it " should compile a decimal default value with a type-cast" do
779789 let sql = " CREATE TABLE a (\n electricity_unit_price DOUBLE PRECISION DEFAULT 0.17::DOUBLE PRECISION NOT NULL\n );\n "
780- 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 = [] }
790+ 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 }
781791 compileSql [statement] `shouldBe` sql
782792
783793 it " should compile a integer default value" do
784794 let sql = " CREATE TABLE a (\n electricity_unit_price INT DEFAULT 0 NOT NULL\n );\n "
785- 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 = [] }
795+ 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 }
786796 compileSql [statement] `shouldBe` sql
787797
788798 it " should compile a partial index" do
@@ -1019,10 +1029,27 @@ tests = do
10191029 ]
10201030 , primaryKeyConstraint = PrimaryKeyConstraint []
10211031 , constraints = []
1032+ , unlogged = False
10221033 }
10231034 ]
10241035 compileSql statements `shouldBe` sql
10251036 it " should compile 'DROP FUNCTION ..;' statements" do
10261037 let sql = " DROP FUNCTION my_function;\n "
10271038 let statements = [ DropFunction { functionName = " my_function" } ]
10281039 compileSql statements `shouldBe` sql
1040+ it " should compile 'CREATE UNLOGGED TABLE' statements" do
1041+ let sql = [trimming |
1042+ CREATE UNLOGGED TABLE pg_large_notifications (
1043+
1044+ );
1045+ |] <> " \n "
1046+ let statements = [
1047+ StatementCreateTable CreateTable
1048+ { name = " pg_large_notifications"
1049+ , columns = []
1050+ , constraints = []
1051+ , unlogged = True
1052+ , primaryKeyConstraint = PrimaryKeyConstraint []
1053+ }
1054+ ]
1055+ compileSql statements `shouldBe` sql
0 commit comments