mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Keep index names when using with sqlite3
This commit is contained in:
parent
e68abc2c96
commit
d01f913f8d
3 changed files with 16 additions and 2 deletions
|
@ -1,5 +1,10 @@
|
||||||
## Rails 4.0.0 (unreleased) ##
|
## Rails 4.0.0 (unreleased) ##
|
||||||
|
|
||||||
|
* Keep index names when using `alter_table` with sqlite3.
|
||||||
|
Fix #3489
|
||||||
|
|
||||||
|
*Yves Senn*
|
||||||
|
|
||||||
* Add ability for postgresql adapter to disable user triggers in disable_referential_integrity.
|
* Add ability for postgresql adapter to disable user triggers in disable_referential_integrity.
|
||||||
Fix #5523
|
Fix #5523
|
||||||
|
|
||||||
|
|
|
@ -537,7 +537,6 @@ module ActiveRecord
|
||||||
end
|
end
|
||||||
yield @definition if block_given?
|
yield @definition if block_given?
|
||||||
end
|
end
|
||||||
|
|
||||||
copy_table_indexes(from, to, options[:rename] || {})
|
copy_table_indexes(from, to, options[:rename] || {})
|
||||||
copy_table_contents(from, to,
|
copy_table_contents(from, to,
|
||||||
@definition.columns.map {|column| column.name},
|
@definition.columns.map {|column| column.name},
|
||||||
|
@ -560,7 +559,7 @@ module ActiveRecord
|
||||||
|
|
||||||
unless columns.empty?
|
unless columns.empty?
|
||||||
# index name can't be the same
|
# index name can't be the same
|
||||||
opts = { :name => name.gsub(/_(#{from})_/, "_#{to}_") }
|
opts = { name: name.gsub(/(^|_)(#{from})_/, "\\1#{to}_") }
|
||||||
opts[:unique] = true if index.unique
|
opts[:unique] = true if index.unique
|
||||||
add_index(to, columns, opts)
|
add_index(to, columns, opts)
|
||||||
end
|
end
|
||||||
|
|
|
@ -173,6 +173,16 @@ module ActiveRecord
|
||||||
refute TestModel.new.administrator?
|
refute TestModel.new.administrator?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_change_column_with_custom_index_name
|
||||||
|
add_column "test_models", "category", :string
|
||||||
|
add_index :test_models, :category, name: 'test_models_categories_idx'
|
||||||
|
|
||||||
|
assert_equal ['test_models_categories_idx'], connection.indexes('test_models').map(&:name)
|
||||||
|
change_column "test_models", "category", :string, null: false, default: 'article'
|
||||||
|
|
||||||
|
assert_equal ['test_models_categories_idx'], connection.indexes('test_models').map(&:name)
|
||||||
|
end
|
||||||
|
|
||||||
def test_change_column_default
|
def test_change_column_default
|
||||||
add_column "test_models", "first_name", :string
|
add_column "test_models", "first_name", :string
|
||||||
connection.change_column_default "test_models", "first_name", "Tester"
|
connection.change_column_default "test_models", "first_name", "Tester"
|
||||||
|
|
Loading…
Reference in a new issue