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

Fix setup_db.sh by waiting for pg_isready success return. Fixes #3876 #3908

Merged
merged 8 commits into from
Oct 21, 2021
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
- Fix intermittent errors in partial parsing tests ([#4060](https:/dbt-labs/dbt-core/issues/4060), [#4068](https:/dbt-labs/dbt-core/pull/4068))
- Make finding disabled nodes more consistent ([#4069](https:/dbt-labs/dbt-core/issues/4069), [#4073](https:/dbt-labas/dbt-core/pull/4073))
- Remove connection from `render_with_context` during parsing, thereby removing misleading log message ([#3137](https:/dbt-labs/dbt-core/issues/3137), [#4062](https:/dbt-labas/dbt-core/pull/4062))
- Wait for postgres docker container to be ready in `setup_db.sh`. ([#3876](https:/dbt-labs/dbt-core/issues/3876), [#3908](https:/dbt-labs/dbt-core/pull/3908))

Contributors:
- [@sungchun12](https:/sungchun12) ([#4017](https:/dbt-labs/dbt/pull/4017))
- [@matt-winkler](https:/matt-winkler) ([#4017](https:/dbt-labs/dbt/pull/4017))
- [@NiallRees](https:/NiallRees) ([#3625](https:/dbt-labs/dbt/pull/3625))
- [@rvacaru](https:/rvacaru) ([#3908](https:/dbt-labs/dbt/pull/3908))

## dbt-core 1.0.0b1 (October 11, 2021)

Expand Down
2 changes: 0 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:/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.

```
Expand Down
10 changes: 9 additions & 1 deletion test/setup_db.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#!/bin/bash
set -x

env | grep '^PG'

# If you want to run this script for your own postgresql (run with
Expand Down Expand Up @@ -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;
rvacaru marked this conversation as resolved.
Show resolved Hide resolved

createdb dbt
psql -c "CREATE ROLE root WITH PASSWORD 'password';"
psql -c "ALTER ROLE root WITH LOGIN;"
Expand Down