diff --git a/.github/actions/setup-postgres-linux/action.yml b/.github/actions/setup-postgres-linux/action.yml index 74cb7aa7..67de5acc 100644 --- a/.github/actions/setup-postgres-linux/action.yml +++ b/.github/actions/setup-postgres-linux/action.yml @@ -9,6 +9,10 @@ runs: run: sudo systemctl start postgresql.service shell: bash +# - name: Configure the database +# run: sudo -u postgres psql -f ./scripts/setup_test_database.sql +# shell: bash + - name: Configure the database - run: sudo -u postgres psql -f ./scripts/setup_test_database.sql + run: sudo -u postgres bash ${{ github.action_path }}/setup_db.sh shell: bash diff --git a/.github/actions/setup-postgres-linux/setup_db.sh b/.github/actions/setup-postgres-linux/setup_db.sh new file mode 100755 index 00000000..f52da735 --- /dev/null +++ b/.github/actions/setup-postgres-linux/setup_db.sh @@ -0,0 +1,37 @@ +#!/bin/bash +set -x +env | grep '^PG' + +# If you want to run this script for your own postgresql (run with +# docker-compose) it will look like this: +# PGHOST=127.0.0.1 PGUSER=root PGPASSWORD=password PGDATABASE=postgres \ +PGUSER="${PGUSER:-postgres}" +export PGUSER +PGPORT="${PGPORT:-5432}" +export PGPORT +PGHOST="${PGHOST:-localhost}" + +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;" +psql -c "GRANT CREATE, CONNECT ON DATABASE dbt TO root WITH GRANT OPTION;" + +psql -c "CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER;" +psql -c "ALTER ROLE noaccess WITH LOGIN;" +psql -c "GRANT CONNECT ON DATABASE dbt TO noaccess;" +psql -c "CREATE ROLE dbt_test_user_1;" +psql -c "CREATE ROLE dbt_test_user_2;" +psql -c "CREATE ROLE dbt_test_user_3;" + +psql -c 'CREATE DATABASE "dbtMixedCase";' +psql -c 'GRANT CREATE, CONNECT ON DATABASE "dbtMixedCase" TO root WITH GRANT OPTION;' + +set +x diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 468e46cf..b02285dc 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -46,11 +46,8 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Run empty script - run: bash ./scripts/my-script.sh - -# - name: Setup postgres -# uses: ./.github/actions/setup-postgres-linux + - name: Setup postgres + uses: ./.github/actions/setup-postgres-linux - name: Run integration tests run: hatch run integration-tests:all