Don't overpopulate the Schema table

This commit is contained in:
Michael Snoyman 2018-12-19 08:55:09 +02:00
parent 4f91ac6c73
commit 40e551a6f2
No known key found for this signature in database
GPG Key ID: A048E8C057E86876

View File

@ -224,8 +224,7 @@ openStackageDatabase pg = liftIO $ do
getSchema :: PostgresConf -> IO (Maybe Int)
getSchema fp = do
StackageDatabase pool <- openStackageDatabase fp
eres <- tryAny $ runSqlPool (selectList [] []) pool
putStrLn $ "getSchema result: " ++ tshow eres
eres <- tryAny $ runSqlPool (selectList [] [Desc SchemaVal, LimitTo 1]) pool
case eres of
Right [Entity _ (Schema v)] -> return $ Just v
_ -> return Nothing
@ -241,7 +240,9 @@ createStackageDatabase fp = liftIO $ do
StackageDatabase pool <- openStackageDatabase fp
flip runSqlPool pool $ do
runMigration migrateAll
unless schemaMatch $ insert_ $ Schema currentSchema
unless schemaMatch $ do
deleteWhere ([] :: [Filter Schema])
insert_ $ Schema currentSchema
root <- liftIO $ (</> "database") <$> getAppUserDataDirectory "stackage"
createDirectoryIfMissing True root