Skip to content

Commit

Permalink
Merge pull request #202 from yesodweb/warnAboutTruncate
Browse files Browse the repository at this point in the history
Warn that TRUNCATEing many tables with Postgres can become slow
  • Loading branch information
snoyberg authored Jun 28, 2020
2 parents a9e866c + 77cda01 commit 55c7460
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/TestImport.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ wipeDB app = runDBWithApp app $ do
tables <- getTables
sqlBackend <- ask

-- TRUNCATEing all tables is the simplest approach to wiping the database.
-- Should your application grow to hundreds of tables and tests,
-- switching to DELETE could be a substantial speedup.
-- See: https://github.com/yesodweb/yesod-scaffold/issues/201
let escapedTables = map (connEscapeName sqlBackend . DBName) tables
query = "TRUNCATE TABLE " ++ intercalate ", " escapedTables
rawExecute query []
Expand Down

0 comments on commit 55c7460

Please sign in to comment.