Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MySQL expression index dumping with escaped quotes #49336

Merged

Conversation

fatkodima
Copy link
Member

Fixes #49334.
There was a "similar" issue previously #40822.

@Flixt
Copy link
Contributor

Flixt commented Sep 21, 2023

I have a similar problem in #42429 with expressions of check constraints.
By the amount of occurrences of this problem I start wondering if there is a bigger problem somewhere on a lower level and if we are just fixing symptoms 🤔. Do you have any deeper understanding of why this happens at all?

@fatkodima
Copy link
Member Author

For MySQL/PostgreSQL/SQLite in order to pass ' or " as a symbol in a string literal, we need to escape it (usually done by repeating the same character twice, like in 'O''Connor'), see

def quote_string(s)
s.gsub("\\", '\&\&').gsub("'", "''") # ' (for ruby-mode)
end

Then later, when we query these DBMS's for that value, it returns it quoted, as we passed it previously. If we will use these values as is, for example, in schema.rb and try to load the schema, rails will escape them again, which is incorrect. Thats why we need to remove these escapes, in all the places. I do not think there is a single place to do this.

@eileencodes eileencodes merged commit f57d54c into rails:main Sep 25, 2023
4 checks passed
@fatkodima fatkodima deleted the fix-mysql-expression-index-dumping branch September 25, 2023 18:19
rafaelfranca pushed a commit that referenced this pull request Sep 26, 2023
…umping

Fix MySQL expression index dumping with escaped quotes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect dumping of functional indices in MySQL 8.0.13+
3 participants