-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add github workflow with database tests of all schema files
- Loading branch information
1 parent
d00060b
commit f6e8c11
Showing
1 changed file
with
173 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,173 @@ | ||
name: Test database creation and TAP_SCHEMA upload | ||
on: [push] | ||
|
||
jobs: | ||
|
||
postgresql: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
services: | ||
postgres: | ||
image: postgres:13 | ||
env: | ||
POSTGRES_USER: rubin | ||
POSTGRES_PASSWORD: rubin | ||
POSTGRES_DB: sdm_schemas_test | ||
ports: | ||
- 5432:5432 | ||
options: >- | ||
--health-cmd pg_isready | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip uv | ||
uv pip install --system -r requirements.txt | ||
- name: Set engine URL | ||
run: echo "FELIS_ENGINE_URL=postgresql+psycopg2://rubin:rubin@localhost:5432/sdm_schemas_test" >> $GITHUB_ENV | ||
|
||
# Create databases from YAML files. Drop existing databases since some of | ||
# the schema names are duplicated and also ignore constraints since many | ||
# schemas are missing required indices for FK constraints. | ||
- name: Create databases | ||
run: | | ||
for file in yml/*.yaml; do | ||
echo "Creating database from $file..." | ||
felis --log-level ERROR create --drop --ignore-constraints "$file" | ||
echo "Done creating database from $file" | ||
done | ||
- name: Create SQL files | ||
run: | | ||
for file in yml/*.yaml; do | ||
echo "Creating SQL from $file..." | ||
felis --log-level ERROR create --engine-url=postgresql+psycopg2:// --output-file "${file%.yaml}.sql" "$file" | ||
echo "Done creating SQL from $file" | ||
done | ||
- name: Initialize TAP_SCHEMA database | ||
run: | | ||
felis init-tap $FELIS_ENGINE_URL | ||
# Upload to TAP_SCHEMA database. Clear the tables after each upload to | ||
# avoid conflicts between schemas. Skip consdb schemas since they are | ||
# currently incompatible. | ||
- name: Upload to TAP_SCHEMA database | ||
run: | | ||
for file in yml/*.yaml; do | ||
filename=$(basename "$file") | ||
if [[ $filename == cdb_* ]]; then | ||
echo "Skipping TAP_SCHEMA upload of $file" | ||
continue | ||
fi | ||
echo "Uploading to TAP_SCHEMA from $file..." | ||
felis --log-level ERROR load-tap "$file" | ||
echo "Done uploading to TAP_SCHEMA from $file" | ||
psql postgresql://rubin:rubin@localhost/sdm_schemas_test -q -c "TRUNCATE TABLE columns, key_columns, keys, schemas, tables;" | ||
done | ||
mysql: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
services: | ||
mysql: | ||
image: mysql:8 | ||
env: | ||
MYSQL_ROOT_PASSWORD: root | ||
MYSQL_DATABASE: sdm_schemas_test | ||
MYSQL_USER: rubin | ||
MYSQL_PASSWORD: rubin | ||
ports: | ||
- 3306:3306 | ||
options: >- | ||
--health-cmd "mysqladmin ping --silent" | ||
--health-interval 10s | ||
--health-timeout 5s | ||
--health-retries 5 | ||
steps: | ||
- name: Check out repo | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
cache: "pip" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip uv | ||
uv pip install --system -r requirements.txt | ||
- name: Grant privileges to MySQL user | ||
run: | | ||
mysql -h 127.0.0.1 -P 3306 -u root -proot -e "GRANT ALL PRIVILEGES ON *.* TO 'rubin'@'%' WITH GRANT OPTION; FLUSH PRIVILEGES;" | ||
- name: Set engine URL | ||
run: echo "FELIS_ENGINE_URL=mysql+pymysql://rubin:rubin@localhost:3306" >> $GITHUB_ENV | ||
|
||
# Create databases from YAML files. Drop existing databases since some of | ||
# the schema names are duplicated and also ignore constraints since many | ||
# schemas are missing required indices for FK constraints. | ||
- name: Create databases | ||
run: | | ||
set +e | ||
for file in yml/*.yaml; do | ||
filename=$(basename "$file") | ||
if [[ $filename == "apdb.yaml" ]]; then | ||
echo "Skipping TAP_SCHEMA upload of $file" | ||
continue | ||
fi | ||
echo "Creating database from $file..." | ||
felis --log-level ERROR create --drop --ignore-constraints "$file" | ||
echo "Done creating database from $file" | ||
done | ||
set -e | ||
- name: Create SQL files | ||
run: | | ||
for file in yml/*.yaml; do | ||
echo "Creating SQL from $file..." | ||
felis --log-level ERROR create --engine-url=mysql+pymysql:// --output-file "${file%.yaml}.sql" "$file" | ||
echo "Done creating SQL from $file" | ||
done | ||
- name: Initialize TAP_SCHEMA database | ||
run: | | ||
mysql -h 127.0.0.1 -P 3306 -u rubin -prubin -e "CREATE DATABASE TAP_SCHEMA;" | ||
felis init-tap ${FELIS_ENGINE_URL}/TAP_SCHEMA | ||
# Upload to TAP_SCHEMA database. Clear the tables after each upload to | ||
# avoid conflicts between schemas. Skip consdb schemas since they are | ||
# currently incompatible. | ||
- name: Upload to TAP_SCHEMA database | ||
run: | | ||
set +e | ||
for file in yml/*.yaml; do | ||
filename=$(basename "$file") | ||
if [[ $filename == cdb_* ]]; then | ||
echo "Skipping TAP_SCHEMA upload of $file" | ||
continue | ||
fi | ||
echo "Uploading to TAP_SCHEMA from $file..." | ||
felis --log-level ERROR load-tap --engine-url ${FELIS_ENGINE_URL}/TAP_SCHEMA "$file" | ||
echo "Done uploading to TAP_SCHEMA from $file" | ||
mysql -h 127.0.0.1 -P 3306 -u rubin -prubin -e "TRUNCATE TABLE columns, key_columns, keys, schemas, tables;" | ||
done | ||
set -e | ||