Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly wait for database creation instead of relying on sleep #56

Open
3 tasks done
yamcodes opened this issue Oct 9, 2023 · 1 comment · May be fixed by #71
Open
3 tasks done

Properly wait for database creation instead of relying on sleep #56

yamcodes opened this issue Oct 9, 2023 · 1 comment · May be fixed by #71
Assignees
Labels
devcontainers Relates to dev containers. enhancement New feature or request help wanted Extra attention is needed

Comments

@yamcodes
Copy link
Contributor

yamcodes commented Oct 9, 2023

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

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 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:

  1. 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.
  2. Rely on the healthcheck implemented in docker-compose.yml, through pg_isready.

Additional context

It would be great to find real world examples for devcontainers that succesfully apply migrations when the container is built.

Validations

  • Read the Contributing Guide.
  • Read the README.md.
  • Check that there isn't already an issue that requests the same feature.
@yamcodes yamcodes added bug Something isn't working help wanted Extra attention is needed and removed bug Something isn't working labels Oct 9, 2023
@yamcodes yamcodes mentioned this issue Oct 9, 2023
5 tasks
@yamcodes yamcodes changed the title Dev containers: properly wait for database creation instead of relying on sleep Properly wait for database creation instead of relying on sleep Oct 16, 2023
@yamcodes yamcodes added enhancement New feature or request devcontainers Relates to dev containers. labels Oct 16, 2023
@Hajbo
Copy link
Collaborator

Hajbo commented Oct 18, 2023

I think we can solve it with some changes to the docker compose file, I'll play around with it a bit

@Hajbo Hajbo linked a pull request Oct 18, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devcontainers Relates to dev containers. enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants