RemovePsqlMetaCommands strips psql meta-command lines (e.g. `\restrict KEY`, `\unrestrict KEY`, `\connect foo`) from SQL input. These are emitted by pg_dump but are not valid SQL, so they must be removed before parsing.
(contents string)
| 44 | // `\unrestrict KEY`, `\connect foo`) from SQL input. These are emitted by |
| 45 | // pg_dump but are not valid SQL, so they must be removed before parsing. |
| 46 | func RemovePsqlMetaCommands(contents string) string { |
| 47 | s := bufio.NewScanner(strings.NewReader(contents)) |
| 48 | var lines []string |
| 49 | for s.Scan() { |
| 50 | line := s.Text() |
| 51 | if psqlMetaCommand.MatchString(line) { |
| 52 | continue |
| 53 | } |
| 54 | lines = append(lines, line) |
| 55 | } |
| 56 | return strings.Join(lines, "\n") |
| 57 | } |
| 58 | |
| 59 | func IsDown(filename string) bool { |
| 60 | // Remove golang-migrate rollback files. |