-
Notifications
You must be signed in to change notification settings - Fork 302
Expand file tree
/
Copy pathMigrationTest.hs
More file actions
66 lines (57 loc) · 1.96 KB
/
MigrationTest.hs
File metadata and controls
66 lines (57 loc) · 1.96 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE UndecidableInstances #-}
module MigrationTest where
import Database.Persist.TH
import qualified Data.Text as T
import Init
share [mkPersist sqlSettings, mkMigrate "migrationMigrate"] [persistLowerCase|
Target
field1 Int
field2 T.Text
UniqueTarget field1 field2
deriving Eq Show
Source
field3 Int
field4 TargetId
CustomSqlId
pk Int sql=id
Primary pk
|]
share [mkPersist sqlSettings, mkMigrate "migrationAddCol"] [persistLowerCase|
Target1 sql=target
field1 Int
field2 T.Text
UniqueTarget1 field1 field2
deriving Eq Show
Source1 sql=source
field3 Int
extra Int
field4 Target1Id
|]
share [mkPersist sqlSettings, mkMigrate "migrationWithDefaultMaybeText"] [persistLowerCase|
TextMaybeDefault
field1 Int
field2 T.Text Maybe default=null
deriving Eq Show
|]
specsWith :: (MonadUnliftIO m) => RunDb SqlBackend m -> Spec
specsWith runDb = describe "Migration" $ do
it "is idempotent" $ runDb $ do
again <- getMigration migrationMigrate
liftIO $ again @?= []
it "really is idempotent" $ runDb $ do
void $ runMigrationSilent migrationMigrate
void $ runMigrationSilent migrationMigrate
again <- getMigration migrationMigrate
liftIO $ again @?= []
it "can add an extra column" $ runDb $ do
-- Failing test case for #735. Foreign-key checking, switched on in
-- version 2.6.1, caused persistent-sqlite to generate a `references`
-- constraint in a *temporary* table during migration, which fails.
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"]