1717Source
1818 field3 Int
1919 field4 TargetId
20+
2021|]
2122
2223share [mkPersist sqlSettings, mkMigrate " migrationAddCol" , mkDeleteCascade sqlSettings] [persistLowerCase |
@@ -30,21 +31,43 @@ Source1 sql=source
3031 field3 Int
3132 extra Int
3233 field4 Target1Id
34+
3335|]
3436
35- specsWith :: (MonadIO m ) => RunDb SqlBackend m -> Spec
37+ share [mkPersist sqlSettings, mkMigrate " addPrimKey" , mkDeleteCascade sqlSettings] [persistLowerCase |
38+ FromRawMigration
39+ name T.Text
40+ age Int
41+
42+ Primary name
43+
44+ |]
45+
46+ specsWith :: (MonadIO m , MonadFail m ) => RunDb SqlBackend m -> Spec
3647specsWith runDb = describe " Migration" $ do
3748 it " is idempotent" $ runDb $ do
38- again <- getMigration migrationMigrate
39- liftIO $ again @?= []
40- it " really is idempotent" $ runDb $ do
41- runMigration migrationMigrate
42- again <- getMigration migrationMigrate
43- liftIO $ again @?= []
49+ _ <- runMigration migrateionMigrate
50+ again <- getMigration migrationMigrate
51+ liftIO $ again @?= []
4452 it " can add an extra column" $ runDb $ do
45- -- Failing test case for #735. Foreign-key checking, switched on in
46- -- version 2.6.1, caused persistent-sqlite to generate a `references`
47- -- constraint in a *temporary* table during migration, which fails.
48- _ <- runMigration migrationAddCol
49- again <- getMigration migrationAddCol
50- liftIO $ again @?= []
53+ -- Failing test case for #735. Foreign-key checking, switched on in
54+ -- version 2.6.1, caused persistent-sqlite to generate a `references`
55+ -- constraint in a *temporary* table during migration, which fails.
56+ _ <- runMigration migrationMigrate
57+ _ <- runMigration migrationAddCol
58+ again <- getMigration migrationAddCol
59+ liftIO $ again @?= []
60+ describe " Add Primary key constraint on raw table" $ do
61+ it " should not be considered safe" $ runDb $ do
62+ rawExecute " CREATE TABLE from_raw_migration (name VARCHAR NOT NULL, age INT8 NOT NULL)" []
63+ Right migration <- parseMigration addPrimKey
64+ liftIO $ migration
65+ `shouldSatisfy`
66+ (\ cm -> True `elem` map fst cm)
67+
68+ it " works" $ runDb $ do
69+ rawExecute " CREATE TABLE from_raw_migration (name VARCHAR NOT NULL, age INT NOT NULL)" []
70+ Right migration <- parseMigration addPrimKey
71+ () <- runMigration addPrimKey
72+ again <- getMigration addPrimKey
73+ liftIO $ again @?= []
0 commit comments