File tree Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Expand file tree Collapse file tree 3 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -65,8 +65,8 @@ DROP TABLE comment;
65
65
package db
66
66
67
67
type Comment struct {
68
- ID int32
69
- Text string
68
+ ID int32
69
+ Text string
70
70
}
71
71
```
72
72
@@ -84,6 +84,7 @@ CREATE TABLE post (
84
84
```
85
85
86
86
In ` 20060102.down.sql ` :
87
+
87
88
``` sql
88
89
DROP TABLE post;
89
90
```
@@ -97,3 +98,21 @@ type Post struct {
97
98
Body sql.NullString
98
99
}
99
100
```
101
+
102
+ ## dbmate
103
+
104
+ ``` sql
105
+ -- migrate:up
106
+ CREATE TABLE foo (bar INT NOT NULL );
107
+
108
+ -- migrate:down
109
+ DROP TABLE foo;
110
+ ```
111
+
112
+ ``` go
113
+ package db
114
+
115
+ type Foo struct {
116
+ Bar int32
117
+ }
118
+ ```
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
+ // tern: ---- create above / drop below ----
13
+ // dbmate: -- migrate:down
13
14
func RemoveRollbackStatements (contents string ) string {
14
15
s := bufio .NewScanner (strings .NewReader (contents ))
15
16
var lines []string
@@ -23,6 +24,9 @@ func RemoveRollbackStatements(contents string) string {
23
24
if strings .HasPrefix (s .Text (), "---- create above / drop below ----" ) {
24
25
break
25
26
}
27
+ if strings .HasPrefix (s .Text (), "-- migrate:down" ) {
28
+ break
29
+ }
26
30
lines = append (lines , s .Text ())
27
31
}
28
32
return strings .Join (lines , "\n " )
Original file line number Diff line number Diff line change @@ -46,6 +46,16 @@ const outputTern = `
46
46
-- Write your migrate up statements here
47
47
ALTER TABLE todo RENAME COLUMN done TO is_done;`
48
48
49
+ const inputDbmate = `
50
+ -- migrate:up
51
+ CREATE TABLE foo (bar int);
52
+ -- migrate:down
53
+ DROP TABLE foo;`
54
+
55
+ const outputDbmate = `
56
+ -- migrate:up
57
+ CREATE TABLE foo (bar int);`
58
+
49
59
func TestRemoveRollback (t * testing.T ) {
50
60
if diff := cmp .Diff (outputGoose , RemoveRollbackStatements (inputGoose )); diff != "" {
51
61
t .Errorf ("goose migration mismatch:\n %s" , diff )
@@ -56,6 +66,9 @@ func TestRemoveRollback(t *testing.T) {
56
66
if diff := cmp .Diff (outputTern , RemoveRollbackStatements (inputTern )); diff != "" {
57
67
t .Errorf ("tern migration mismatch:\n %s" , diff )
58
68
}
69
+ if diff := cmp .Diff (outputDbmate , RemoveRollbackStatements (inputDbmate )); diff != "" {
70
+ t .Errorf ("dbmate migration mismatch:\n %s" , diff )
71
+ }
59
72
}
60
73
61
74
func TestRemoveGolangMigrateRollback (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments