Commit 6f7ca47d authored by Nicolas Lenz's avatar Nicolas Lenz

Switch to PostgreSQL

parent 120faf1f
Pipeline #338 passed with stage
in 25 minutes and 23 seconds
......@@ -4,7 +4,8 @@ module Main where
import Import
import Auth
import Database.Persist.Sqlite
import Control.Monad.Logger (runStderrLoggingT)
import Database.Persist.Postgresql
main :: IO ()
main = do
......@@ -22,7 +23,10 @@ addUser name = do
hFlush stdout
pass <- withEcho False getLine
putChar '\n'
runSqlite "wms-server.sqlite3" $ Auth.addUser name pass
settings <- loadYamlSettings [configSettingsYml] [] useEnv
runStderrLoggingT $ withPostgresqlConn
(pgConnStr $ appDatabaseConf settings)
(runSqlConn $ Auth.addUser name pass)
putStrLn "User added."
withEcho :: Bool -> IO a -> IO a
......
......@@ -30,8 +30,8 @@ ip-from-header: "_env:YESOD_IP_FROM_HEADER:false"
database:
# See config/test-settings.yml for an override during tests
database: "_env:YESOD_SQLITE_DATABASE:wms-server.sqlite3"
poolsize: "_env:YESOD_SQLITE_POOLSIZE:10"
connstr: "_env:YESOD_PG_CONNSTR:postgresql://wms@localhost/wms"
poolsize: "_env:YESOD_PG_POOLSIZE:10"
copyright: Insert copyright statement here
#analytics: UA-YOURCODE
......@@ -13,7 +13,7 @@ dependencies:
- bytestring
- text
- persistent
- persistent-sqlite
- persistent-postgresql
- persistent-template
- template-haskell
- shakespeare
......
......@@ -21,8 +21,8 @@ module Application
) where
import Control.Monad.Logger (liftLoc, runLoggingT)
import Database.Persist.Sqlite (createSqlitePool, runSqlPool,
sqlDatabase, sqlPoolSize)
import Database.Persist.Postgresql (createPostgresqlPool, runSqlPool,
pgConnStr, pgPoolSize)
import Import
import Language.Haskell.TH.Syntax (qLocation)
import Network.Wai (Middleware)
......@@ -73,9 +73,9 @@ makeFoundation appSettings = do
logFunc = messageLoggerSource tempFoundation appLogger
-- Create the database connection pool
pool <- flip runLoggingT logFunc $ createSqlitePool
(sqlDatabase $ appDatabaseConf appSettings)
(sqlPoolSize $ appDatabaseConf appSettings)
pool <- flip runLoggingT logFunc $ createPostgresqlPool
(pgConnStr $ appDatabaseConf appSettings)
(pgPoolSize $ appDatabaseConf appSettings)
-- Perform database migration using our application's logging settings.
runLoggingT (runSqlPool (runMigration migrateAll) pool) logFunc
......
......@@ -16,7 +16,7 @@ import Data.Aeson (Result (..), fromJSON, withObject, (.!=),
(.:?))
import Data.FileEmbed (embedFile)
import Data.Yaml (decodeEither')
import Database.Persist.Sqlite (SqliteConf)
import Database.Persist.Postgresql (PostgresConf)
import Language.Haskell.TH.Syntax (Exp, Name, Q)
import Network.Wai.Handler.Warp (HostPreference)
import Yesod.Default.Config2 (applyEnvValue, configSettingsYml)
......@@ -29,7 +29,7 @@ import Yesod.Default.Util (WidgetFileSettings, widgetFileNoReload,
data AppSettings = AppSettings
{ appStaticDir :: String
-- ^ Directory from which to serve static files.
, appDatabaseConf :: SqliteConf
, appDatabaseConf :: PostgresConf
-- ^ Configuration settings for accessing the database.
, appRoot :: Maybe Text
-- ^ Base for all generated URLs. If @Nothing@, determined
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment