Skip to content

Commit

Permalink
move database configuration into sql file
Browse files Browse the repository at this point in the history
  • Loading branch information
mikealfare committed Jan 27, 2024
1 parent d875cfa commit 71e2604
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup-postgres-linux/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions .github/scripts/setup_postgres_linux.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand Down
12 changes: 2 additions & 10 deletions .github/workflows/integration-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions scripts/setup_test_database.sql
Original file line number Diff line number Diff line change
@@ -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;

0 comments on commit 71e2604

Please sign in to comment.