atdatabases
atdatabases copied to clipboard
feat: allow persistent data in postgres test
The idea is to build a very simple CLI that lets you do something like:
pg-test start --persistVolume my-database --writeEnv .env.local
and it would start a database and put the DATABASE_URL
for the freshly started database in .env.local
and persist data as a my-database
volume in docker.
Questions
- How should we name the containers? Currently we default to
pg-test
for all containers so we automatically shut down old containers when running new ones. Maybe we should use the volume name when one is provided? Maybe we should include the current directory name? - If you have lots of projects using separate pg databases, it might be easy to start one pointing at the wrong port number. Could we hash the volume-name and use that to decide on the port number?
- Port numbers range from 0 to 65535 (i.e. 16 bits), but port numbers 0 to 1023 are reserved for privileged services and designated as well-known ports. Registered ports are 1024 to 49151. Dynamic ports (also called private ports) are 49152 to 65535. (https://www.webopedia.com/quick_ref/portnumbers.asp)
- generate-alphabetic-name can generate a 32 bit numeric hash from any string
- If we can evenly distribute across the remaining 16383 port numbers that are available for general use, we can probably fairly consistently pick different ports for different volume names.
Docker Commands
You can see the volumes via:
docker volume ls
You can delete a volume via:
docker volume rm my-database