diff --git a/internal/compiler/compile.go b/internal/compiler/compile.go index 84fbb20a3c..f73db44241 100644 --- a/internal/compiler/compile.go +++ b/internal/compiler/compile.go @@ -1,6 +1,7 @@ package compiler import ( + "bufio" "errors" "fmt" "io" @@ -38,6 +39,7 @@ func (c *Compiler) parseCatalog(schemas []string) error { continue } contents := migrations.RemoveRollbackStatements(string(blob)) + contents = removePsqlMetaCommands(contents) c.schema = append(c.schema, contents) stmts, err := c.parser.Parse(strings.NewReader(contents)) if err != nil { @@ -57,6 +59,19 @@ func (c *Compiler) parseCatalog(schemas []string) error { return nil } +func removePsqlMetaCommands(contents string) string { + s := bufio.NewScanner(strings.NewReader(contents)) + var lines []string + for s.Scan() { + line := s.Text() + if strings.HasPrefix(line, `\`) { + continue + } + lines = append(lines, line) + } + return strings.Join(lines, "\n") +} + func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) { var q []*Query merr := multierr.New() diff --git a/internal/endtoend/testdata/pg_dump/schema.sql b/internal/endtoend/testdata/pg_dump/schema.sql index 06bfb9d37c..05af2a6525 100644 --- a/internal/endtoend/testdata/pg_dump/schema.sql +++ b/internal/endtoend/testdata/pg_dump/schema.sql @@ -5,6 +5,8 @@ -- Dumped from database version 15.3 (Debian 15.3-1.pgdg120+1) -- Dumped by pg_dump version 15.3 +\restrict auwherpfqaiuwrhgp + SET statement_timeout = 0; SET lock_timeout = 0; SET idle_in_transaction_session_timeout = 0;

AltStyle によって変換されたページ (->オリジナル) /