-
Notifications
You must be signed in to change notification settings - Fork 0
Add automated database schema diagram generation #187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
6627ffe
503149d
4afe8c2
52b7dc3
cd62a6e
cb03740
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create a sample SQLite database from the hadiscover models for schema diagram generation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -e | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Creating sample database from models..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Get the script directory and project root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| PROJECT_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| BACKEND_DIR="$PROJECT_ROOT/backend" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Install backend dependencies using the shared script | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Installing backend dependencies..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd "$PROJECT_ROOT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .github/scripts/install-backend-deps.sh | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create a temporary Python script to generate the database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cat > /tmp/create_db.py << 'EOF' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """Generate sample SQLite database from SQLAlchemy models.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from app.models.database import Base | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from sqlalchemy import create_engine | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Create engine and database | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+18
to
+24
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| engine = create_engine('sqlite:///sample_schema.db') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Base.metadata.create_all(engine) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| print("Sample database created successfully at backend/sample_schema.db") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+28
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from app.models.database import Base | |
| from sqlalchemy import create_engine | |
| # Create engine and database | |
| engine = create_engine('sqlite:///sample_schema.db') | |
| Base.metadata.create_all(engine) | |
| print("Sample database created successfully at backend/sample_schema.db") | |
| from pathlib import Path | |
| from sqlalchemy import create_engine | |
| from app.models.database import Base | |
| # Determine database path in current working directory (backend/) | |
| db_path = Path("sample_schema.db") | |
| # Remove existing database file to avoid stale schemas | |
| if db_path.exists(): | |
| db_path.unlink() | |
| # Create engine and database | |
| engine = create_engine(f"sqlite:///{db_path}") | |
| Base.metadata.create_all(engine) | |
| print(f"Sample database created successfully at {db_path.resolve()}") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| --- | ||
| name: Generate Database Schema Diagram | ||
|
|
||
| # yamllint disable-line rule:truthy | ||
| on: | ||
| workflow_dispatch: null | ||
|
Comment on lines
+4
to
+6
|
||
| push: | ||
| branches: | ||
| - main | ||
| paths: | ||
| - "backend/app/models/**" | ||
| - ".github/workflows/schema-diagram.yml" | ||
| - ".github/scripts/create-sample-db.sh" | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| generate-schema-diagram: | ||
| name: Generate Schema Diagram | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout code | ||
| # v6 | ||
| uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd | ||
| with: | ||
| persist-credentials: false | ||
|
|
||
| - name: Setup Python | ||
| # v6 | ||
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 | ||
| with: | ||
| python-version: "3.14" | ||
| cache: "pip" | ||
| cache-dependency-path: backend/requirements.txt | ||
|
|
||
| - name: Create sample database | ||
| run: .github/scripts/create-sample-db.sh | ||
|
|
||
| - name: Generate schema diagram | ||
| # v17.6.0 | ||
| uses: schemacrawler/SchemaCrawler-Action@v17.6.0 | ||
| with: | ||
| entrypoint: /schemacrawler.sh | ||
| args: >- | ||
| --server=sqlite | ||
| --database=backend/sample_schema.db | ||
| --info-level=maximum | ||
| --command=schema | ||
| --output-format=png | ||
| --output-file=schema-diagram.png | ||
|
|
||
| - name: Upload schema diagram | ||
| # v4 | ||
| uses: >- | ||
| actions/upload-artifact@c0d66db0b43eb92e5f6e4fc5f8f67c6d8c1e2d10 | ||
| with: | ||
| name: database-schema-diagram | ||
| path: schema-diagram.png | ||
| retention-days: 90 | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script creates/activates a
backend/venvand installs dependencies on every run. In CI this adds time and duplicates the existing.github/scripts/install-backend-deps.shpattern used elsewhere. Consider reusing the existing dependency-install script (and/or avoid creating a venv inside the repo) to keep workflows consistent and faster.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to reuse the existing
.github/scripts/install-backend-deps.shscript instead of duplicating the dependency installation logic. The script now calls the shared install script which is consistent with other workflows. (commit cd62a6e)