This PR adds a docker compose target to run the postgres database locally, then updates the server to connect to it.
Related Issues / PRs
Resolves #50
Thought Process
I was trying to keep it as simple as possible, so this only adds a convenience docker compose script to run pg, otherwise you can setup postgres manually.
The https://github.com/jackc/pgx module seems to be the best postgres db driver for Go, so I pulled it in, set up a connection pool, and performed a ping.
There was a little bit of refactoring for the config; I decided to make an explicit local config and remove the local defaults from the config struct tags.
Testing Steps
You'll need to run docker, then run:
docker compose up -d
Which will download the postgres image if it hasn't already and run it with the settings we want.
Then run the server: go run ./cmd/eventual
If you don't get any errors, then it succeeded. You can try shutting down the database and running the server, which should then fail and show an error.
When you're done, you can shutdown postgres running in docker by running:
docker compose down
Risks
If the environment variable in production isn't set, then the server will fail to connect to the database and shutdown. The database is also configured to scale to zero, so it's possible that after everything has stopped after no activity, when the server goes to boot up again, it may fail a few times (I actually don't know if fly will attempt to restart it) before the database comes up. A follow up issue may be to introduce some retry logic for the connections if pgx doesn't already include some.
Overview
This PR adds a docker compose target to run the postgres database locally, then updates the server to connect to it.
Related Issues / PRs
Resolves #50
Thought Process
I was trying to keep it as simple as possible, so this only adds a convenience docker compose script to run pg, otherwise you can setup postgres manually.
The https://github.com/jackc/pgx module seems to be the best postgres db driver for Go, so I pulled it in, set up a connection pool, and performed a ping.
There was a little bit of refactoring for the config; I decided to make an explicit local config and remove the local defaults from the config struct tags.
Testing Steps
You'll need to run docker, then run:
Which will download the postgres image if it hasn't already and run it with the settings we want.
Then run the server:
go run ./cmd/eventual
If you don't get any errors, then it succeeded. You can try shutting down the database and running the server, which should then fail and show an error.
When you're done, you can shutdown postgres running in docker by running:
Risks
If the environment variable in production isn't set, then the server will fail to connect to the database and shutdown. The database is also configured to scale to zero, so it's possible that after everything has stopped after no activity, when the server goes to boot up again, it may fail a few times (I actually don't know if fly will attempt to restart it) before the database comes up. A follow up issue may be to introduce some retry logic for the connections if pgx doesn't already include some.