mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-12 04:08:29 +01:00
Enable running stackage-server-cron on an empty DB
It did run migrations, but ran them in the wrong spot.
This commit is contained in:
parent
96522f62ea
commit
6331131b68
@ -179,8 +179,9 @@ stackageServerCron StackageCronOptions {..} = do
|
||||
, pcCasaMaxPerRequest = defaultCasaMaxPerRequest
|
||||
, pcSnapshotLocation = defaultSnapshotLocation
|
||||
}
|
||||
currentHoogleVersionId <-
|
||||
runRIO logFunc $ getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
||||
currentHoogleVersionId <- runRIO logFunc $ do
|
||||
runStackageMigrations' pantryConfig
|
||||
getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
||||
let stackage =
|
||||
StackageCron
|
||||
{ scPantryConfig = pantryConfig
|
||||
|
||||
@ -23,6 +23,7 @@ module Stackage.Database.Schema
|
||||
, GetStackageDatabase(..)
|
||||
, withStackageDatabase
|
||||
, runStackageMigrations
|
||||
, runStackageMigrations'
|
||||
, getCurrentHoogleVersionId
|
||||
, getCurrentHoogleVersionIdWithPantryConfig
|
||||
-- * Tables
|
||||
@ -217,25 +218,33 @@ withStackageDatabase shouldLog dbs inner = do
|
||||
bracket (liftIO getPoolIO) (liftIO . destroyAllResources) $ \pool -> do
|
||||
inner (StackageDatabase (`runSqlPool` pool))
|
||||
|
||||
getSchema :: (HasLogFunc env, GetStackageDatabase env (RIO env)) => RIO env (Maybe Int)
|
||||
getSchema :: ReaderT SqlBackend (RIO RIO.LogFunc) (Maybe Int)
|
||||
getSchema =
|
||||
run $ do
|
||||
do
|
||||
eres <- tryAny (selectList [] [])
|
||||
lift $ logInfo $ "getSchema result: " <> displayShow eres
|
||||
case eres of
|
||||
Right [Entity _ (Schema v)] -> return $ Just v
|
||||
_ -> return Nothing
|
||||
|
||||
runStackageMigrations' :: PantryConfig -> RIO RIO.LogFunc () -- HasLogFunc env => PantryConfig -> RIO env ()
|
||||
runStackageMigrations' pantryConfig = do
|
||||
stackageDb <- getStackageDatabaseFromPantry pantryConfig
|
||||
runDatabase stackageDb stackageMigrations
|
||||
|
||||
|
||||
runStackageMigrations :: (HasLogFunc env, GetStackageDatabase env (RIO env)) => RIO env ()
|
||||
runStackageMigrations = do
|
||||
runStackageMigrations = run stackageMigrations
|
||||
|
||||
stackageMigrations :: ReaderT SqlBackend (RIO RIO.LogFunc) () -- ReaderT SqlBackend (RIO RIO.LogFunc) ()
|
||||
stackageMigrations = do
|
||||
runMigration Pantry.migrateAll
|
||||
runMigration migrateAll
|
||||
actualSchema <- getSchema
|
||||
run $ do
|
||||
runMigration Pantry.migrateAll
|
||||
runMigration migrateAll
|
||||
unless (actualSchema == Just currentSchema) $ do
|
||||
lift $
|
||||
logWarn $
|
||||
"Current schema does not match actual schema: " <>
|
||||
displayShow (actualSchema, currentSchema)
|
||||
deleteWhere ([] :: [Filter Schema])
|
||||
insert_ $ Schema currentSchema
|
||||
unless (actualSchema == Just currentSchema) $ do
|
||||
lift $
|
||||
logWarn $
|
||||
"Current schema does not match actual schema: " <>
|
||||
displayShow (actualSchema, currentSchema)
|
||||
deleteWhere ([] :: [Filter Schema])
|
||||
insert_ $ Schema currentSchema
|
||||
|
||||
Loading…
Reference in New Issue
Block a user