From dca8fefd3376cd96f8075a828c2204f5706aaa52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=2E=20St=C3=B8vring?= Date: Tue, 13 Aug 2024 09:25:09 +0200 Subject: [PATCH 1/4] Update test-sql-queries.yml --- .github/workflows/test-sql-queries.yml | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-sql-queries.yml b/.github/workflows/test-sql-queries.yml index 50015cd8..34ac5303 100644 --- a/.github/workflows/test-sql-queries.yml +++ b/.github/workflows/test-sql-queries.yml @@ -2,6 +2,8 @@ name: Test SQL Queries on: workflow_dispatch: pull_request: +env: + PGPASSWORD: postgres jobs: test: name: Test SQL Queries @@ -29,10 +31,20 @@ jobs: sleep 1 done - name: Run create-tables.sql - env: - PGPASSWORD: postgres run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d testdb -f create-tables.sql + - name: Ensure tables were created + run: | + COUNT=$(psql -h localhost -U postgres -d testdb -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + if [ "$count" -eq 0 ]; then + echo "No tables found. Exiting with error." + exit 1 + fi - name: Run drop-tables.sql - env: - PGPASSWORD: postgres run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d testdb -f drop-tables.sql + - name: Ensure all tables were dropped + run: | + COUNT=$(psql -h localhost -U postgres -d testdb -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + if [ "$count" -gt 0 ]; then + echo "Tables found: $count. Exiting with error." + exit 1 + fi From 74d7cdb9407c6a662173229a4c995e2743aba183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=2E=20St=C3=B8vring?= Date: Tue, 13 Aug 2024 09:29:28 +0200 Subject: [PATCH 2/4] Update test-sql-queries.yml --- .github/workflows/test-sql-queries.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test-sql-queries.yml b/.github/workflows/test-sql-queries.yml index 34ac5303..2db048d2 100644 --- a/.github/workflows/test-sql-queries.yml +++ b/.github/workflows/test-sql-queries.yml @@ -20,8 +20,8 @@ jobs: --health-retries=5 env: POSTGRES_USER: postgres - POSTGRES_PASSWORD: postgres - POSTGRES_DB: testdb + POSTGRES_PASSWORD: ${{ env.PGPASSWORD }} + POSTGRES_DB: ${{ env.DATABASE_NAME }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -31,20 +31,20 @@ jobs: sleep 1 done - name: Run create-tables.sql - run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d testdb -f create-tables.sql + run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -f create-tables.sql - name: Ensure tables were created run: | - COUNT=$(psql -h localhost -U postgres -d testdb -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + COUNT=$(psql -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") if [ "$count" -eq 0 ]; then echo "No tables found. Exiting with error." exit 1 fi - name: Run drop-tables.sql - run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d testdb -f drop-tables.sql + run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -f drop-tables.sql - name: Ensure all tables were dropped run: | - COUNT=$(psql -h localhost -U postgres -d testdb -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + COUNT=$(psql -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") if [ "$count" -gt 0 ]; then - echo "Tables found: $count. Exiting with error." - exit 1 + echo "Tables found: $count. Exiting with error." + exit 1 fi From 711f06ed4d7333ca9cb6957224ac98b000e41d79 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=2E=20St=C3=B8vring?= Date: Tue, 13 Aug 2024 09:31:06 +0200 Subject: [PATCH 3/4] Update test-sql-queries.yml --- .github/workflows/test-sql-queries.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test-sql-queries.yml b/.github/workflows/test-sql-queries.yml index 2db048d2..04e35ddd 100644 --- a/.github/workflows/test-sql-queries.yml +++ b/.github/workflows/test-sql-queries.yml @@ -4,6 +4,7 @@ on: pull_request: env: PGPASSWORD: postgres + DATABASE_NAME: testdb jobs: test: name: Test SQL Queries From 17e1071b27602f74b2aec313cf68bd9733b2d8d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=2E=20St=C3=B8vring?= Date: Tue, 13 Aug 2024 09:33:33 +0200 Subject: [PATCH 4/4] Update test-sql-queries.yml --- .github/workflows/test-sql-queries.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/test-sql-queries.yml b/.github/workflows/test-sql-queries.yml index 04e35ddd..c26d00fb 100644 --- a/.github/workflows/test-sql-queries.yml +++ b/.github/workflows/test-sql-queries.yml @@ -35,8 +35,8 @@ jobs: run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -f create-tables.sql - name: Ensure tables were created run: | - COUNT=$(psql -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") - if [ "$count" -eq 0 ]; then + COUNT=$(psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + if [ "$COUNT" -eq 0 ]; then echo "No tables found. Exiting with error." exit 1 fi @@ -44,8 +44,8 @@ jobs: run: psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -f drop-tables.sql - name: Ensure all tables were dropped run: | - COUNT=$(psql -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") - if [ "$count" -gt 0 ]; then + COUNT=$(psql -v ON_ERROR_STOP=1 -h localhost -U postgres -d ${{ env.DATABASE_NAME }} -t -A -c "SELECT count(*) FROM information_schema.tables WHERE table_schema = 'public';") + if [ "$COUNT" -gt 0 ]; then echo "Tables found: $count. Exiting with error." exit 1 fi