Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions .github/workflows/example.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: SQLDef Preview Example
name: SQLDef Preview

on:
pull_request:
Expand All @@ -8,7 +8,7 @@ permissions:
pull-requests: write

jobs:
postgresql-preview:
psqldef-preview:
runs-on: ubuntu-latest

services:
Expand Down Expand Up @@ -45,9 +45,9 @@ jobs:
pg-host: localhost
pg-port: 5432
pg-database: testdb
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ github.token }}

mysql-preview:
mysqldef-preview:
runs-on: ubuntu-latest

services:
Expand Down Expand Up @@ -83,9 +83,9 @@ jobs:
mysql-host: 127.0.0.1
mysql-port: 3306
mysql-database: testdb
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ github.token }}

sqlite-preview:
sqlite3def-preview:
runs-on: ubuntu-latest

steps:
Expand All @@ -103,9 +103,9 @@ jobs:
baseline-schema-file: examples/sqlite3def-current.sql
schema-file: examples/sqlite3def-desired.sql
sqlite-database: test.db
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ github.token }}

mssql-preview:
mssqldef-preview:
runs-on: ubuntu-latest

services:
Expand All @@ -124,8 +124,7 @@ jobs:
- 1433:1433

steps:
- name: Checkout code
uses: actions/checkout@v5
- uses: actions/checkout@v5
with:
fetch-depth: 0

Expand Down Expand Up @@ -154,4 +153,4 @@ jobs:
mssql-host: localhost
mssql-port: 1433
mssql-database: testdb
github-token: ${{ secrets.GITHUB_TOKEN }}
github-token: ${{ github.token }}
54 changes: 8 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![CI](https://github.com/gfx/sqldef-preview-action/actions/workflows/ci.yaml/badge.svg)](https://github.com/gfx/sqldef-preview-action/actions/workflows/ci.yaml)
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://opensource.org/licenses/MIT)

A GitHub Action that previews SQL schema migrations of [sqldef](https://github.com/sqldef/sqldef) on pull requests. It automatically generates a preview of schema changes between your base branch and PR branch, posting the DDLs as a comment on your pull request.
A GitHub Action that previews SQL schema migrations of [sqldef](https://github.com/sqldef/sqldef) on pull requests. It automatically generates a preview of schema changes between your base branch and PR branch, posting the migration DDL as a comment on your pull request.

## Features

Expand Down Expand Up @@ -69,6 +69,7 @@ jobs:
pg-user: postgres
pg-password: postgres
pg-database: testdb
github-token: ${{ github.token }}
```
### MySQL Example
Expand Down Expand Up @@ -105,6 +106,7 @@ jobs:
mysql-password: testpassword
mysql-host: 127.0.0.1
mysql-database: testdb
github-token: ${{ github.token }}
```
### SQLite Example
Expand All @@ -115,6 +117,7 @@ jobs:
command: sqlite3def
schema-file: schema/database.sql
sqlite-database: test.db
github-token: ${{ github.token }}
```
### SQL Server Example
Expand Down Expand Up @@ -160,6 +163,7 @@ jobs:
mssql-user: SA
mssql-password: YourStrong@Passw0rd
mssql-database: testdb
github-token: ${{ github.token }}
```
## Input Parameters
Expand All @@ -170,15 +174,14 @@ jobs:
|-----------|-------------|----------|
| `command` | SQLDef command to use: `psqldef`, `mysqldef`, `sqlite3def`, or `mssqldef` | ✅ |
| `schema-file` | Path to the SQL schema file | ✅ |
| `github-token` | GitHub token for commenting on pull requests | ✅ |

### Optional Parameters

| Parameter | Description | Default |
|-----------|-------------|---------|
| `version` | Version of sqldef to use (e.g., `v3.0.0` or `latest`) | `v3.0.0` |
| `baseline-schema-file` | Path to baseline schema file for comparison | Auto-fetched from base branch |
| `version` | Version of sqldef to use (e.g., `v3.0.1` or `latest`) | `v3.0.1` |
| `config-file` | Path to sqldef config file | - |
| `github-token` | GitHub token for commenting on pull requests | `${{ github.token }}` |

### PostgreSQL Parameters

Expand Down Expand Up @@ -216,47 +219,6 @@ jobs:
| `mssql-port` | SQL Server port | `1433` |
| `mssql-database` | SQL Server database name | - |

## Advanced Configuration

### Using sqldef Config Files

You can use sqldef configuration files for additional settings:

```yaml
- uses: gfx/sqldef-preview-action@v1
with:
command: psqldef
schema-file: schema/database.sql
config-file: .sqldef.yaml
# ... database connection parameters
```

### Multiple Database Types

You can test against multiple database types in parallel:

```yaml
jobs:
preview-postgresql:
# PostgreSQL configuration as shown above
preview-mysql:
# MySQL configuration as shown above
preview-sqlite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- uses: gfx/sqldef-preview-action@v1
with:
command: sqlite3def
schema-file: schema/database.sql
sqlite-database: test.db
```

## Example PR Comment

When schema changes are detected, the action posts a comment like this:
Expand All @@ -269,7 +231,7 @@ ALTER TABLE users ADD COLUMN email VARCHAR(255) NULL;
CREATE INDEX idx_users_email ON users(email);
~~~
This comment was created by sqldef-preview-action.
This comment was generated by [SQLDef Preview](https://github.com/YOUR_ORGANIZATION/YOUR_REPO/actions/runs/RUN_ID), powered by [sqldef/sqldef-preview-action](https://github.com/sqldef/sqldef-preview-action).
```

## Development
Expand Down
6 changes: 3 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: 'SQLDef Preview'
description: 'Preview schema changes using sqldef in pull requests'
description: 'Preview how sqldef migration performs in pull requests'
author: 'The sqldef team'
branding:
icon: 'database'
Expand All @@ -17,7 +17,7 @@ inputs:
version:
description: 'Version of sqldef to use'
required: false
default: 'v3.0.0'
default: 'v3.0.1'
config-file:
description: 'Path to sqldef config file'
required: false
Expand Down Expand Up @@ -83,7 +83,7 @@ inputs:
# GitHub token for PR comments
github-token:
description: 'GitHub token for commenting on pull requests'
required: false
required: true

runs:
using: 'node24'
Expand Down
Loading