File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,8 +65,8 @@ DROP TABLE comment;
6565package db
6666
6767type Comment struct {
68- ID int32
69- Text string
68+ ID int32
69+ Text string
7070}
7171```
7272
@@ -84,6 +84,7 @@ CREATE TABLE post (
8484```
8585
8686In ` 20060102.down.sql ` :
87+
8788``` sql
8889DROP TABLE post;
8990```
@@ -97,3 +98,21 @@ type Post struct {
9798 Body sql.NullString
9899}
99100```
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 99//
1010// goose: -- +goose Down
1111// sql-migrate: -- +migrate Down
12- // tern: ---- create above / drop below ----
12+ // tern: ---- create above / drop below ----
13+ // dbmate: -- migrate:down
1314func RemoveRollbackStatements (contents string ) string {
1415 s := bufio .NewScanner (strings .NewReader (contents ))
1516 var lines []string
@@ -23,6 +24,9 @@ func RemoveRollbackStatements(contents string) string {
2324 if strings .HasPrefix (s .Text (), "---- create above / drop below ----" ) {
2425 break
2526 }
27+ if strings .HasPrefix (s .Text (), "-- migrate:down" ) {
28+ break
29+ }
2630 lines = append (lines , s .Text ())
2731 }
2832 return strings .Join (lines , "\n " )
Original file line number Diff line number Diff line change @@ -46,6 +46,16 @@ const outputTern = `
4646-- Write your migrate up statements here
4747ALTER TABLE todo RENAME COLUMN done TO is_done;`
4848
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+
4959func TestRemoveRollback (t * testing.T ) {
5060 if diff := cmp .Diff (outputGoose , RemoveRollbackStatements (inputGoose )); diff != "" {
5161 t .Errorf ("goose migration mismatch:\n %s" , diff )
@@ -56,6 +66,9 @@ func TestRemoveRollback(t *testing.T) {
5666 if diff := cmp .Diff (outputTern , RemoveRollbackStatements (inputTern )); diff != "" {
5767 t .Errorf ("tern migration mismatch:\n %s" , diff )
5868 }
69+ if diff := cmp .Diff (outputDbmate , RemoveRollbackStatements (inputDbmate )); diff != "" {
70+ t .Errorf ("dbmate migration mismatch:\n %s" , diff )
71+ }
5972}
6073
6174func TestRemoveGolangMigrateRollback (t * testing.T ) {
You can’t perform that action at this time.
0 commit comments