From f02ecc47785c5af04b103d1785242afae3752268 Mon Sep 17 00:00:00 2001 From: Eric Moss Date: Wed, 25 Nov 2026 15:57:08 -0500 Subject: [PATCH] migrate: fix the red CI on master Remove migrate/code.go: codeOf, isComment, lineDiff and maxDiffLines have no caller, so the unused linter failed every run. The work stays in efc15bd for when the code-only checksum is wired in. TestRequireWait opened the pool's first connection inside its 150ms deadline, so a slow runner spent the deadline connecting and the first check failed before it could report ErrBehind. The pool is pinged first, so the deadline times the wait alone. Co-Authored-By: Claude Opus 5.5 --- migrate/code.go | 76 ----------------------------------------- migrate/require_test.go | 3 ++ 2 files changed, 3 insertions(+), 76 deletions(-) delete mode 100644 migrate/code.go diff --git a/migrate/code.go b/migrate/code.go deleted file mode 100644 index a0b38e4..0000000 --- a/migrate/code.go +++ /dev/null @@ -1,76 +0,0 @@ -package migrate - -import ( - "fmt" - "strings" -) - -// maxDiffLines bounds the lines of each side a diff shows, so a rewritten file stays readable in -// an error message. -const maxDiffLines = 40 - -// codeOf returns what sql runs: its --keel: directives and its text without comments, with each -// run of whitespace outside a literal reduced to one space. Two files with the same code differ -// only in ways the server cannot see, so its checksum tells a comment or formatting edit from one -// that changes the migration. String, dollar-quoted and quoted-identifier text is kept as written, -// comments inside a function body included, since that text reaches the server. -func codeOf(sql string) string { - var b strings.Builder - for _, ln := range lex(sql).lines { - if text := strings.TrimSpace(ln.text); ln.code && strings.HasPrefix(text, "--keel:") { - b.WriteString(strings.Join(strings.Fields(text), " ")) - b.WriteByte('\n') - } - } - s := &scanner{src: sql, out: []byte(sql), code: true} - gap := false - for s.i < len(sql) { - from, state := s.i, s.state - s.step() - switch { - case isComment(state) || isComment(s.state): - gap = true - case state == lexCode && s.state == lexCode && strings.TrimSpace(sql[from:s.i]) == "": - gap = true - default: - if gap && b.Len() > 0 { - b.WriteByte(' ') - } - gap = false - b.WriteString(sql[from:s.i]) - } - } - return b.String() -} - -// isComment reports whether state is inside a comment. -func isComment(state lexState) bool { - return state == lexLineComment || state == lexBlockComment -} - -// lineDiff shows the lines that differ between two texts, without the lines they share at the -// start and end: "- " for a line of before, "+ " for a line of after, each side capped. -func lineDiff(before, after string) string { - a, b := strings.Split(before, "\n"), strings.Split(after, "\n") - start := 0 - for start < len(a) && start < len(b) && a[start] == b[start] { - start++ - } - end := 0 - for end < len(a)-start && end < len(b)-start && a[len(a)-1-end] == b[len(b)-1-end] { - end++ - } - var out strings.Builder - side := func(sign string, lines []string) { - for i, line := range lines { - if i == maxDiffLines { - fmt.Fprintf(&out, " %s … %d more lines\n", sign, len(lines)-i) - return - } - fmt.Fprintf(&out, " %s %s\n", sign, line) - } - } - side("-", a[start:len(a)-end]) - side("+", b[start:len(b)-end]) - return strings.TrimRight(out.String(), "\n") -} diff --git a/migrate/require_test.go b/migrate/require_test.go index 357c450..5012d36 100644 --- a/migrate/require_test.go +++ b/migrate/require_test.go @@ -57,6 +57,9 @@ func TestRequireWait(t *testing.T) { t.Fatal(err) } defer pool.Close() + if err := pool.Ping(ctx); err != nil { + t.Fatal(err) + } short, cancel := context.WithTimeout(ctx, 150*time.Millisecond) defer cancel()