Skip to content

Commit

Permalink
Merge pull request #5 from diksown/test_sql_ci
Browse files Browse the repository at this point in the history
add sql test to ci
  • Loading branch information
diksown committed Nov 16, 2023
2 parents c22115e + aa9f0bb commit cdb21d8
Show file tree
Hide file tree
Showing 3 changed files with 208 additions and 149 deletions.
19 changes: 19 additions & 0 deletions .github/run_sql_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

DATABASE_NAME="test_sql"
USER="postgres" # Default user
HOST="localhost"

FILES=("esquema.sql" "triggers.sql" "dados.sql" "consultas.sql")

for file in "${FILES[@]}"
do
echo "Running $file..."
PGPASSWORD=postgres psql --set ON_ERROR_STOP=on -d "$DATABASE_NAME" -U "$USER" -h "$HOST" -f "sql/$file"
if [ $? -ne 0 ]; then
echo "Error encountered running $file"
exit 1
fi
done

echo "All files executed successfully"
31 changes: 31 additions & 0 deletions .github/workflows/test_sql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: SQL Test

on:
push:

jobs:
test-database:
runs-on: ubuntu-latest

services:
postgres:
image: postgres
env:
POSTGRES_PASSWORD: postgres
POSTGRES_DB: test_sql
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Run SQL Files
run: .github/run_sql_files.sh
env:
PGPASSWORD: postgres
Loading

0 comments on commit cdb21d8

Please sign in to comment.