Properly wait for database creation instead of relying on sleep
#56
Labels
devcontainers
Relates to dev containers.
enhancement
New feature or request
help wanted
Extra attention is needed
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:Link to line in codebase
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 insidedocker-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
: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.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
README.md
.The text was updated successfully, but these errors were encountered: