Skip to content

Commit f445838

Browse files
authored
Merge pull request rails#53570 from fatkodima/fix-sqlite3-partial-indexes-with-comments
Fix retrieving partial indexes with comments for SQLite
2 parents 3431225 + d7349cc commit f445838

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

activerecord/lib/active_record/connection_adapters/sqlite3/schema_statements.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def indexes(table_name)
2727
col["name"]
2828
end
2929

30+
where = where.sub(/\s*\/\*.*\*\/\z/, "") if where
3031
orders = {}
3132

3233
if columns.any?(&:nil?) # index created with an expression

activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,15 @@ def test_compound_index
698698
end
699699
end
700700

701+
def test_partial_index_with_comment
702+
with_example_table do
703+
@conn.add_index "ex", :id, name: "fun", where: "number > 0 /*tag:test*/"
704+
index = @conn.indexes("ex").find { |idx| idx.name == "fun" }
705+
assert_equal ["id"], index.columns
706+
assert_equal "number > 0", index.where
707+
end
708+
end
709+
701710
if ActiveRecord::Base.lease_connection.supports_expression_index?
702711
def test_expression_index
703712
with_example_table do

0 commit comments

Comments
 (0)