-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support upsert with empty updates #301
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,34 @@ import Common.Test | |
import Common.Test.Import hiding (from, on) | ||
import PostgreSQL.MigrateJSON | ||
|
||
spec :: Spec | ||
spec = beforeAll mkConnectionPool $ do | ||
tests | ||
|
||
describe "PostgreSQL specific tests" $ do | ||
testAscRandom random_ | ||
testRandomMath | ||
testSelectDistinctOn | ||
testPostgresModule | ||
testPostgresqlOneAscOneDesc | ||
testPostgresqlTwoAscFields | ||
testPostgresqlSum | ||
testPostgresqlRandom | ||
testPostgresqlUpdate | ||
testPostgresqlCoalesce | ||
testPostgresqlTextFunctions | ||
testInsertUniqueViolation | ||
testUpsert | ||
testInsertSelectWithConflict | ||
testFilterWhere | ||
testCommonTableExpressions | ||
setDatabaseState insertJsonValues cleanJSON | ||
$ describe "PostgreSQL JSON tests" $ do | ||
testJSONInsertions | ||
testJSONOperators | ||
testLateralQuery | ||
testValuesExpression | ||
|
||
returningType :: forall a m . m a -> m a | ||
returningType a = a | ||
|
||
|
@@ -1038,18 +1066,27 @@ testInsertUniqueViolation = | |
sqlErrorHint = ""} | ||
|
||
testUpsert :: SpecDb | ||
testUpsert = | ||
describe "Upsert test" $ do | ||
testUpsert = focus $ describe "Upsert test" $ do | ||
itDb "Upsert can insert like normal" $ do | ||
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u1e `shouldBe` u1 | ||
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u1e `shouldBe` u1 | ||
itDb "Upsert performs update on collision" $ do | ||
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u1e `shouldBe` u1 | ||
u2e <- EP.upsert u2 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u2e `shouldBe` u2 | ||
u3e <- EP.upsert u3 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u3e `shouldBe` u1{oneUniqueName="fifth"} | ||
u1e <- EP.upsert u1 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u1e `shouldBe` u1 | ||
u2e <- EP.upsert u2 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u2e `shouldBe` u2 | ||
u3e <- EP.upsert u3 [OneUniqueName =. val "fifth"] | ||
liftIO $ entityVal u3e `shouldBe` u1{oneUniqueName="fifth"} | ||
describe "With no updates" $ do | ||
itDb "Works with no updates" $ do | ||
_ <- EP.upsert u1 [] | ||
pure () | ||
Comment on lines
+1081
to
+1083
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, this passes. Hooray. |
||
itDb "Works with no updates, twice" $ do | ||
Entity u1Key u1' <- EP.upsert u1 [] | ||
Entity u1Key_ u1'' <- EP.upsert u1 { oneUniqueName = "Something Else" } [] | ||
pure () | ||
Comment on lines
+1084
to
+1087
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, this fails with The reason is that: INSERT INTO "OneUnique" (name, value)
VALUES (?, ?)
ON CONFLICT DO NOTHING
RETURNING id, name, value does not return anything if we don't perform an
|
||
-- liftIO $ do | ||
-- u1 `shouldBe` u1' | ||
|
||
testInsertSelectWithConflict :: SpecDb | ||
testInsertSelectWithConflict = | ||
|
@@ -1378,39 +1415,6 @@ selectJSON f = select $ from $ \v -> do | |
f $ just (v ^. JsonValue) | ||
return v | ||
|
||
--------------- JSON --------------- JSON --------------- JSON --------------- | ||
--------------- JSON --------------- JSON --------------- JSON --------------- | ||
--------------- JSON --------------- JSON --------------- JSON --------------- | ||
|
||
|
||
|
||
spec :: Spec | ||
spec = beforeAll mkConnectionPool $ do | ||
tests | ||
|
||
describe "PostgreSQL specific tests" $ do | ||
testAscRandom random_ | ||
testRandomMath | ||
testSelectDistinctOn | ||
testPostgresModule | ||
testPostgresqlOneAscOneDesc | ||
testPostgresqlTwoAscFields | ||
testPostgresqlSum | ||
testPostgresqlRandom | ||
testPostgresqlUpdate | ||
testPostgresqlCoalesce | ||
testPostgresqlTextFunctions | ||
testInsertUniqueViolation | ||
testUpsert | ||
testInsertSelectWithConflict | ||
testFilterWhere | ||
testCommonTableExpressions | ||
setDatabaseState insertJsonValues cleanJSON | ||
$ describe "PostgreSQL JSON tests" $ do | ||
testJSONInsertions | ||
testJSONOperators | ||
testLateralQuery | ||
testValuesExpression | ||
|
||
insertJsonValues :: SqlPersistT IO () | ||
insertJsonValues = do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,4 +19,3 @@ spec = do | |
sequential $ MySQL.spec | ||
describe "Postgresql" $ do | ||
sequential $ Postgres.spec | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is just moved up to the top