From 71e2604e3eed05fb01f16f47eadc1c5cfe28ea2d Mon Sep 17 00:00:00 2001 From: Mike Alfare Date: Sat, 27 Jan 2024 17:29:47 -0500 Subject: [PATCH] move database configuration into sql file --- .github/actions/setup-postgres-linux/action.yml | 4 ++-- .github/scripts/setup_postgres_linux.sh | 3 --- .github/workflows/integration-tests.yml | 12 ++---------- scripts/setup_test_database.sql | 16 ++++++++++++++++ 4 files changed, 20 insertions(+), 15 deletions(-) create mode 100644 scripts/setup_test_database.sql diff --git a/.github/actions/setup-postgres-linux/action.yml b/.github/actions/setup-postgres-linux/action.yml index 32bf025e..9e49c4ae 100644 --- a/.github/actions/setup-postgres-linux/action.yml +++ b/.github/actions/setup-postgres-linux/action.yml @@ -10,6 +10,6 @@ runs: shell: bash - name: Configure the database - run: sudo -u postgres bash setup_postgres_linux.sh + run: sudo -u postgres psql -f setup_test_database.sql shell: bash - working-directory: ./.github/scripts + working-directory: ./scripts diff --git a/.github/scripts/setup_postgres_linux.sh b/.github/scripts/setup_postgres_linux.sh index 3a12f105..f52da735 100755 --- a/.github/scripts/setup_postgres_linux.sh +++ b/.github/scripts/setup_postgres_linux.sh @@ -15,13 +15,10 @@ 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; -echo "Postgres is running" - createdb dbt psql -c "CREATE ROLE root WITH PASSWORD 'password';" psql -c "ALTER ROLE root WITH LOGIN;" diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index b7f70c00..278c8e98 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -49,16 +49,8 @@ jobs: with: python-version: ${{ matrix.python-version }} - - name: Start the postgres service - run: | - sudo systemctl start postgresql.service - pg_isready - shell: bash - - - name: Configure the database - run: sudo -u postgres bash setup_postgres_linux.sh - shell: bash - working-directory: ./.github/scripts + - name: Setup postgres + uses: ./.github/actions/setup-postgres-linux - name: Run integration tests run: hatch run integration-tests:all diff --git a/scripts/setup_test_database.sql b/scripts/setup_test_database.sql new file mode 100644 index 00000000..8da2c0be --- /dev/null +++ b/scripts/setup_test_database.sql @@ -0,0 +1,16 @@ +CREATE DATABASE dbt; + +CREATE ROLE root WITH PASSWORD 'password'; +ALTER ROLE root WITH LOGIN; +GRANT CREATE, CONNECT ON DATABASE dbt TO root WITH GRANT OPTION; + +CREATE ROLE noaccess WITH PASSWORD 'password' NOSUPERUSER; +ALTER ROLE noaccess WITH LOGIN; +GRANT CONNECT ON DATABASE dbt TO noaccess; + +CREATE ROLE dbt_test_user_1; +CREATE ROLE dbt_test_user_2; +CREATE ROLE dbt_test_user_3; + +CREATE DATABASE "dbtMixedCase"; +GRANT CREATE, CONNECT ON DATABASE "dbtMixedCase" TO root WITH GRANT OPTION;