forked from Giswater/giswater_dbmodel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() |
Empty file.