diff --git a/src/Vervis/Migration.hs b/src/Vervis/Migration.hs index 3807cab..b78bc60 100644 --- a/src/Vervis/Migration.hs +++ b/src/Vervis/Migration.hs @@ -24,6 +24,7 @@ import Control.Exception import Control.Monad import Control.Monad.IO.Class import Control.Monad.Trans.Class (lift) +import Control.Monad.Trans.Except import Control.Monad.Trans.Maybe import Control.Monad.Trans.Reader (ReaderT, runReaderT) import Data.Aeson @@ -45,6 +46,7 @@ import Database.Persist import Database.Persist.BackendDataType (backendDataType, PersistDefault (..)) import Database.Persist.Migration import Database.Persist.Schema (SchemaT, Migration) +import Database.Persist.Schema.SQL import Database.Persist.Schema.Types hiding (Entity) import Database.Persist.Schema.PostgreSQL (schemaBackend) import Database.Persist.Sql (SqlBackend, toSqlKey, fromSqlKey) @@ -2707,6 +2709,12 @@ changes hLocal ctx = migrateDB :: (MonadSite m, SiteEnv m ~ App) => Host -> HashidsContext -> ReaderT SqlBackend m (Either Text (Int, Int)) -migrateDB hLocal ctx = - let f cs = fmap (, length cs) <$> runMigrations schemaBackend "" 1 cs - in f $ changes hLocal ctx +migrateDB hLocal ctx = runExceptT $ do + ExceptT $ flip runReaderT (schemaBackend, "") $ runExceptT $ do + foreigns <- lift findMisnamedForeigns + unless (null foreigns) $ + throwE $ T.intercalate " ; " (map displayMisnamedForeign foreigns) + + let migrations = changes hLocal ctx + (,length migrations) <$> + ExceptT (runMigrations schemaBackend "" 1 migrations)