Remove all lines after a rollback comment. goose: -- +goose Down sql-migrate: -- +migrate Down tern: ---- create above / drop below ---- dbmate: -- migrate:down
(contents string)
| 19 | // tern: ---- create above / drop below ---- |
| 20 | // dbmate: -- migrate:down |
| 21 | func RemoveRollbackStatements(contents string) string { |
| 22 | s := bufio.NewScanner(strings.NewReader(contents)) |
| 23 | var lines []string |
| 24 | for s.Scan() { |
| 25 | statement := strings.ToLower(s.Text()) |
| 26 | if strings.HasPrefix(statement, "-- +goose down") { |
| 27 | break |
| 28 | } |
| 29 | if strings.HasPrefix(statement, "-- +migrate down") { |
| 30 | break |
| 31 | } |
| 32 | if strings.HasPrefix(statement, "---- create above / drop below ----") { |
| 33 | break |
| 34 | } |
| 35 | if strings.HasPrefix(statement, "-- migrate:down") { |
| 36 | break |
| 37 | } |
| 38 | lines = append(lines, s.Text()) |
| 39 | } |
| 40 | return strings.Join(lines, "\n") |
| 41 | } |
| 42 | |
| 43 | // RemovePsqlMetaCommands strips psql meta-command lines (e.g. `\restrict KEY`, |
| 44 | // `\unrestrict KEY`, `\connect foo`) from SQL input. These are emitted by |