Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions internal/migrations/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var psqlMetaCommand = regexp.MustCompile(`^\\[A-Za-z!?;][^\n]*$`)
// dbmate: -- migrate:down
func RemoveRollbackStatements(contents string) string {
s := bufio.NewScanner(strings.NewReader(contents))
s.Buffer(nil, len(contents)+1)
var lines []string
for s.Scan() {
statement := strings.ToLower(s.Text())
Expand All @@ -45,6 +46,7 @@ func RemoveRollbackStatements(contents string) string {
// pg_dump but are not valid SQL, so they must be removed before parsing.
func RemovePsqlMetaCommands(contents string) string {
s := bufio.NewScanner(strings.NewReader(contents))
s.Buffer(nil, len(contents)+1)
var lines []string
for s.Scan() {
line := s.Text()
Expand Down
12 changes: 12 additions & 0 deletions internal/migrations/migrations_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package migrations

import (
"strings"
"testing"

"github.com/google/go-cmp/cmp"
Expand Down Expand Up @@ -105,3 +106,14 @@ func TestRemoveGolangMigrateRollback(t *testing.T) {
}
}
}

func TestRemoveLongLines(t *testing.T) {
long := "INSERT INTO blobs VALUES ('" + strings.Repeat("x", 100_000) + "');"
input := "CREATE TABLE blobs (data text);\n" + long + "\nCREATE TABLE after (id int);"
if diff := cmp.Diff(input, RemoveRollbackStatements(input)); diff != "" {
t.Errorf("RemoveRollbackStatements mismatch:\n%s", diff)
}
if diff := cmp.Diff(input, RemovePsqlMetaCommands(input)); diff != "" {
t.Errorf("RemovePsqlMetaCommands mismatch:\n%s", diff)
}
}
Loading