mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-01-28 11:50:24 +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
|
, pcCasaMaxPerRequest = defaultCasaMaxPerRequest
|
||||||
, pcSnapshotLocation = defaultSnapshotLocation
|
, pcSnapshotLocation = defaultSnapshotLocation
|
||||||
}
|
}
|
||||||
currentHoogleVersionId <-
|
currentHoogleVersionId <- runRIO logFunc $ do
|
||||||
runRIO logFunc $ getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
runStackageMigrations' pantryConfig
|
||||||
|
getCurrentHoogleVersionIdWithPantryConfig pantryConfig
|
||||||
let stackage =
|
let stackage =
|
||||||
StackageCron
|
StackageCron
|
||||||
{ scPantryConfig = pantryConfig
|
{ scPantryConfig = pantryConfig
|
||||||
|
|||||||
@ -23,6 +23,7 @@ module Stackage.Database.Schema
|
|||||||
, GetStackageDatabase(..)
|
, GetStackageDatabase(..)
|
||||||
, withStackageDatabase
|
, withStackageDatabase
|
||||||
, runStackageMigrations
|
, runStackageMigrations
|
||||||
|
, runStackageMigrations'
|
||||||
, getCurrentHoogleVersionId
|
, getCurrentHoogleVersionId
|
||||||
, getCurrentHoogleVersionIdWithPantryConfig
|
, getCurrentHoogleVersionIdWithPantryConfig
|
||||||
-- * Tables
|
-- * Tables
|
||||||
@ -217,25 +218,33 @@ withStackageDatabase shouldLog dbs inner = do
|
|||||||
bracket (liftIO getPoolIO) (liftIO . destroyAllResources) $ \pool -> do
|
bracket (liftIO getPoolIO) (liftIO . destroyAllResources) $ \pool -> do
|
||||||
inner (StackageDatabase (`runSqlPool` pool))
|
inner (StackageDatabase (`runSqlPool` pool))
|
||||||
|
|
||||||
getSchema :: (HasLogFunc env, GetStackageDatabase env (RIO env)) => RIO env (Maybe Int)
|
getSchema :: ReaderT SqlBackend (RIO RIO.LogFunc) (Maybe Int)
|
||||||
getSchema =
|
getSchema =
|
||||||
run $ do
|
do
|
||||||
eres <- tryAny (selectList [] [])
|
eres <- tryAny (selectList [] [])
|
||||||
lift $ logInfo $ "getSchema result: " <> displayShow eres
|
lift $ logInfo $ "getSchema result: " <> displayShow eres
|
||||||
case eres of
|
case eres of
|
||||||
Right [Entity _ (Schema v)] -> return $ Just v
|
Right [Entity _ (Schema v)] -> return $ Just v
|
||||||
_ -> return Nothing
|
_ -> 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 :: (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
|
actualSchema <- getSchema
|
||||||
run $ do
|
unless (actualSchema == Just currentSchema) $ do
|
||||||
runMigration Pantry.migrateAll
|
lift $
|
||||||
runMigration migrateAll
|
logWarn $
|
||||||
unless (actualSchema == Just currentSchema) $ do
|
"Current schema does not match actual schema: " <>
|
||||||
lift $
|
displayShow (actualSchema, currentSchema)
|
||||||
logWarn $
|
deleteWhere ([] :: [Filter Schema])
|
||||||
"Current schema does not match actual schema: " <>
|
insert_ $ Schema currentSchema
|
||||||
displayShow (actualSchema, currentSchema)
|
|
||||||
deleteWhere ([] :: [Filter Schema])
|
|
||||||
insert_ $ Schema currentSchema
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user