(schemas []string)
| 27 | } |
| 28 | |
| 29 | func (c *Compiler) parseCatalog(schemas []string) error { |
| 30 | files, err := sqlpath.Glob(schemas) |
| 31 | if err != nil { |
| 32 | return err |
| 33 | } |
| 34 | merr := multierr.New() |
| 35 | for _, filename := range files { |
| 36 | blob, err := os.ReadFile(filename) |
| 37 | if err != nil { |
| 38 | merr.Add(filename, "", 0, err) |
| 39 | continue |
| 40 | } |
| 41 | contents := migrations.RemoveRollbackStatements(string(blob)) |
| 42 | contents = migrations.RemovePsqlMetaCommands(contents) |
| 43 | c.schema = append(c.schema, contents) |
| 44 | |
| 45 | // In database-only mode, we parse the schema to validate syntax |
| 46 | // but don't update the catalog - the database will be the source of truth |
| 47 | stmts, err := c.parser.Parse(strings.NewReader(contents)) |
| 48 | if err != nil { |
| 49 | merr.Add(filename, contents, 0, err) |
| 50 | continue |
| 51 | } |
| 52 | |
| 53 | // Skip catalog updates in database-only mode |
| 54 | if c.databaseOnlyMode { |
| 55 | continue |
| 56 | } |
| 57 | |
| 58 | for i := range stmts { |
| 59 | if err := c.catalog.Update(stmts[i], c); err != nil { |
| 60 | merr.Add(filename, contents, stmts[i].Pos(), err) |
| 61 | continue |
| 62 | } |
| 63 | } |
| 64 | } |
| 65 | if len(merr.Errs()) > 0 { |
| 66 | return merr |
| 67 | } |
| 68 | return nil |
| 69 | } |
| 70 | |
| 71 | func (c *Compiler) parseQueries(o opts.Parser) (*Result, error) { |
| 72 | ctx := context.Background() |
no test coverage detected