persistent-migration 0.2.1 → 0.3.0
raw patch · 7 files changed
+35/−25 lines, 7 files
Files
- CHANGELOG.md +6/−0
- persistent-migration.cabal +3/−3
- src/Database/Persist/Migration/Core.hs +12/−8
- src/Database/Persist/Migration/Postgres.hs +4/−3
- test/integration/Migration.hs +2/−0
- test/integration/Utils/Backends.hs +1/−1
- test/unit/Utils/Backends.hs +7/−10
CHANGELOG.md view
@@ -1,3 +1,9 @@+## persistent-migration 0.3.0++Fixes:+* Don't insert into `persistent_migration` table if no migrations are running ([#72](https://github.com/brandonchinn178/persistent-migration/pull/72))+* Fix `SERIAL` type for INT64 columns ([#79](https://github.com/brandonchinn178/persistent-migration/pull/79))+ ## persistent-migration 0.2.1 Fixes:
persistent-migration.cabal view
@@ -1,13 +1,13 @@ cabal-version: 1.18 --- This file has been generated from package.yaml by hpack version 0.33.0.+-- This file has been generated from package.yaml by hpack version 0.34.4. -- -- see: https://github.com/sol/hpack ----- hash: 719969a82682f1123ab4f973c7366736f3b3fa2ccc013f2c901a334894fc6408+-- hash: cc80da6911feb3f7cbe8f194c55aa3de1b4521d73ec516a4be6a2f8f2f8c4c50 name: persistent-migration-version: 0.2.1+version: 0.3.0 synopsis: Manual migrations for the persistent library description: Manual migrations for the persistent library. category: Database
src/Database/Persist/Migration/Core.hs view
@@ -146,14 +146,18 @@ -- | Run the given migration. After successful completion, saves the migration to the database. runMigration :: MonadIO m => MigrateBackend -> MigrateSettings -> Migration -> SqlPersistT m () runMigration backend settings@MigrateSettings{..} migration = do- getMigration backend settings migration >>= mapM_ executeSql- now <- liftIO getCurrentTime- let version = getLatestVersion migration- rawExecute "INSERT INTO persistent_migration(version, label, timestamp) VALUES (?, ?, ?)"- [ PersistInt64 $ fromIntegral version- , PersistText $ Text.pack $ fromMaybe (show version) $ versionToLabel version- , PersistUTCTime now- ]+ currVersion <- getCurrVersion backend+ let latestVersion = getLatestVersion migration+ case currVersion of+ Just current | current >= latestVersion -> pure ()+ _ -> do+ getMigration backend settings migration >>= mapM_ executeSql+ now <- liftIO getCurrentTime+ rawExecute "INSERT INTO persistent_migration(version, label, timestamp) VALUES (?, ?, ?)"+ [ PersistInt64 $ fromIntegral latestVersion+ , PersistText $ Text.pack $ fromMaybe (show latestVersion) $ versionToLabel latestVersion+ , PersistUTCTime now+ ] -- | Get the SQL queries for the given migration. getMigration :: MonadIO m
src/Database/Persist/Migration/Postgres.hs view
@@ -120,9 +120,10 @@ (\sqls -> Text.unwords $ [quote colName, sqlType] ++ sqls) $ map showColumnProp colProps where- sqlType = if AutoIncrement `elem` colProps- then "SERIAL"- else showSqlType colType+ sqlType = case (AutoIncrement `elem` colProps, colType) of+ (True, SqlInt32) -> "SERIAL"+ (True, SqlInt64) -> "BIGSERIAL"+ _ -> showSqlType colType -- | Show a 'SqlType'. See `showSqlType` from `Database.Persist.Postgresql`. showSqlType :: SqlType -> Text
test/integration/Migration.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE CPP #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE DerivingStrategies #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE MultiParamTypeClasses #-}
test/integration/Utils/Backends.hs view
@@ -47,7 +47,7 @@ let connString = ByteString.pack $ "postgresql:///test_db?host=" ++ dir' runNoLoggingT $ createPostgresqlPool connString 4 stopPostgres pool = do- callProcess' "pg_ctl" ["-D", dir', "stop"]+ callProcess' "pg_ctl" ["-D", dir', "stop", "-m", "fast"] destroyAllResources pool -- utilities callProcess' cmd args = do
test/unit/Utils/Backends.hs view
@@ -16,7 +16,9 @@ import qualified Data.Map as Map import Data.Maybe (maybeToList) import Database.Persist.Migration (Version)-import Database.Persist.Sql (PersistValue(..), SqlBackend(..), Statement(..))+import Database.Persist.Sql (PersistValue(..), Statement(..))+import Database.Persist.SqlBackend+ (MkSqlBackendArgs(..), SqlBackend, mkSqlBackend) import System.IO.Unsafe (unsafePerformIO) {- Mock test database -}@@ -45,7 +47,7 @@ withTestBackend :: (SqlBackend -> IO a) -> IO a withTestBackend action = do smap <- newIORef Map.empty- action SqlBackend+ action $ mkSqlBackend MkSqlBackendArgs { connPrepare = \case "SELECT version FROM persistent_migration ORDER BY timestamp DESC LIMIT 1" -> return stmt@@ -57,23 +59,18 @@ _ -> return stmt , connStmtMap = smap , connInsertSql = error "connInsertSql"- , connUpsertSql = error "connUpsertSql"- , connPutManySql = error "connPutManySql"- , connInsertManySql = error "connInsertManySql" , connClose = error "connClose" , connMigrateSql = error "connMigrateSql" , connBegin = error "connBegin" , connCommit = error "connCommit" , connRollback = error "connRollback"- , connEscapeName = error "connEscapeName"+ , connEscapeFieldName = error "connEscapeFieldName"+ , connEscapeTableName = error "connEscapeTableName"+ , connEscapeRawName = error "connEscapeRawName" , connNoLimit = error "connNoLimit" , connRDBMS = error "connRDBMS" , connLimitOffset = error "connLimitOffset" , connLogFunc = \_ _ _ _ -> return ()- , connMaxParams = error "connMaxParams"-#if MIN_VERSION_persistent(2, 9, 0)- , connRepsertManySql = error "connRepsertManySql"-#endif } where stmt = Statement