@@ -18,6 +18,10 @@ Source
18
18
field3 Int
19
19
field4 TargetId
20
20
21
+ PreUnique sql=pre_unique
22
+ field5 Int
23
+ field6 T.Text
24
+
21
25
|]
22
26
23
27
share [mkPersist sqlSettings, mkMigrate " migrationAddCol" , mkDeleteCascade sqlSettings] [persistLowerCase |
@@ -40,11 +44,27 @@ FromRawMigration
40
44
age Int
41
45
42
46
Primary name
47
+ |]
48
+
49
+ share [mkPersist sqlSettings, mkMigrate " addUniqKey" , mkDeleteCascade sqlSettings] [persistLowerCase |
50
+
51
+ PostUnique sql=pre_unique
52
+ field5 Int
53
+ field6 T.Text
54
+
55
+ UniquField5 field5
43
56
44
57
|]
45
58
59
+ dropTables :: MonadIO m => SqlPersistT m ()
60
+ dropTables = do
61
+ rawExecute " DROP TABLE IF EXISTS source" []
62
+ rawExecute " DROP TABLE IF EXISTS target" []
63
+ rawExecute " DROP TABLE IF EXISTS pre_unique" []
64
+ rawExecute " DROP TABLE IF EXISTS from_raw_migration" []
65
+
46
66
specsWith :: (MonadIO m , MonadFail m ) => RunDb SqlBackend m -> Spec
47
- specsWith runDb = describe " Migration" $ do
67
+ specsWith runDb = describe " Migration" $ before_ (runDb dropTables) $ do
48
68
it " is idempotent" $ runDb $ do
49
69
_ <- runMigration migrationMigrate
50
70
again <- getMigration migrationMigrate
@@ -57,7 +77,15 @@ specsWith runDb = describe "Migration" $ do
57
77
_ <- runMigration migrationAddCol
58
78
again <- getMigration migrationAddCol
59
79
liftIO $ again @?= []
60
- describe " Add Primary key constraint on raw table" $ do
80
+ describe " Add Unique Key constraint" $ do
81
+ it " should not be considered safe" $ runDb $ do
82
+ _ <- runMigration migrationMigrate
83
+ Right migration <- parseMigration addUniqKey
84
+ liftIO $ migration
85
+ `shouldSatisfy`
86
+ (\ cm -> True `elem` map fst cm)
87
+
88
+ xdescribe " Add Primary key constraint on raw table" $ do
61
89
it " should not be considered safe" $ runDb $ do
62
90
rawExecute " CREATE TABLE from_raw_migration (name VARCHAR NOT NULL, age INT8 NOT NULL)" []
63
91
Right migration <- parseMigration addPrimKey
0 commit comments