Skip to content

Commit add24a3

Browse files
Merge pull request #9 from wpolicarpo/fix-schema-dumper-tests
Fix SchemaDumper tests
2 parents cc86d04 + 359a90c commit add24a3

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

lib/active_record/connection_adapters/sqlserver/schema_statements.rb

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,33 @@ def drop_table(table_name, options = {})
3232
end
3333
end
3434

35-
def indexes(table_name, name = nil)
36-
data = select("EXEC sp_helpindex #{quote(table_name)}", name) rescue []
35+
def indexes(table_name)
36+
data = select("EXEC sp_helpindex #{quote(table_name)}", "SCHEMA") rescue []
37+
3738
data.reduce([]) do |indexes, index|
3839
index = index.with_indifferent_access
40+
3941
if index[:index_description] =~ /primary key/
4042
indexes
4143
else
4244
name = index[:index_name]
4345
unique = index[:index_description] =~ /unique/
4446
where = select_value("SELECT [filter_definition] FROM sys.indexes WHERE name = #{quote(name)}")
45-
columns = index[:index_keys].split(',').map do |column|
47+
orders = {}
48+
columns = []
49+
50+
index[:index_keys].split(',').each do |column|
4651
column.strip!
47-
column.gsub! '(-)', '' if column.ends_with?('(-)')
48-
column
52+
53+
if column.ends_with?('(-)')
54+
column.gsub! '(-)', ''
55+
orders[column] = :desc
56+
end
57+
58+
columns << column
4959
end
50-
indexes << IndexDefinition.new(table_name, name, unique, columns, where: where)
60+
61+
indexes << IndexDefinition.new(table_name, name, unique, columns, where: where, orders: orders)
5162
end
5263
end
5364
end

0 commit comments

Comments
 (0)