aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
diff options
context:
space:
mode:
authorYves Senn <yves.senn@gmail.com>2012-12-28 01:27:26 +0100
committerYves Senn <yves.senn@gmail.com>2013-02-20 17:50:10 +0100
commitcca43528d40589556401408eb3c315cde199347c (patch)
treecd2794639db357bbb140e2263eb233f88cb4ff47 /activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
parent7bae72c69f2352fd7e02f2d08adf873e4354aea0 (diff)
downloadrails-cca43528d40589556401408eb3c315cde199347c.tar.gz
rails-cca43528d40589556401408eb3c315cde199347c.tar.bz2
rails-cca43528d40589556401408eb3c315cde199347c.zip
reserve index name chars for internal rails operations
Some adapter (SQLite3) need to perform renaming operations to support the rails DDL. These rename prefixes operate with prefixes. When an index name already uses up the full space provieded by `index_name_length` these internal operations will fail. This patch introduces `allowed_index_name_length` which respects the amount of characters used for internal operations. It will always be <= `index_name_length` and every adapter can define how many characters need to be reserved.
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb9
1 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
index 91444950be..1b93af5033 100644
--- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
+++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb
@@ -187,6 +187,13 @@ module ActiveRecord
true
end
+ # Returns 51. SQLite supports index names up to 64
+ # characters. The rest is used by rails internally to perform
+ # temporary rename operations
+ def allowed_index_name_length
+ index_name_length - 13
+ end
+
def native_database_types #:nodoc:
{
:primary_key => default_primary_key_type,
@@ -559,7 +566,7 @@ module ActiveRecord
unless columns.empty?
# index name can't be the same
- opts = { name: name.gsub(/(^|_)(#{from})_/, "\\1#{to}_") }
+ opts = { name: name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), internal: true }
opts[:unique] = true if index.unique
add_index(to, columns, opts)
end