diff options
author | fatkodima <fatkodima123@gmail.com> | 2017-12-31 16:54:53 +0200 |
---|---|---|
committer | fatkodima <fatkodima123@gmail.com> | 2017-12-31 16:54:53 +0200 |
commit | 3bd170eb935d582f6dbdf7e693385db68110acc8 (patch) | |
tree | 3e9d194e3de5d95d5b3bbecbb9ac01005d87eff1 /activerecord | |
parent | 71b4bf698f7443bd8d2e436bc9f37b4d6ec8fc8d (diff) | |
download | rails-3bd170eb935d582f6dbdf7e693385db68110acc8.tar.gz rails-3bd170eb935d582f6dbdf7e693385db68110acc8.tar.bz2 rails-3bd170eb935d582f6dbdf7e693385db68110acc8.zip |
Fix recreating partial indexes after alter table for sqlite
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index 5a4540f6ad..441c7cd28f 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -452,6 +452,7 @@ module ActiveRecord # index name can't be the same opts = { name: name.gsub(/(^|_)(#{from})_/, "\\1#{to}_"), internal: true } opts[:unique] = true if index.unique + opts[:where] = index.where if index.where add_index(to, columns, opts) end end diff --git a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb index 6f72df4412..cd5d6f17d8 100644 --- a/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb +++ b/activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb @@ -453,6 +453,23 @@ module ActiveRecord Barcode.reset_column_information end + def test_remove_column_preserves_partial_indexes + connection = Barcode.connection + connection.create_table :barcodes, force: true do |t| + t.string :code + t.string :region + t.boolean :bool_attr + + t.index :code, unique: true, where: :bool_attr, name: "partial" + end + connection.remove_column :barcodes, :region + + index = connection.indexes("barcodes").find { |idx| idx.name == "partial" } + assert_equal "bool_attr", index.where + ensure + Barcode.reset_column_information + end + def test_supports_extensions assert_not @conn.supports_extensions?, "does not support extensions" end |