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

drop index if it exists #317

Merged
merged 1 commit into from
Sep 7, 2016
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/cequel/schema/table_updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def create_index(column_name, index_name = nil)
# @return [void]
#
def drop_index(index_name)
statements << "DROP INDEX #{index_name}"
statements << "DROP INDEX IF EXISTS #{index_name}"
end

# @!visibility protected
Expand Down
29 changes: 22 additions & 7 deletions spec/examples/schema/table_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,16 +121,31 @@
end

describe '#drop_index' do
before do
tab_name = table_name
cequel.schema.alter_table(table_name) do
create_index :title
drop_index :"#{tab_name}_title_idx"
context 'index exists' do
before do
tab_name = table_name
cequel.schema.alter_table(table_name) do
create_index :title
drop_index :"#{tab_name}_title_idx"
end
end

it 'should drop the index' do
expect(table.data_column(:title)).not_to be_indexed
end
end

it 'should drop the index' do
expect(table.data_column(:title)).not_to be_indexed
context 'index does not exist' do
before do
tab_name = table_name
cequel.schema.alter_table(table_name) do
drop_index :"#{tab_name}_title_idx"
end
end

it 'should nop on non existent index' do
expect(table.data_column(:title)).not_to be_indexed
end
end
end

Expand Down