mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-20 05:51:54 +03:00
0922a3bb24
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/5451 GitOrigin-RevId: 8847af09a83293c619326d22209289397911bc5a
57 lines
1.7 KiB
Haskell
57 lines
1.7 KiB
Haskell
-- |
|
|
-- Tests to determine whether we can create tables with unique constraints.
|
|
--
|
|
-- https://hasura.io/docs/latest/guides/postgres/constraints/#unique-constraints
|
|
module Test.Postgres.UniqueConstraintsSpec (spec) where
|
|
|
|
import Data.List.NonEmpty qualified as NE
|
|
import Harness.Backend.Citus qualified as Citus
|
|
import Harness.Backend.Postgres qualified as Postgres
|
|
import Harness.Test.Fixture qualified as Fixture
|
|
import Harness.Test.Schema (Table (..), table)
|
|
import Harness.Test.Schema qualified as Schema
|
|
import Harness.TestEnvironment (TestEnvironment)
|
|
import Hasura.Prelude
|
|
import Test.Hspec (SpecWith, describe, it)
|
|
|
|
spec :: SpecWith TestEnvironment
|
|
spec = do
|
|
Fixture.run
|
|
( NE.fromList
|
|
[ (Fixture.fixture $ Fixture.Backend Fixture.Postgres)
|
|
{ Fixture.setupTeardown = \(testEnv, _) ->
|
|
[ Postgres.setupTablesAction schema testEnv
|
|
]
|
|
},
|
|
(Fixture.fixture $ Fixture.Backend Fixture.Citus)
|
|
{ Fixture.setupTeardown = \(testEnv, _) ->
|
|
[ Citus.setupTablesAction schema testEnv
|
|
]
|
|
}
|
|
]
|
|
)
|
|
tests
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Schema
|
|
|
|
schema :: [Table]
|
|
schema =
|
|
[ (table "test")
|
|
{ tableColumns =
|
|
[ Schema.column "id" Schema.TInt,
|
|
Schema.column "username" Schema.TStr
|
|
],
|
|
tableUniqueConstraints =
|
|
[ Schema.UniqueConstraintExpression "lower(username)"
|
|
]
|
|
}
|
|
]
|
|
|
|
--------------------------------------------------------------------------------
|
|
-- Tests
|
|
|
|
tests :: Fixture.Options -> SpecWith TestEnvironment
|
|
tests _ = describe "Unique constraints" do
|
|
it "Creates a schema with unique constraints" \_ -> pure @IO ()
|