You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In ActiveRecord migrations using PostgresSQL when a table has an index defined using an expression, further renaming migrations fail because the regex to parse the index doesn't support expressions with line breaks.
This seems to be caused by PostgresSQL formatting the expression when creating the index. Move about this in the debugging area at the bottom.
In ActiveRecord migrations using PostgresSQL when a table has an index defined using an expression, further renaming migrations fail because the regex to parse the index doesn't support expressions with line breaks.
This seems to be caused by PostgresSQL formatting the expression when creating the index. Move about this in the debugging area at the bottom.
Steps to reproduce
https://gist.github.com/tiagotex/364712d6501e77456d735878568172e7
Expected behavior
Renaming a column in a table with an index with an expression should work.
Actual behavior
An exception is raised:
System configuration
Rails version:
5.0.6 and master
Ruby version:
2.4.2
Debugging
The error is raised in master/activerecord/lib/active_record/connection_adapters/postgresql/schema_statements.rb:141,
using
isnil
because of the expression on Line 110In this case
inddef
is:"CREATE UNIQUE INDEX index_posts_on_date_and_user_id ON posts (date, (\nCASE\n WHEN user_id IS NULL THEN false\n ELSE true\nEND))"
In Postgres when we set an index that contains a CASE expression, it will try to be nice and format the expression for us.
This formatting breaks the Regex. I've implemented a quick fix by using
squish
to remove new lines and extra spacing before doing the regex match:This fixes the problem. If you think this solution is good enough or have another suggestion I'm available to submit a fix.
Thank you for the awesome work 💚
The text was updated successfully, but these errors were encountered: