File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ sqlc will ignore rollback statements when parsing migration SQL files. The follo
44
55- [ goose] ( https://github.com/pressly/goose )
66- [ sql-migrate] ( https://github.com/rubenv/sql-migrate )
7+ - [ tern] ( https://github.com/jackc/tern )
78
89## goose
910
@@ -50,3 +51,20 @@ type People struct {
5051 ID int32
5152}
5253```
54+
55+ ### tern
56+
57+ ``` sql
58+ CREATE TABLE comment (id int NOT NULL , text text NOT NULL );
59+ -- -- create above / drop below ----
60+ DROP TABLE comment;
61+ ```
62+
63+ ``` go
64+ package db
65+
66+ type Comment struct {
67+ ID int32
68+ Text string
69+ }
70+ ```
Original file line number Diff line number Diff line change 99//
1010// goose: -- +goose Down
1111// sql-migrate: -- +migrate Down
12+ // tern: ---- create above / drop below ----
1213func RemoveRollbackStatements (contents string ) string {
1314 s := bufio .NewScanner (strings .NewReader (contents ))
1415 var lines []string
@@ -19,6 +20,9 @@ func RemoveRollbackStatements(contents string) string {
1920 if strings .HasPrefix (s .Text (), "-- +migrate Down" ) {
2021 break
2122 }
23+ if strings .HasPrefix (s .Text (), "---- create above / drop below ----" ) {
24+ break
25+ }
2226 lines = append (lines , s .Text ())
2327 }
2428 return strings .Join (lines , "\n " )
Original file line number Diff line number Diff line change @@ -35,11 +35,25 @@ const outputMigrate = `
3535CREATE TABLE people (id int);
3636`
3737
38+ const inputTern = `
39+ -- Write your migrate up statements here
40+ ALTER TABLE todo RENAME COLUMN done TO is_done;
41+ ---- create above / drop below ----
42+ ALTER TABLE todo RENAME COLUMN is_done TO done;
43+ `
44+
45+ const outputTern = `
46+ -- Write your migrate up statements here
47+ ALTER TABLE todo RENAME COLUMN done TO is_done;`
48+
3849func TestRemoveRollback (t * testing.T ) {
3950 if diff := cmp .Diff (outputGoose , RemoveRollbackStatements (inputGoose )); diff != "" {
4051 t .Errorf ("goose migration mismatch:\n %s" , diff )
4152 }
4253 if diff := cmp .Diff (outputMigrate , RemoveRollbackStatements (inputMigrate )); diff != "" {
4354 t .Errorf ("sql-migrate migration mismatch:\n %s" , diff )
4455 }
56+ if diff := cmp .Diff (outputTern , RemoveRollbackStatements (inputTern )); diff != "" {
57+ t .Errorf ("tern migration mismatch:\n %s" , diff )
58+ }
4559}
You can’t perform that action at this time.
0 commit comments