aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-30 21:17:22 -0300
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-30 21:17:22 -0300
commit1ea6cc11211dc89e3e14b2b641a3cca8a0a91d55 (patch)
treefa408d4a72b88eed9905f88d8608c231c6694a39 /activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
parent3d51da3964583193be6421717a2f3bfd917fbb91 (diff)
downloadrails-1ea6cc11211dc89e3e14b2b641a3cca8a0a91d55.tar.gz
rails-1ea6cc11211dc89e3e14b2b641a3cca8a0a91d55.tar.bz2
rails-1ea6cc11211dc89e3e14b2b641a3cca8a0a91d55.zip
Extract the index length validation to a auxiliar method
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb11
1 files changed, 8 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
index 6e42089801..24afd9c5da 100644
--- a/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
+++ b/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -586,9 +586,8 @@ module ActiveRecord
# rename_index :people, 'index_people_on_last_name', 'index_users_on_last_name'
#
def rename_index(table_name, old_name, new_name)
- if new_name.length > allowed_index_name_length
- raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters"
- end
+ validate_index_length!(table_name, new_name)
+
# this is a naive implementation; some DBs may support this more efficiently (Postgres, for instance)
old_index_def = indexes(table_name).detect { |i| i.name == old_name }
return unless old_index_def
@@ -995,6 +994,12 @@ module ActiveRecord
"fk_rails_#{SecureRandom.hex(5)}"
end
end
+
+ def validate_index_length!(table_name, new_name)
+ if new_name.length > allowed_index_name_length
+ raise ArgumentError, "Index name '#{new_name}' on table '#{table_name}' is too long; the limit is #{allowed_index_name_length} characters"
+ end
+ end
end
end
end