forked from sqlc-dev/sqlc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmigrations.go
More file actions
39 lines (36 loc) · 929 Bytes
/
migrations.go
File metadata and controls
39 lines (36 loc) · 929 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package migrations
import (
"bufio"
"strings"
)
// Remove all lines after a rollback comment.
//
// goose: -- +goose Down
// sql-migrate: -- +migrate Down
// tern: ---- create above / drop below ----
// dbmate: -- migrate:down
func RemoveRollbackStatements(contents string) string {
s := bufio.NewScanner(strings.NewReader(contents))
var lines []string
for s.Scan() {
statement := strings.ToLower(s.Text())
if strings.HasPrefix(statement, "-- +goose down") {
break
}
if strings.HasPrefix(statement, "-- +migrate down") {
break
}
if strings.HasPrefix(statement, "---- create above / drop below ----") {
break
}
if strings.HasPrefix(statement, "-- migrate:down") {
break
}
lines = append(lines, s.Text())
}
return strings.Join(lines, "\n")
}
func IsDown(filename string) bool {
// Remove golang-migrate rollback files.
return strings.HasSuffix(filename, ".down.sql")
}