dbmate icon indicating copy to clipboard operation
dbmate copied to clipboard

[pg] \restrict header + footer fix

Open drew-u410 opened this issue 4 months ago • 3 comments

  • In postgres: 17.6 it looks like a \restrict header was added to pg_dump output.
    • Discussed in the release notes here: https://www.postgresql.org/docs/release/17.6/ under "Prevent pg_dump scripts from being used to attack the user running the restore (Nathan Bossart) §"
    • Change here: https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=575f54d4c
  • In using dbmate, it seems to be quite confused trying to parse these files with this \restrict header in them.
  • The TrimLeadingSQLComments looks like maybe the best place to update and also trim these out.
  • Confusingly, this change to pg_dump also ends a file with \unrestrict causing an issue parsing at the end too.

--

  • The mysql test failure seems unrelated?

drew-u410 avatar Aug 21 '25 15:08 drew-u410

The MySQL test failure is due to this:

https://github.com/amacneil/dbmate/pull/673#issuecomment-3197769135

dossy avatar Aug 21 '25 15:08 dossy

Disappointed that they didn't implement this with \set restrict <key> and \unset restrict which would have been 100% backwards compatible.

I'm not sure I like the idea of filtering all possible (future) meta-commands from pg_dump output vs. only removing \restrict and \unrestrict` because who knows what else will break in the future.

I also don't like the idea of filtering them out at all: if you're using a version of Postgres 17.6+ and it emits these, you are responsible for loading these into a version of Postgres that understands them, or removing them yourself. I don't think dbmate should be interfering with the output of the dump tool the user is using.

I feel like the right move here is to make dbmate's SQL parser smarter enough to not choke on what Postgres deems valid input to its own tools, and not filter them out.

Maybe I'm not quite understanding the issue, so if anyone else has thoughts, please chime in.

dossy avatar Aug 21 '25 16:08 dossy

Yea- I truly wasn't sure. Feel free to discard / approach differently.

It just totally broke and I felt compelled to at least propose some solution for discussion.

drew-u410 avatar Aug 21 '25 16:08 drew-u410