Skip to content

Commit c8d2f47

Browse files
authored
Handle foreign keys and indices properly in SQLite and add e2e tests (#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
1 parent fd6bc98 commit c8d2f47

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3646
-10
lines changed

.github/workflows/tests.yml

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,18 @@ jobs:
5151
MYSQL_PORT: 3307
5252
run: |
5353
go test -tags sqlite -race ./...
54+
- name: Reset soda
55+
env:
56+
SODA_DIALECT: "sqlite"
57+
run: |
58+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
59+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
60+
shell: bash
61+
- name: Run e2e
62+
env:
63+
SODA_DIALECT: "sqlite"
64+
run: |
65+
go test -tags sqlite,e2e -race ./internal/e2e/...
5466
5567
pg-tests:
5668
name: PostgreSQL tests
@@ -102,6 +114,18 @@ jobs:
102114
POSTGRESQL_URL: "postgres://postgres:postgres@${{job.services.postgres.host}}:${{ job.services.postgres.ports[5432] }}/pop_test?sslmode=disable"
103115
run: |
104116
go test -tags sqlite -race ./...
117+
- name: Reset soda
118+
env:
119+
SODA_DIALECT: "sqlite"
120+
run: |
121+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
122+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
123+
shell: bash
124+
- name: Run e2e
125+
env:
126+
SODA_DIALECT: "sqlite"
127+
run: |
128+
go test -tags sqlite,e2e -race ./internal/e2e/...
105129
106130
crdb-tests:
107131
name: Cockroach tests
@@ -147,13 +171,79 @@ jobs:
147171
SODA_DIALECT: "cockroach"
148172
run: |
149173
go test -tags sqlite -race ./...
174+
- name: Reset soda
175+
env:
176+
SODA_DIALECT: "sqlite"
177+
run: |
178+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
179+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
180+
shell: bash
181+
- name: Run e2e
182+
env:
183+
SODA_DIALECT: "sqlite"
184+
run: |
185+
go test -tags sqlite,e2e -race ./internal/e2e/...
186+
187+
sqlite-tests-windows:
188+
name: SQLite tests
189+
runs-on: ${{ matrix.os }}
190+
strategy:
191+
matrix:
192+
os: [windows-latest]
193+
steps:
194+
- name: Install sqlite3
195+
run: choco install sqlite
196+
- name: Set up Go
197+
uses: actions/setup-go@v1
198+
with:
199+
go-version: 1.13
200+
id: go
201+
- name: Checkout Code
202+
uses: actions/checkout@v1
203+
with:
204+
fetch-depth: 1
205+
- name: Get dependencies
206+
run: |
207+
go get -v -tags sqlite -t -d ./...
208+
- name: Install soda
209+
env:
210+
GO111MODULE: "off"
211+
run: |
212+
mkdir -p "$HOME/go/bin"
213+
go get -v -tags sqlite github.com/gobuffalo/soda
214+
shell: bash
215+
- name: Run soda
216+
env:
217+
SODA_DIALECT: "sqlite"
218+
run: |
219+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
220+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
221+
$HOME/go/bin/soda migrate -e $SODA_DIALECT -p ./testdata/migrations
222+
shell: bash
223+
- name: Test
224+
env:
225+
SODA_DIALECT: "sqlite"
226+
run: |
227+
go test -tags sqlite -race ./...
228+
- name: Reset soda
229+
env:
230+
SODA_DIALECT: "sqlite"
231+
run: |
232+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
233+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
234+
shell: bash
235+
- name: Run e2e
236+
env:
237+
SODA_DIALECT: "sqlite"
238+
run: |
239+
go test -tags sqlite,e2e -race ./internal/e2e/...
150240
151241
sqlite-tests:
152242
name: SQLite tests
153243
runs-on: ${{ matrix.os }}
154244
strategy:
155245
matrix:
156-
os: [ubuntu-latest, macOS-latest, windows-latest]
246+
os: [ubuntu-latest, macOS-latest]
157247

158248
steps:
159249
- name: Set up Go
@@ -188,3 +278,15 @@ jobs:
188278
SODA_DIALECT: "sqlite"
189279
run: |
190280
go test -tags sqlite -race ./...
281+
- name: Reset soda
282+
env:
283+
SODA_DIALECT: "sqlite"
284+
run: |
285+
$HOME/go/bin/soda drop -e $SODA_DIALECT -p ./testdata/migrations
286+
$HOME/go/bin/soda create -e $SODA_DIALECT -p ./testdata/migrations
287+
shell: bash
288+
- name: Run e2e
289+
env:
290+
SODA_DIALECT: "sqlite"
291+
run: |
292+
go test -tags sqlite,e2e -race ./internal/e2e/...

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,20 @@ Sometimes during a migration you need to shell out to an external command.
197197
```javascript
198198
exec("echo hello")
199199
```
200+
201+
## Development
202+
203+
### Testing
204+
205+
To run end-to-end tests, use
206+
207+
```
208+
make test
209+
```
210+
211+
If you made changes to the end-to-end tests and want to update the fixtures,
212+
run:
213+
214+
```
215+
REFRESH_FIXTURES=true make test
216+
```

database.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ sqlserver:
3232
sqlite:
3333
dialect: "sqlite3"
3434
database: "./sql_scripts/sqlite/test.sqlite"
35+
options:
36+
mode: rwc
3537

go.mod

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

0 commit comments

Comments
 (0)