mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #31607 from fatkodima/fix-sqlite-partial-indexes
Fix recreating partial indexes after alter table for sqlite
This commit is contained in:
commit
5428c8e3a2
2 changed files with 18 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue