Skip to content

Commit 44bcda4

Browse files
committed
[postgres] adapter was missing the custom rename_index method (fixes #577)
1 parent 001a77b commit 44bcda4

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/arjdbc/postgresql/adapter.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1067,6 +1067,10 @@ def remove_index!(table_name, index_name)
10671067
execute "DROP INDEX #{quote_table_name(index_name)}"
10681068
end
10691069

1070+
def rename_index(table_name, old_name, new_name)
1071+
execute "ALTER INDEX #{quote_column_name(old_name)} RENAME TO #{quote_table_name(new_name)}"
1072+
end
1073+
10701074
def index_name_length
10711075
63
10721076
end

test/db/postgresql/unit_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ def test_add_index
145145
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:remove_method, :index_name_exists?) if redefined
146146
end if ar_version('4.0')
147147

148+
def test_rename_index
149+
expected = "ALTER INDEX \"last_name_index\" RENAME TO \"name_index\""
150+
assert_equal expected, rename_index(:people, :last_name_index, :name_index)
151+
end # if ar_version('4.0')
152+
148153
private
149154

150155
def method_missing(method_symbol, *arguments)

0 commit comments

Comments
 (0)