-
Notifications
You must be signed in to change notification settings - Fork 53
fix: handle indexes with a hidden compound #345
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
Conversation
c36330f to
93526f5
Compare
4c9aa0a to
af51719
Compare
af51719 to
9f56778
Compare
This fixes regional related parts, hence fixes #344
9f56778 to
9204637
Compare
| return super unless database_version >= 24_02_02 | ||
|
|
||
| Hash[query(<<~SQL, "SCHEMA")].values_at(*column_numbers).compact | ||
| SELECT a.attnum, a.attname | ||
| FROM pg_attribute a | ||
| WHERE a.attrelid = #{table_oid} | ||
| AND a.attnum IN (#{column_numbers.join(", ")}) | ||
| AND NOT a.attishidden | ||
| SQL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not specific to CRDB >= 24.0.2. On 24.1.2 unique constraints on a region by row table will combine the crdb_region and column on the dumped schema. Since attishidden is not available in CRDB 24.1.2 this seems to do the trick:
def column_names_from_column_numbers(table_oid, column_numbers)
Hash[query(<<~SQL, "SCHEMA")].values_at(*column_numbers).compact
SELECT a.attnum, a.attname
FROM pg_attribute a
WHERE a.attrelid = #{table_oid}
AND a.attnum IN (#{column_numbers.join(", ")})
AND a.attisdropped <> 't'
AND a.attname <> 'crdb_region'
SQL
endWithout attisdropped <> t, I see weird ....pg.dropped.18... strings in the schema dump. All this is happening after upgrade to Rails 7.1.x and Cockroach AR Adapter 7.1.x. I can't reproduce it on Rails 7.0.x.
When it comes to unique_constraints, I also see a problem with indexes with expressions. For example:
t.index "lower(name::STRING) ASC", name: "index_table_name_redacted_on_name_unique", unique: trueis becoming:
t.unique_constraint [], name: "index_table_name_redacted_on_name_unique"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue with a workaround for unique_constraint here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmalek-sa I'm not targetting 24.0.2 but 24.2.2, which is the version where the related issue started raising. We do not need this patch before (hence the conditionnal!)
Also crdb_region is not the only issue, see the tests in this PR they are targetting hash sharded indexes!
EDIT: I understand now there is a second issue. I'll answer in the issue, and I'd rather solve it in a different PR so that we can ship this one quicker as it is blocking migrations for some users of 24.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, thanks for identifying the fix!
This fixes regional related parts, hence fixes #344