1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE DataKinds, FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wno-unused-top-binds #-}
module EquivalentTypeTestPostgres (specs) where
import Control.Monad.Trans.Resource (runResourceT)
import qualified Data.Text as T
import Database.Persist.TH
import PgInit
share [mkPersist sqlSettings, mkMigrate "migrateAll1"] [persistLowerCase|
EquivalentType sql=equivalent_types
field1 Int sqltype=bigint
field2 T.Text sqltype=text
field3 T.Text sqltype=us_postal_code
deriving Eq Show
|]
share [mkPersist sqlSettings, mkMigrate "migrateAll2"] [persistLowerCase|
EquivalentType2 sql=equivalent_types
field1 Int sqltype=int8
field2 T.Text
field3 T.Text sqltype=us_postal_code
deriving Eq Show
|]
specs :: Spec
specs = describe "doesn't migrate equivalent types" $ do
it "works" $ asIO $ runResourceT $ runConn $ do
_ <- rawExecute "DROP DOMAIN IF EXISTS us_postal_code CASCADE" []
_ <- rawExecute "CREATE DOMAIN us_postal_code AS TEXT CHECK(VALUE ~ '^\\d{5}$')" []
_ <- runMigrationSilent migrateAll1
xs <- getMigration migrateAll2
liftIO $ xs @?= []
|