From dbdd70d21ec6e9be4c1a1f95b85703076d7f1d62 Mon Sep 17 00:00:00 2001 From: Mona Mayrhofer Date: Mon, 18 Mar 2024 10:46:02 +0100 Subject: [PATCH] Fix small oversights Fix incomplete instances in QueryBuilderSpec with primaryKeyConditionForId Fix pk-columns in SchemaCompilerSpec to be unique and non-nullable for completeness --- Test/QueryBuilderSpec.hs | 2 ++ Test/SchemaCompilerSpec.hs | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/Test/QueryBuilderSpec.hs b/Test/QueryBuilderSpec.hs index a54a3f4dd..ee4c71688 100644 --- a/Test/QueryBuilderSpec.hs +++ b/Test/QueryBuilderSpec.hs @@ -74,6 +74,7 @@ type instance PrimaryKey "taggings" = UUID instance Table Tagging where columnNames = ["id", "post_id", "tag_id"] primaryKeyColumnNames = ["id"] + primaryKeyConditionForId (Id id) = [("id", toField id)] data CompositeTagging = CompositeTagging { postId :: UUID @@ -103,6 +104,7 @@ type instance PrimaryKey "users" = UUID instance Table User where columnNames = ["id", "name"] primaryKeyColumnNames = ["id"] + primaryKeyConditionForId (Id id) = [("id", toField id)] data FavoriteTitle = FavoriteTitle { diff --git a/Test/SchemaCompilerSpec.hs b/Test/SchemaCompilerSpec.hs index 54f1c704d..b0445e5fe 100644 --- a/Test/SchemaCompilerSpec.hs +++ b/Test/SchemaCompilerSpec.hs @@ -148,7 +148,7 @@ tests = do it "should compile CanUpdate instance with an array type with an explicit cast" do let statement = StatementCreateTable $ CreateTable { name = "users", - columns = [ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing], + columns = [ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing], primaryKeyConstraint = PrimaryKeyConstraint ["id"], constraints = [] , unlogged = False @@ -164,7 +164,7 @@ tests = do let statement = StatementCreateTable CreateTable { name = "users" , columns = - [ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing + [ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing , Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (TypeCastExpression (DoubleExpression 0.17) PDouble), notNull = True, isUnique = False, generator = Nothing} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] @@ -234,7 +234,7 @@ tests = do let statement = StatementCreateTable CreateTable { name = "users" , columns = - [ Column "id" PUUID Nothing False True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing + [ Column "id" PUUID Nothing True True Nothing, Column "ids" (PArray PUUID) Nothing False False Nothing , Column {name = "electricity_unit_price", columnType = PDouble, defaultValue = Just (IntExpression 0), notNull = True, isUnique = False, generator = Nothing} ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] @@ -304,7 +304,7 @@ tests = do let statement = StatementCreateTable CreateTable { name = "users" , columns = - [ Column "id" PUUID Nothing False True Nothing + [ Column "id" PUUID Nothing True True Nothing , Column {name = "ts", columnType = PTSVector, defaultValue = Nothing, notNull = True, isUnique = False, generator = Just (ColumnGenerator { generate = VarExpression "someResult", stored = False }) } ] , primaryKeyConstraint = PrimaryKeyConstraint ["id"] @@ -584,7 +584,7 @@ tests = do it "should compile FilterPrimaryKey instance when primary key is called id" do let statement = StatementCreateTable $ CreateTable { name = "things", - columns = [ Column "id" PUUID Nothing False False Nothing ], + columns = [ Column "id" PUUID Nothing True True Nothing ], primaryKeyConstraint = PrimaryKeyConstraint ["id"], constraints = [], unlogged = False