From 3ae94756552305a5fc80141dcd4842fd4f7e9acf Mon Sep 17 00:00:00 2001 From: Razvan Vacaru Date: Thu, 21 Oct 2021 09:16:28 +0200 Subject: [PATCH] Fix setup_db.sh by waiting for pg_isready success return. Fixes #3876 (#3908) * Fix setup_db.sh by waiting for pg_isready success return. Fixes #3876 * restored noaccess and dbtMixedCase creation and updated changelog and contributing md files * restored root auth commands * restored creation of dbt schema, aparently this is needed even if docker compose also creates it... * pr comments: avoid infinite loop and quote variables * Update changelog Co-authored-by: Jeremy Cohen --- CHANGELOG.md | 2 ++ CONTRIBUTING.md | 2 -- test/setup_db.sh | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c61b7aabc1..6b23135c2af 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,11 +16,13 @@ - Fix intermittent errors in partial parsing tests ([#4060](https://github.com/dbt-labs/dbt-core/issues/4060), [#4068](https://github.com/dbt-labs/dbt-core/pull/4068)) - Make finding disabled nodes more consistent ([#4069](https://github.com/dbt-labs/dbt-core/issues/4069), [#4073](https://github.com/dbt-labas/dbt-core/pull/4073)) - Remove connection from `render_with_context` during parsing, thereby removing misleading log message ([#3137](https://github.com/dbt-labs/dbt-core/issues/3137), [#4062](https://github.com/dbt-labas/dbt-core/pull/4062)) +- Wait for postgres docker container to be ready in `setup_db.sh`. ([#3876](https://github.com/dbt-labs/dbt-core/issues/3876), [#3908](https://github.com/dbt-labs/dbt-core/pull/3908)) Contributors: - [@sungchun12](https://github.com/sungchun12) ([#4017](https://github.com/dbt-labs/dbt/pull/4017)) - [@matt-winkler](https://github.com/matt-winkler) ([#4017](https://github.com/dbt-labs/dbt/pull/4017)) - [@NiallRees](https://github.com/NiallRees) ([#3625](https://github.com/dbt-labs/dbt/pull/3625)) +- [@rvacaru](https://github.com/rvacaru) ([#3908](https://github.com/dbt-labs/dbt/pull/3908)) ## dbt-core 1.0.0b1 (October 11, 2021) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 38a81cbde68..5397d5e3716 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -174,8 +174,6 @@ docker-compose up -d database PGHOST=localhost PGUSER=root PGPASSWORD=password PGDATABASE=postgres bash test/setup_db.sh ``` -Note that you may need to run the previous command twice as it does not currently wait for the database to be running before attempting to run commands against it. This will be fixed with [#3876](https://github.com/dbt-labs/dbt-core/issues/3876). - `dbt` uses test credentials specified in a `test.env` file in the root of the repository for non-Postgres databases. This `test.env` file is git-ignored, but please be _extra_ careful to never check in credentials or other sensitive information when developing against `dbt`. To create your `test.env` file, copy the provided sample file, then supply your relevant credentials. This step is only required to use non-Postgres databases. ``` diff --git a/test/setup_db.sh b/test/setup_db.sh index b52c3c487d8..b8b869e143b 100644 --- a/test/setup_db.sh +++ b/test/setup_db.sh @@ -1,6 +1,5 @@ #!/bin/bash set -x - env | grep '^PG' # If you want to run this script for your own postgresql (run with @@ -30,6 +29,15 @@ if [[ -n $CIRCLECI ]]; then connect_circle fi +for i in {1..10}; do + if $(pg_isready -h "${PGHOST}" -p "${PGPORT}" -U "${PGUSER}") ; then + break + fi + + echo "Waiting for postgres to be ready..." + sleep 2; +done; + createdb dbt psql -c "CREATE ROLE root WITH PASSWORD 'password';" psql -c "ALTER ROLE root WITH LOGIN;"