diff --git a/persistent-test/src/MigrationTest.hs b/persistent-test/src/MigrationTest.hs index 7ee8255e0..8a5fd0aa8 100644 --- a/persistent-test/src/MigrationTest.hs +++ b/persistent-test/src/MigrationTest.hs @@ -4,6 +4,7 @@ module MigrationTest where import Database.Persist.TH import qualified Data.Text as T +import Data.Time import Init @@ -36,6 +37,20 @@ Source1 sql=source field4 Target1Id |] +share [mkPersist sqlSettings, mkMigrate "migrationWithDefaultMaybeText"] [persistLowerCase| +TextMaybeDefault + field1 Int + field2 T.Text Maybe default=null + deriving Eq Show +|] + +share [mkPersist sqlSettings, mkMigrate "migrationWithDefaultTime"] [persistLowerCase| +TimeDefault + field3 Int + extra UTCTime default=current_timestamp + field4 Target1Id +|] + specsWith :: (MonadUnliftIO m) => RunDb SqlBackend m -> Spec specsWith runDb = describe "Migration" $ do it "is idempotent" $ runDb $ do @@ -53,3 +68,11 @@ specsWith runDb = describe "Migration" $ do void $ runMigrationSilent migrationAddCol again <- getMigration migrationAddCol liftIO $ again @?= [] + fit "is idempotent (default text example)" $ runDb $ do + void $ runMigrationSilent migrationWithDefaultMaybeText + again <- getMigration migrationWithDefaultMaybeText + liftIO $ again @?= ["ALTER TABLE \"text_maybe_default\" ALTER COLUMN \"field2\" SET DEFAULT null"] + fit "is idempotent (default time example)" $ runDb $ do + void $ runMigrationSilent migrationWithDefaultTime + again <- getMigration migrationWithDefaultTime + liftIO $ again @?= ["ALTER TABLE \"time_default\" ALTER COLUMN \"extra\" SET DEFAULT current_timestamp"]