Skip to content

Commit c64e694

Browse files
committed
Partial indexes using :where in schema dumper. Fixes #153
I have altered the deal 🙏 I dont alter it any further. Furthermore, I wish you to wear this 👗 and 👶 bonnet. cc @hmadison
1 parent 6890cbb commit c64e694

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
* Every time datatype has perfect micro/nano second handling.
2323
* All supported datatypes dump defaults properly to schema.rb
24+
* Partial indexes using `:where` in schema dumper. Fixes #153
2425

2526

2627
## v4.2.6

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,13 @@ def indexes(table_name, name = nil)
3232
else
3333
name = index[:index_name]
3434
unique = index[:index_description] =~ /unique/
35+
where = select_value("SELECT [filter_definition] FROM sys.indexes WHERE name = #{quote(name)}")
3536
columns = index[:index_keys].split(',').map do |column|
3637
column.strip!
3738
column.gsub! '(-)', '' if column.ends_with?('(-)')
3839
column
3940
end
40-
indexes << IndexDefinition.new(table_name, name, unique, columns)
41+
indexes << IndexDefinition.new(table_name, name, unique, columns, nil, nil, where)
4142
end
4243
end
4344
end

test/cases/coerced_tests.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ def test_schema_dump_keeps_large_precision_integer_columns_as_decimal_coerced
601601
# This is a poorly written test and really does not catch the bottom'ness it is meant too. Ours throw it off.
602602
coerce_tests! :test_foreign_keys_are_dumped_at_the_bottom_to_circumvent_dependency_issues
603603

604+
# Fall through false positive with no filter.
605+
coerce_tests! :test_schema_dumps_partial_indices
606+
def test_schema_dumps_partial_indices_coerced
607+
index_definition = standard_dump.split(/\n/).grep(/add_index.*company_partial_index/).first.strip
608+
assert_equal 'add_index "companies", ["firm_id", "type"], name: "company_partial_index", where: "([rating]>(10))"', index_definition
609+
end
610+
604611
end
605612

606613
class SchemaDumperDefaultsTest < ActiveRecord::TestCase

0 commit comments

Comments
 (0)