Per-project Postgres

submited by
Style Pass
2022-05-13 13:00:11

Here’s a little trick I worked out a while back. Along the way I’ll introduce two tools, direnv and Nix, which I’ve found super helpful when developing many different projects on the same computer. Each of these three tricks are useful by themselves but I find they go together especially well.

When I do web development with Django, I appreciate that it’s easy to set up a local development copy of a Django site using an in-process SQLite database. That makes it quick and easy to get started, because I don’t have to have a database server running on my laptop, or log in as an administrator to create accounts and databases and set access control rules.

On the other hand, many code bases require a specific database backend. And even in projects that have a multi-database abstraction layer over SQL, testing using a different database that you use in production is a recipe for unpleasant surprises.

So I worked out how to set up a Postgres database that’s almost as convenient as SQLite. (I’ve used this same approach for Elasticsearch as well; doing the same for MySQL or other databases is left as an exercise for the reader.)

Leave a Comment