← Back to context

Comment by mlni

14 days ago

Running all migrations before every tests can take you a surprisingly long way.

Once that gets a bit too slow, running migrations once before every suite and then deleting all data before each test works really well. It's pretty easy to make the deleting dynamic by querying the names of all tables and constructing one statement to clear the data, which avoids referential integrity issues. Surprisingly, `TRUNCATE` is measurably slower than `DELETE FROM`.

Another nice touch is that turning off `fsync` in postgres makes it noticeably faster, while maintaining all transactional semantics.