Automatically sync your database schema with ChartDB to keep your ER diagrams up-to-date.
- π Automatic database schema synchronization
- π Updates ChartDB diagrams in real-time
- π Secure handling of credentials via GitHub Secrets
- π³ Docker-based for consistent execution
- ποΈ Supports PostgreSQL, MySQL, SQL Server, MariaDB, SQLite, ClickHouse, CockroachDB, and Oracle
name: Sync Database with ChartDB on: push: branches: [ main ] schedule: - cron: '0 0 * * *' # Daily sync at midnight jobs: sync: runs-on: ubuntu-latest steps: - name: Sync Database Schema uses: chartdb/chartdb-action@v1 with: db-host: ${{ secrets.DB_HOST }} db-port: '5432' db-database: ${{ secrets.DB_DATABASE }} db-username: ${{ secrets.DB_USERNAME }} db-password: ${{ secrets.DB_PASSWORD }} db-type: 'postgresql' chartdb-api-token: ${{ secrets.CHARTDB_API_TOKEN }} chartdb-diagram-id: ${{ secrets.CHARTDB_DIAGRAM_ID }}name: Sync GitHub Actions Database on: workflow_dispatch: push: paths: - 'migrations/**' - 'schema/**' jobs: sync: runs-on: ubuntu-latest services: postgres: image: postgres:15 env: POSTGRES_USER: testuser POSTGRES_PASSWORD: testpass POSTGRES_DB: testdb options: >- --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5 ports: - 5432:5432 steps: - uses: actions/checkout@v4 - name: Run migrations run: | # Your migration commands here - name: Sync with ChartDB uses: chartdb/chartdb-action@v1 with: db-host: 'localhost' db-port: '5432' db-database: 'testdb' db-username: 'testuser' db-password: 'testpass' db-type: 'postgresql' chartdb-api-token: ${{ secrets.CHARTDB_API_TOKEN }} chartdb-diagram-id: ${{ secrets.CHARTDB_DIAGRAM_ID }}| Input | Description | Required | Default |
|---|---|---|---|
db-host | Database host address | Yes | - |
db-port | Database port | No | 5432 |
db-database | Database name | Yes | - |
db-username | Database username | Yes | - |
db-password | Database password (use secrets!) | No | - |
db-type | Database type (postgresql, mysql, sql_server, sqlite, mariadb, clickhouse, cockroachdb, oracle) | Yes | - |
chartdb-api-token | ChartDB API token (use secrets!) | Yes | - |
chartdb-diagram-id | ChartDB diagram ID to sync with | Yes | - |
network | Docker network mode | No | host |
| Output | Description |
|---|---|
status | Sync status (success or failed) |
- Sign up at ChartDB
- Create or open your diagram
- Navigate to diagram settings
- Generate an API token
- Copy your diagram ID from the URL or settings
Add the following secrets to your repository:
- Go to Settings β Secrets and variables β Actions
- Add these secrets:
DB_HOST: Your database hostDB_DATABASE: Your database nameDB_USERNAME: Database usernameDB_PASSWORD: Database passwordCHARTDB_API_TOKEN: Your ChartDB API tokenCHARTDB_DIAGRAM_ID: Your ChartDB diagram ID
Create .github/workflows/chartdb-sync.yml in your repository with one of the examples above.
- Always use GitHub Secrets for sensitive information
- Never commit credentials directly in workflow files
- Consider using environment-specific secrets for different stages
- Use least-privilege database users for syncing
- Rotate API tokens regularly
db-type: 'postgresql' db-port: '5432' # defaultdb-type: 'mysql' db-port: '3306' # defaultdb-type: 'mariadb' db-port: '3306' # defaultdb-type: 'sql_server' db-port: '1433' # default- name: Sync with ChartDB if: github.ref == 'refs/heads/main' uses: chartdb/chartdb-action@v1 with: # ... your configurationjobs: sync-staging: runs-on: ubuntu-latest environment: staging steps: - uses: chartdb/chartdb-action@v1 with: db-host: ${{ secrets.STAGING_DB_HOST }} chartdb-diagram-id: ${{ secrets.STAGING_DIAGRAM_ID }} # ... other staging config sync-production: runs-on: ubuntu-latest environment: production if: github.ref == 'refs/heads/main' steps: - uses: chartdb/chartdb-action@v1 with: db-host: ${{ secrets.PROD_DB_HOST }} chartdb-diagram-id: ${{ secrets.PROD_DIAGRAM_ID }} # ... other production config- name: Sync with ChartDB id: chartdb-sync uses: chartdb/chartdb-action@v1 with: # ... your configuration - name: Check sync status if: steps.chartdb-sync.outputs.status == 'failed' run: | echo "ChartDB sync failed! Check the logs above." exit 1If the action fails to connect to your database:
- Check network accessibility: Ensure your database is accessible from GitHub Actions runners
- Verify credentials: Double-check all secrets are correctly set
- Firewall rules: Add GitHub Actions IP ranges to your database firewall if needed
- Use self-hosted runners: For private databases, consider using self-hosted runners
The action uses host network mode by default. For other configurations:
with: network: 'bridge' # or 'none', 'container:name', etc.Contributions are welcome! Please feel free to submit a Pull Request.
MIT
- π§ Email: support@chartdb.io
- π Issues: GitHub Issues
- π Documentation: ChartDB Docs
- ChartDB - Visual database design tool