mirror of
https://github.com/commercialhaskell/stackage-server.git
synced 2026-02-08 09:07:27 +01:00
More talkative create, do not duplicate schema, vacuum
This commit is contained in:
parent
5b228f6e45
commit
7533b9b014
@ -66,6 +66,7 @@ currentSchema = 1
|
|||||||
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
|
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
|
||||||
Schema
|
Schema
|
||||||
val Int
|
val Int
|
||||||
|
deriving Show
|
||||||
Imported
|
Imported
|
||||||
name SnapName
|
name SnapName
|
||||||
type Text
|
type Text
|
||||||
@ -194,24 +195,30 @@ getSchema :: FilePath -> IO (Maybe Int)
|
|||||||
getSchema fp = do
|
getSchema fp = do
|
||||||
StackageDatabase pool <- openStackageDatabase fp
|
StackageDatabase pool <- openStackageDatabase fp
|
||||||
eres <- try $ runSqlPool (selectList [] []) pool
|
eres <- try $ runSqlPool (selectList [] []) pool
|
||||||
|
putStrLn $ "getSchema result: " ++ tshow eres
|
||||||
case eres :: Either SqliteException [Entity Schema] of
|
case eres :: Either SqliteException [Entity Schema] of
|
||||||
Right [Entity _ (Schema v)] -> return $ Just v
|
Right [Entity _ (Schema v)] -> return $ Just v
|
||||||
_ -> return Nothing
|
_ -> return Nothing
|
||||||
|
|
||||||
createStackageDatabase :: MonadIO m => FilePath -> m ()
|
createStackageDatabase :: MonadIO m => FilePath -> m ()
|
||||||
createStackageDatabase fp = liftIO $ do
|
createStackageDatabase fp = liftIO $ do
|
||||||
|
putStrLn "Entering createStackageDatabase"
|
||||||
actualSchema <- getSchema fp
|
actualSchema <- getSchema fp
|
||||||
when (actualSchema /= Just currentSchema)
|
let schemaMatch = actualSchema == Just currentSchema
|
||||||
$ void $ tryIO $ removeFile $ fpToString fp
|
unless schemaMatch $ do
|
||||||
|
putStrLn $ "Current schema does not match actual schema: " ++ tshow (actualSchema, currentSchema)
|
||||||
|
putStrLn $ "Deleting " ++ fpToText fp
|
||||||
|
void $ tryIO $ removeFile $ fpToString fp
|
||||||
|
|
||||||
StackageDatabase pool <- openStackageDatabase fp
|
StackageDatabase pool <- openStackageDatabase fp
|
||||||
putStrLn "Initial migration"
|
|
||||||
flip runSqlPool pool $ do
|
flip runSqlPool pool $ do
|
||||||
runMigration migrateAll
|
runMigration migrateAll
|
||||||
insert_ $ Schema currentSchema
|
unless schemaMatch $ insert_ $ Schema currentSchema
|
||||||
|
|
||||||
root <- liftIO $ fmap (</> "database") $ fmap fpFromString $ getAppUserDataDirectory "stackage"
|
root <- liftIO $ fmap (</> "database") $ fmap fpFromString $ getAppUserDataDirectory "stackage"
|
||||||
F.createTree root
|
F.createTree root
|
||||||
runResourceT $ do
|
runResourceT $ do
|
||||||
|
putStrLn "Updating all-cabal-metadata repo"
|
||||||
flip runSqlPool pool $ sourcePackages root $$ getZipSink
|
flip runSqlPool pool $ sourcePackages root $$ getZipSink
|
||||||
( ZipSink (mapM_C addPackage)
|
( ZipSink (mapM_C addPackage)
|
||||||
*> ZipSink (do
|
*> ZipSink (do
|
||||||
@ -219,6 +226,18 @@ createStackageDatabase fp = liftIO $ do
|
|||||||
lift $ do
|
lift $ do
|
||||||
deleteWhere ([] :: [Filter Deprecated])
|
deleteWhere ([] :: [Filter Deprecated])
|
||||||
mapM_ addDeprecated deprs)
|
mapM_ addDeprecated deprs)
|
||||||
|
*> ZipSink (
|
||||||
|
let loop i =
|
||||||
|
await >>= maybe (return ()) (const $ go $ i + 1)
|
||||||
|
go i = do
|
||||||
|
when (i `mod` 500 == 0)
|
||||||
|
$ putStrLn $ concat
|
||||||
|
[ "Processed "
|
||||||
|
, tshow i
|
||||||
|
, " packages"
|
||||||
|
]
|
||||||
|
loop i
|
||||||
|
in loop (0 :: Int))
|
||||||
)
|
)
|
||||||
sourceBuildPlans root $$ mapM_C (\(sname, fp', eval) -> flip runSqlPool pool $ do
|
sourceBuildPlans root $$ mapM_C (\(sname, fp', eval) -> flip runSqlPool pool $ do
|
||||||
let (typ, action) =
|
let (typ, action) =
|
||||||
@ -231,6 +250,7 @@ createStackageDatabase fp = liftIO $ do
|
|||||||
Left _ -> putStrLn $ "Skipping: " ++ fpToText fp'
|
Left _ -> putStrLn $ "Skipping: " ++ fpToText fp'
|
||||||
Right _ -> action
|
Right _ -> action
|
||||||
)
|
)
|
||||||
|
flip runSqlPool pool $ rawExecute "VACUUM" []
|
||||||
|
|
||||||
getDeprecated' :: [Deprecation] -> Tar.Entry -> [Deprecation]
|
getDeprecated' :: [Deprecation] -> Tar.Entry -> [Deprecation]
|
||||||
getDeprecated' orig e =
|
getDeprecated' orig e =
|
||||||
|
|||||||
@ -125,9 +125,8 @@ stackageServerCron = do
|
|||||||
Right _ -> putStrLn "Success"
|
Right _ -> putStrLn "Success"
|
||||||
|
|
||||||
let dbfp = fpFromText keyName
|
let dbfp = fpFromText keyName
|
||||||
_ <- return (upload, dbfp)
|
createStackageDatabase dbfp
|
||||||
--createStackageDatabase dbfp
|
upload dbfp keyName
|
||||||
--upload dbfp keyName
|
|
||||||
|
|
||||||
(db, _) <- loadFromS3
|
(db, _) <- loadFromS3
|
||||||
names <- runReaderT last5Lts5Nightly db
|
names <- runReaderT last5Lts5Nightly db
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user