diff --git a/.github/workflows/database_ws.yml b/.github/workflows/database_ws.yml new file mode 100644 index 0000000000..199dd48b89 --- /dev/null +++ b/.github/workflows/database_ws.yml @@ -0,0 +1,90 @@ +name: Create Giswater Schema (WS) + +on: + push: + branches: [ dev-3.6 ] + pull_request: + branches: [ dev-3.6 ] + +jobs: + setup-and-test-db: + runs-on: ubuntu-latest + + services: + postgres: + image: postgres:latest + ports: + - 5432:5432 + env: + POSTGRES_DB: giswater_test_db + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres + options: >- + --health-cmd "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + + steps: + - name: Checkout repository + uses: actions/checkout@v2 + + - name: Set up Python + uses: actions/setup-python@v2 + with: + python-version: '3.x' + + - name: Install Python dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + + - name: Wait for PostgreSQL to be ready + run: | + echo "Waiting for PostgreSQL to be ready..." + while ! pg_isready -h localhost -p 5432 -U postgres; do + sleep 1 + done + + - name: Replace variables in SQL files + run: python replace_vars.py + + - name: Create sample schema + env: + PGPASSWORD: postgres + run: | + # Define the root directories to process + root_directories=("utils" "ws" "i18n") + + # Process each root directory and its subdirectories + for root_dir in "${root_directories[@]}"; do + echo "Processing root directory: $root_dir" + find "$root_dir" -type f -name "*.sql" | sort | while read -r file; do + echo "Executing $file..." + psql -h localhost -U postgres -d giswater_test_db -f "$file" + done + done + + # Define the base updates directory + updates_dir="updates/36" + + # Check if the updates directory exists + if [ -d "$updates_dir" ]; then + # Process "utils" and "ws" subdirectories within updates_dir + find "$updates_dir" -type d -name "utils" -o -name "ws" | sort | while read -r subdir; do + echo "Processing directory: $subdir" + find "$subdir" -type f -name "*.sql" | sort | while read -r file; do + echo "Executing $file..." + psql -h localhost -U postgres -d giswater_test_db -f "$file" + done + done + else + echo "Directory $updates_dir does not exist" + fi + + - name: Verify Database + env: + PGPASSWORD: postgres + run: | + # Add any SQL checks or verifications here + psql -h localhost -U postgres -d giswater_test_db -c '\dt' \ No newline at end of file diff --git a/.github/workflows/replace_vars.py b/.github/workflows/replace_vars.py new file mode 100644 index 0000000000..d88d92480c --- /dev/null +++ b/.github/workflows/replace_vars.py @@ -0,0 +1,24 @@ +import os + +def replace_vars_in_file(file_path, replacements): + with open(file_path, 'r') as file: + content = file.read() + for old, new in replacements.items(): + content = content.replace(old, new) + with open(file_path, 'w') as file: + file.write(content) + +def main(): + sql_dir = './' + replacements = { + 'SCHEMA_NAME': 'ws_36', + 'SRID_VALUE': '25831', + # Add more replacements as needed + } + for root, dirs, files in os.walk(sql_dir): + for file in files: + if file.endswith('.sql'): + replace_vars_in_file(os.path.join(root, file), replacements) + +if __name__ == "__main__": + main() diff --git a/.github/workflows/requirements.txt b/.github/workflows/requirements.txt new file mode 100644 index 0000000000..e69de29bb2