the-bed-stack
the-bed-stack copied to clipboard
Properly wait for database creation instead of relying on `sleep`
Clear and concise description of the problem
Currently in scripts/create-db.sh
, we rely on the following command to ensure that the database has been created, before running migrations:
sleep 10
Obviously, this is unreliable, since different machines can take different time to create the database.
Importantly, the reason this is happening is that we are applying the migrations through postCreateCommand
. This command is executed without waiting for the database to be created.
Suggested solution
We can avoid doing this in postCreateCommand
, and add logic to the database instructions directly inside docker-compose.yml
.
The problem with this is I'm unsure how it will work with drizzle-orm
, since the db image is created before initializing and installing bun.
Alternative
Alternatively, if we wish to keep using postCreateCommand
:
- Rely on scripts like
wait-for-it.sh
. The problem with this approach is that it just waits for the db server to run, not for the database to be created. - Rely on the healthcheck implemented in
docker-compose.yml
, throughpg_isready
.
Additional context
It would be great to find real world examples for devcontainers that succesfully apply migrations when the container is built.
Validations
- [X] Read the Contributing Guide.
- [X] Read the
README.md
. - [X] Check that there isn't already an issue that requests the same feature.
I think we can solve it with some changes to the docker compose file, I'll play around with it a bit