MSP-8976 Up deps

This commit is contained in:
Иван Перлов committed 2026-11-20 17:19:44 +03:00
1 parent b8ef777339
commit 11d705124d
603 files changed
+47715 -13202

No files matched your search

+13 -37
View File
@@ -9,7 +9,6 @@ import (
"log"
"os"
"strings"
"sync"
"github.com/mfridman/interpolate"
)
@@ -81,14 +80,8 @@ func (s *stateMachine) print(msg string, args ...any) {
}
}
const scanBufSize = 4 * 1024 * 1024
var bufferPool = sync.Pool{
New: func() any {
buf := make([]byte, scanBufSize)
return &buf
},
}
// scanBufSize is the maximum length of a single line in a migration file.
const scanBufSize = 4 * 1024 * 1024 // 4 MiB
// Split given SQL script into individual statements and return
// SQL statements for given direction (up=true, down=false).
@@ -101,12 +94,11 @@ var bufferPool = sync.Pool{
// 'StatementBegin' and 'StatementEnd' to allow the script to
// tell us to ignore semicolons.
func ParseSQLMigration(r io.Reader, direction Direction, debug bool) (stmts []string, useTx bool, err error) {
scanBufPtr := bufferPool.Get().(*[]byte)
scanBuf := *scanBufPtr
defer bufferPool.Put(scanBufPtr)
scanner := bufio.NewScanner(r)
scanner.Buffer(scanBuf, scanBufSize)
// A nil buffer makes the scanner allocate its default 4 KiB buffer and grow
// it, up to scanBufSize, only when a line needs it. Most migration files are
// a few KiB, so a large fixed buffer per call would be mostly wasted.
scanner.Buffer(nil, scanBufSize)
stateMachine := newStateMachine(start, debug)
useTx = true
@@ -209,16 +201,15 @@ func ParseSQLMigration(r io.Reader, direction Direction, debug bool) (stmts []st
// Do not include the "+goose StatementEnd" annotation in the final statement.
default:
if useEnvsub {
expanded, err := interpolate.Interpolate(&envWrapper{}, line)
expanded, err := interpolate.Expand(line, interpolate.LookupFunc(os.LookupEnv))
if err != nil {
return nil, false, fmt.Errorf("variable substitution failed: %w:\n%s", err, line)
}
line = expanded
}
// Write SQL line to a buffer.
if _, err := buf.WriteString(line + "\n"); err != nil {
return nil, false, fmt.Errorf("failed to write to buf: %w", err)
}
buf.WriteString(line)
buf.WriteByte('\n')
}
// Read SQL body one by line, if we're in the right direction.
//
@@ -358,37 +349,22 @@ func missingSemicolonError(state parserState, direction Direction, s string) err
)
}
type envWrapper struct{}
var _ interpolate.Env = (*envWrapper)(nil)
func (e *envWrapper) Get(key string) (string, bool) {
return os.LookupEnv(key)
}
func cleanupStatement(input string) string {
return strings.TrimSpace(input)
}
// Checks the line to see if the line has a statement-ending semicolon
// or if the line contains a double-dash comment.
//
// The line is split into words on Unicode whitespace, the same way
// bufio.ScanWords does, and the words before the first "--" are inspected.
func endsWithSemicolon(line string) bool {
scanBufPtr := bufferPool.Get().(*[]byte)
scanBuf := *scanBufPtr
defer bufferPool.Put(scanBufPtr)
prev := ""
scanner := bufio.NewScanner(strings.NewReader(line))
scanner.Buffer(scanBuf, scanBufSize)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
word := scanner.Text()
for word := range strings.FieldsSeq(line) {
if strings.HasPrefix(word, "--") {
break
}
prev = word
}
return strings.HasSuffix(prev, ";")
}