Skip to content

Commit

Permalink
Merge pull request #31607 from fatkodima/fix-sqlite-partial-indexes
Browse files Browse the repository at this point in the history
Fix recreating partial indexes after alter table for sqlite
  • Loading branch information
kamipo committed Dec 31, 2017
2 parents 71b4bf6 + 3bd170e commit 5428c8e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ def copy_table_indexes(from, to, rename = {})
# 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
Expand Down
17 changes: 17 additions & 0 deletions activerecord/test/cases/adapters/sqlite3/sqlite3_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,23 @@ def test_add_column_with_custom_primary_key
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
Expand Down

0 comments on commit 5428c8e

Please sign in to comment.