Skip to content

Commit

Permalink
Handle foreign keys and indices properly in SQLite and add e2e tests (#…
Browse files Browse the repository at this point in the history
…94)

This patch resolves issues with `change_column` and `drop_column` which previously caused duplicate or missing indices and foreign keys. To prevent future regressions and help debugging,
a new e2e-test pipeline has been added to the project and the CI. Documentation for running the tests has been added to the README.

End-to-end tests currently support MySQL, PostgreSQL, and SQLite and do not yet cover other SQL dialects.

During review, please help ensure that the SQL fixtures are not missing something :)

Closes #92
  • Loading branch information
aeneasr authored Jun 23, 2020
1 parent fd6bc98 commit c8d2f47
Show file tree
Hide file tree
Showing 88 changed files with 3,646 additions and 10 deletions.
104 changes: 103 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@ jobs:
MYSQL_PORT: 3307
run: |
go test -tags sqlite -race ./...
- name: Reset soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Run e2e
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite,e2e -race ./internal/e2e/...
pg-tests:
name: PostgreSQL tests
Expand Down Expand Up @@ -102,6 +114,18 @@ jobs:
POSTGRESQL_URL: "postgres://postgres:postgres@${{job.services.postgres.host}}:${{ job.services.postgres.ports[5432] }}/pop_test?sslmode=disable"
run: |
go test -tags sqlite -race ./...
- name: Reset soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Run e2e
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite,e2e -race ./internal/e2e/...
crdb-tests:
name: Cockroach tests
Expand Down Expand Up @@ -147,13 +171,79 @@ jobs:
SODA_DIALECT: "cockroach"
run: |
go test -tags sqlite -race ./...
- name: Reset soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Run e2e
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite,e2e -race ./internal/e2e/...
sqlite-tests-windows:
name: SQLite tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
steps:
- name: Install sqlite3
run: choco install sqlite
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
id: go
- name: Checkout Code
uses: actions/checkout@v1
with:
fetch-depth: 1
- name: Get dependencies
run: |
go get -v -tags sqlite -t -d ./...
- name: Install soda
env:
GO111MODULE: "off"
run: |
mkdir -p "$HOME/go/bin"
go get -v -tags sqlite github.com/gobuffalo/soda
shell: bash
- name: Run soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda migrate -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Test
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite -race ./...
- name: Reset soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Run e2e
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite,e2e -race ./internal/e2e/...
sqlite-tests:
name: SQLite tests
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
os: [ubuntu-latest, macOS-latest]

steps:
- name: Set up Go
Expand Down Expand Up @@ -188,3 +278,15 @@ jobs:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite -race ./...
- name: Reset soda
env:
SODA_DIALECT: "sqlite"
run: |
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
shell: bash
- name: Run e2e
env:
SODA_DIALECT: "sqlite"
run: |
go test -tags sqlite,e2e -race ./internal/e2e/...
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,3 +197,20 @@ Sometimes during a migration you need to shell out to an external command.
```javascript
exec("echo hello")
```

## Development

### Testing

To run end-to-end tests, use

```
make test
```

If you made changes to the end-to-end tests and want to update the fixtures,
run:

```
REFRESH_FIXTURES=true make test
```
2 changes: 2 additions & 0 deletions database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ sqlserver:
sqlite:
dialect: "sqlite3"
database: "./sql_scripts/sqlite/test.sqlite"
options:
mode: rwc

11 changes: 6 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ require (
github.com/Masterminds/semver/v3 v3.0.3
github.com/go-sql-driver/mysql v1.5.0
github.com/gobuffalo/plush/v4 v4.0.0
github.com/gobuffalo/pop/v5 v5.2.0
github.com/jackc/pgx/v4 v4.6.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kr/pretty v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20190813141303-74dc4d7220e7 // indirect
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
gopkg.in/yaml.v2 v2.2.8 // indirect
github.com/stretchr/testify v1.5.1
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
golang.org/x/text v0.3.3 // indirect
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 // indirect
)
Loading

0 comments on commit c8d2f47

Please sign in to comment.