File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed 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
4
4
5
5
- [ goose] ( https://github.com/pressly/goose )
6
6
- [ sql-migrate] ( https://github.com/rubenv/sql-migrate )
7
+ - [ tern] ( https://github.com/jackc/tern )
7
8
8
9
## goose
9
10
@@ -50,3 +51,20 @@ type People struct {
50
51
ID int32
51
52
}
52
53
```
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 9
9
//
10
10
// goose: -- +goose Down
11
11
// sql-migrate: -- +migrate Down
12
+ // tern: ---- create above / drop below ----
12
13
func RemoveRollbackStatements (contents string ) string {
13
14
s := bufio .NewScanner (strings .NewReader (contents ))
14
15
var lines []string
@@ -19,6 +20,9 @@ func RemoveRollbackStatements(contents string) string {
19
20
if strings .HasPrefix (s .Text (), "-- +migrate Down" ) {
20
21
break
21
22
}
23
+ if strings .HasPrefix (s .Text (), "---- create above / drop below ----" ) {
24
+ break
25
+ }
22
26
lines = append (lines , s .Text ())
23
27
}
24
28
return strings .Join (lines , "\n " )
Original file line number Diff line number Diff line change @@ -35,11 +35,25 @@ const outputMigrate = `
35
35
CREATE TABLE people (id int);
36
36
`
37
37
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
+
38
49
func TestRemoveRollback (t * testing.T ) {
39
50
if diff := cmp .Diff (outputGoose , RemoveRollbackStatements (inputGoose )); diff != "" {
40
51
t .Errorf ("goose migration mismatch:\n %s" , diff )
41
52
}
42
53
if diff := cmp .Diff (outputMigrate , RemoveRollbackStatements (inputMigrate )); diff != "" {
43
54
t .Errorf ("sql-migrate migration mismatch:\n %s" , diff )
44
55
}
56
+ if diff := cmp .Diff (outputTern , RemoveRollbackStatements (inputTern )); diff != "" {
57
+ t .Errorf ("tern migration mismatch:\n %s" , diff )
58
+ }
45
59
}
You can’t perform that action at this time.
0 commit comments