Merge branch 'master' of github.com:yesodweb/yesod
This commit is contained in:
commit
28cf60e6e7
@ -12,62 +12,61 @@
|
|||||||
#
|
#
|
||||||
# * Create an empty package.json
|
# * Create an empty package.json
|
||||||
# echo '{ "name": "~project~", "version": "0.0.1", "dependencies": {} }' >> package.json
|
# echo '{ "name": "~project~", "version": "0.0.1", "dependencies": {} }' >> package.json
|
||||||
#
|
#
|
||||||
# Postgresql Yesod setup:
|
# Postgresql Yesod setup:
|
||||||
#
|
#
|
||||||
# * add code to read the DATABASE_URL environment variable.
|
|
||||||
#
|
|
||||||
# import System.Environment
|
|
||||||
# main = do
|
|
||||||
# # parse env variable
|
|
||||||
# durl <- getEnv "DATABASE_URL"
|
|
||||||
# # pass settings to withConnectionPool instead of directly using loadConnStr
|
|
||||||
# defaultMain (fromArgsExtra loadExtra) withYesodHeroku
|
|
||||||
#
|
|
||||||
# * add a dependency on the "heroku" package in your cabal file
|
# * add a dependency on the "heroku" package in your cabal file
|
||||||
#
|
|
||||||
# * add code in Application.hs to turn the url into connection parameters. The below works for Postgresql.
|
|
||||||
#
|
#
|
||||||
# #ifdef !DEVELOPMENT
|
# * add code in Application.hs to use the heroku package and load the connection parameters.
|
||||||
# import qualified Web.Heroku
|
# The below works for Postgresql.
|
||||||
# #endif
|
#
|
||||||
|
# #if !DEVELOPMENT
|
||||||
|
# import qualified Web.Heroku
|
||||||
|
# #endif
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# canonicalizeKey :: (Text, val) -> (Text, val)
|
# getApplication :: AppConfig DefaultEnv Extra -> Logger -> IO Application
|
||||||
# canonicalizeKey ("dbname", val) = ("database", val)
|
# getApplication conf logger = do
|
||||||
# canonicalizeKey pair = pair
|
# manager <- newManager def
|
||||||
|
# s <- staticSite
|
||||||
|
# hconfig <- loadHerokuConfig
|
||||||
|
# dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv conf)
|
||||||
|
# (Database.Persist.Store.loadConfig . combineMappings hconfig) >>=
|
||||||
|
# Database.Persist.Store.applyEnv
|
||||||
|
# p <- Database.Persist.Store.createPoolConfig (dbconf :: Settings.PersistConfig)
|
||||||
|
# Database.Persist.Store.runPool dbconf (runMigration migrateAll) p
|
||||||
|
# let foundation = ~sitearg~ conf setLogger s p manager dbconf
|
||||||
|
# app <- toWaiAppPlain foundation
|
||||||
|
# return $ logWare app
|
||||||
|
# where
|
||||||
|
##ifdef DEVELOPMENT
|
||||||
|
# logWare = logCallbackDev (logBS setLogger)
|
||||||
|
# setLogger = logger
|
||||||
|
##else
|
||||||
|
# setLogger = toProduction logger -- by default the logger is set for development
|
||||||
|
# logWare = logCallback (logBS setLogger)
|
||||||
|
##endif
|
||||||
#
|
#
|
||||||
# toMapping :: [(key, val)] -> DO.Object key val
|
# #if !DEVELOPMENT
|
||||||
# toMapping = DO.Mapping . map (\(key, val) -> (key, DO.Scalar val))
|
# canonicalizeKey :: (Text, val) -> (Text, val)
|
||||||
|
# canonicalizeKey ("dbname", val) = ("database", val)
|
||||||
|
# canonicalizeKey pair = pair
|
||||||
#
|
#
|
||||||
# combineMappings :: DO.Object key val -> DO.Object key val -> DO.Object key val
|
# toMapping :: [(Text, Text)] -> AT.Value
|
||||||
# combineMappings (DO.Mapping m1) (DO.Mapping m2) = DO.Mapping $ m1 ++ m2
|
# toMapping xs = AT.Object $ M.fromList $ map (\(key, val) -> (key, AT.String val)) xs
|
||||||
# combineMappings _ _ = error "Data.Object is not a Mapping."
|
# #endif
|
||||||
#
|
#
|
||||||
# loadHerokuConfig :: DO.TextObject -> IO Settings.PersistConfig
|
# combineMappings :: AT.Value -> AT.Value -> AT.Value
|
||||||
# loadHerokuConfig ymlenv = do
|
# combineMappings (AT.Object m1) (AT.Object m2) = AT.Object $ m1 `M.union` m2
|
||||||
# #if DEVELOPMENT
|
# combineMappings _ _ = error "Data.Object is not a Mapping."
|
||||||
# let urlMap = DO.Mapping []
|
|
||||||
# #else
|
|
||||||
# urlMap <- Web.Heroku.dbConnParams >>= return . toMapping . map canonicalizeKey
|
|
||||||
# #endif
|
|
||||||
# either error return $ Database.Persist.Base.loadConfig (combineMappings urlMap ymlenv)
|
|
||||||
#
|
#
|
||||||
#
|
# loadHerokuConfig :: IO AT.Value
|
||||||
# withYesodHeroku :: AppConfig DefaultEnv () -> Logger -> (Application -> IO ()) -> IO ()
|
# loadHerokuConfig = do
|
||||||
# withYesodHeroku conf logger f = do
|
# #if DEVELOPMENT
|
||||||
# s <- staticSite
|
# return $ AT.Object M.empty
|
||||||
# dbconf <- withYamlEnvironment "config/postgresql.yml" (appEnv conf) loadHerokuConfig
|
# #else
|
||||||
# Database.Persist.Base.withPool (dbconf :: Settings.PersistConfig) $ \p -> do
|
# Web.Heroku.dbConnParams >>= return . toMapping . map canonicalizeKey
|
||||||
# Database.Persist.Base.runPool dbconf (runMigration migrateAll) p
|
# #endif
|
||||||
# let h = YesodHeroku conf logger s p
|
|
||||||
# defaultRunner (f . logWare) h
|
|
||||||
# where
|
|
||||||
# #ifdef DEVELOPMENT
|
|
||||||
# logWare = logStdoutDev
|
|
||||||
# #else
|
|
||||||
# logWare = logStdout
|
|
||||||
# #endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user