Static mz_mysql_util::privileges::GRANT_REGEX

source ยท
static GRANT_REGEX: LazyLock<Regex>
Expand description

Regex to parse a SHOW GRANTS line. Inspired by several stack overflow posts and adjusted to account for the different quoting styles across MySQL versions. If this regex matches then this is a grant on an actual object which looks like: GRANT SELECT, INSERT, UPDATE ON db1.* TO u1@localhost GRANT SELECT ON db1.table1 TO my_user@localhost WITH GRANT OPTION The regex needs to account for the possibility of a wildcard schema or table, and for the quote-char to be part of the table/schema name too. Group 1 is the list of privileges being granted Group 2 is either the wildcard * or a quoted database/schema Group 4 is the unquoted database/schema when the wildcard is not matched Group 5 is either the wildcard * or a quoted table Group 7 is the unquoted table when the wildcard is not matched Group 9 is the user being granted We use the fancy_regex crate to allow backreferences which are necessary to find the ending quote of each identifier since there are different quoting types across mysql versions.