From d82a828d89a488235ee069412bcee4d5ff4dce08 Mon Sep 17 00:00:00 2001 From: Michael Snoyman Date: Wed, 29 Apr 2015 13:55:50 +0300 Subject: [PATCH] Scaffolding updates, including #982 --- yesod-bin/hsfiles/mysql.hsfiles | 25 +++++++++++++------------ yesod-bin/hsfiles/postgres-fay.hsfiles | 9 ++++++--- yesod-bin/hsfiles/postgres.hsfiles | 9 ++++++--- yesod-bin/hsfiles/simple.hsfiles | 3 +-- yesod-bin/hsfiles/sqlite.hsfiles | 3 +++ 5 files changed, 29 insertions(+), 20 deletions(-) diff --git a/yesod-bin/hsfiles/mysql.hsfiles b/yesod-bin/hsfiles/mysql.hsfiles index e4103802..7565bc63 100644 --- a/yesod-bin/hsfiles/mysql.hsfiles +++ b/yesod-bin/hsfiles/mysql.hsfiles @@ -101,6 +101,9 @@ makeFoundation appSettings = do -- temporary foundation without a real connection pool, get a log function -- from there, and then create the real foundation. let mkFoundation appConnPool = App {..} + -- The App {..} syntax is an example of record wild cards. For more + -- information, see: + -- https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html tempFoundation = mkFoundation $ error "connPool forced in tempFoundation" logFunc = messageLoggerSource tempFoundation appLogger @@ -9159,19 +9162,17 @@ withApp = before $ do -- 'withApp' calls it before each test, creating a clean environment for each -- spec to run in. wipeDB :: App -> IO () -wipeDB app = do - runDBWithApp app $ do - tables <- getTables - sqlBackend <- ask - let queries = map (\t -> "TRUNCATE TABLE " ++ (connEscapeName sqlBackend $ DBName t)) tables +wipeDB app = runDBWithApp app $ do + tables <- getTables + sqlBackend <- ask + let queries = map (\t -> "TRUNCATE TABLE " ++ connEscapeName sqlBackend (DBName t)) tables - -- In MySQL, a table cannot be truncated if another table references it via foreign key. - -- Since we're wiping both the parent and child tables, though, it's safe - -- to temporarily disable this check. - rawExecute "SET foreign_key_checks = 0;" [] - forM_ queries (\q -> rawExecute q []) - rawExecute "SET foreign_key_checks = 1;" [] - return () + -- In MySQL, a table cannot be truncated if another table references it via foreign key. + -- Since we're wiping both the parent and child tables, though, it's safe + -- to temporarily disable this check. + rawExecute "SET foreign_key_checks = 0;" [] + forM_ queries (\q -> rawExecute q []) + rawExecute "SET foreign_key_checks = 1;" [] getTables :: MonadIO m => ReaderT SqlBackend m [Text] getTables = do diff --git a/yesod-bin/hsfiles/postgres-fay.hsfiles b/yesod-bin/hsfiles/postgres-fay.hsfiles index b76f3a7c..dc2073c6 100644 --- a/yesod-bin/hsfiles/postgres-fay.hsfiles +++ b/yesod-bin/hsfiles/postgres-fay.hsfiles @@ -107,6 +107,9 @@ makeFoundation appSettings = do -- temporary foundation without a real connection pool, get a log function -- from there, and then create the real foundation. let mkFoundation appConnPool = App {..} + -- The App {..} syntax is an example of record wild cards. For more + -- information, see: + -- https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html tempFoundation = mkFoundation $ error "connPool forced in tempFoundation" logFunc = messageLoggerSource tempFoundation appLogger @@ -1062,11 +1065,11 @@ ip-from-header: "_env:IP_FROM_HEADER:false" # skip-combining: false database: - user: "_env:PGUSER:PROJECTNAME" + user: "_env:PGUSER:PROJECTNAME_LOWER" password: "_env:PGPASS:PROJECTNAME" host: "_env:PGHOST:localhost" port: "_env:PGPORT:5432" - database: "_env:PGDATABASE:PROJECTNAME" + database: "_env:PGDATABASE:PROJECTNAME_LOWER" poolsize: "_env:PGPOOLSIZE:10" copyright: Insert copyright statement here @@ -1074,7 +1077,7 @@ copyright: Insert copyright statement here {-# START_FILE config/test-settings.yml #-} database: - database: PROJECTNAME_test + database: PROJECTNAME_LOWER_test {-# START_FILE fay-shared/SharedTypes.hs #-} {-# LANGUAGE NoImplicitPrelude #-} diff --git a/yesod-bin/hsfiles/postgres.hsfiles b/yesod-bin/hsfiles/postgres.hsfiles index 766c61bf..42dbc0f3 100644 --- a/yesod-bin/hsfiles/postgres.hsfiles +++ b/yesod-bin/hsfiles/postgres.hsfiles @@ -101,6 +101,9 @@ makeFoundation appSettings = do -- temporary foundation without a real connection pool, get a log function -- from there, and then create the real foundation. let mkFoundation appConnPool = App {..} + -- The App {..} syntax is an example of record wild cards. For more + -- information, see: + -- https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html tempFoundation = mkFoundation $ error "connPool forced in tempFoundation" logFunc = messageLoggerSource tempFoundation appLogger @@ -1002,11 +1005,11 @@ ip-from-header: "_env:IP_FROM_HEADER:false" # skip-combining: false database: - user: "_env:PGUSER:PROJECTNAME" + user: "_env:PGUSER:PROJECTNAME_LOWER" password: "_env:PGPASS:PROJECTNAME" host: "_env:PGHOST:localhost" port: "_env:PGPORT:5432" - database: "_env:PGDATABASE:PROJECTNAME" + database: "_env:PGDATABASE:PROJECTNAME_LOWER" poolsize: "_env:PGPOOLSIZE:10" copyright: Insert copyright statement here @@ -1014,7 +1017,7 @@ copyright: Insert copyright statement here {-# START_FILE config/test-settings.yml #-} database: - database: PROJECTNAME_test + database: PROJECTNAME_LOWER_test {-# START_FILE static/css/bootstrap.css #-} /*! diff --git a/yesod-bin/hsfiles/simple.hsfiles b/yesod-bin/hsfiles/simple.hsfiles index cb001434..67787c08 100644 --- a/yesod-bin/hsfiles/simple.hsfiles +++ b/yesod-bin/hsfiles/simple.hsfiles @@ -894,8 +894,7 @@ copyright: Insert copyright statement here #analytics: UA-YOURCODE {-# START_FILE config/test-settings.yml #-} -database: - database: PROJECTNAME_test +{} {-# START_FILE static/css/bootstrap.css #-} /*! diff --git a/yesod-bin/hsfiles/sqlite.hsfiles b/yesod-bin/hsfiles/sqlite.hsfiles index 6d7b9ef7..2c90217c 100644 --- a/yesod-bin/hsfiles/sqlite.hsfiles +++ b/yesod-bin/hsfiles/sqlite.hsfiles @@ -101,6 +101,9 @@ makeFoundation appSettings = do -- temporary foundation without a real connection pool, get a log function -- from there, and then create the real foundation. let mkFoundation appConnPool = App {..} + -- The App {..} syntax is an example of record wild cards. For more + -- information, see: + -- https://ocharles.org.uk/blog/posts/2014-12-04-record-wildcards.html tempFoundation = mkFoundation $ error "connPool forced in tempFoundation" logFunc = messageLoggerSource tempFoundation appLogger