Skip to content

Commit

Permalink
Warn that TRUNCATEing many tables with Postgres can become slow
Browse files Browse the repository at this point in the history
I think the vast, vast majority of yesod-scaffold users will never grow to the size where they need to care about this. But for the handful that do, it should save them a lot of time.

I could have made a wiki page about this and cleaned it all up, but I think it's not really worth it for how much of an edge case this is. To reach this point, you need to be a pretty advanced Yesod user
  • Loading branch information
MaxGabriel committed Jun 28, 2020
1 parent a9e866c commit 77cda01
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 77cda01

Please sign in to comment.