EquivalentTypeTestPostgres.hs 1.3 KB

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