Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix recreating partial indexes after alter table for sqlite #31607

Merged
merged 1 commit into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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