From 77cda01afa4c01d240b748ea7cbd035fa9675fc0 Mon Sep 17 00:00:00 2001 From: Maximilian Tagher Date: Sun, 28 Jun 2020 11:09:41 -0400 Subject: [PATCH] Warn that TRUNCATEing many tables with Postgres can become slow 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 --- test/TestImport.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/TestImport.hs b/test/TestImport.hs index fa62d57..e467891 100644 --- a/test/TestImport.hs +++ b/test/TestImport.hs @@ -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 []