MCPcopy
hub / github.com/sqlc-dev/sqlc / RemoveRollbackStatements

Function RemoveRollbackStatements

internal/migrations/migrations.go:21–41  ·  view source on GitHub ↗

Remove all lines after a rollback comment. goose: -- +goose Down sql-migrate: -- +migrate Down tern: ---- create above / drop below ---- dbmate: -- migrate:down

(contents string)

Source from the content-addressed store, hash-verified

19// tern: ---- create above / drop below ----
20// dbmate: -- migrate:down
21func 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

Callers 6

parseCatalogMethod · 0.92
VerifyFunction · 0.92
fetchDatabaseUriMethod · 0.92
checkSQLMethod · 0.92
CreateDBFunction · 0.92
TestRemoveRollbackFunction · 0.85

Calls 2

ScanMethod · 0.45
JoinMethod · 0.45

Tested by 1

TestRemoveRollbackFunction · 0.68