Skip to content
Open
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 @@ -2,16 +2,22 @@

Sequel.migration do
up do
alter_table(:dynflow_actions) do
drop_index [:execution_plan_uuid, :id]
if indexes(:dynflow_actions).key?(:dynflow_actions_execution_plan_uuid_id_index)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the actual dropping, we rely on sequel to derive the index name from the table and the columns. Could we reuse that function rather than using the exact index name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, good point. default_index_name(table, Array(columns)).to_sym will keep the existence check aligned with the name Sequel uses in drop_index. I’ll update it.

alter_table(:dynflow_actions) do
drop_index [:execution_plan_uuid, :id]
end
end

alter_table(:dynflow_execution_plans) do
drop_index :uuid
if indexes(:dynflow_execution_plans).key?(:dynflow_execution_plans_uuid_index)
alter_table(:dynflow_execution_plans) do
drop_index :uuid
end
end

alter_table(:dynflow_steps) do
drop_index [:execution_plan_uuid, :id]
if indexes(:dynflow_steps).key?(:dynflow_steps_execution_plan_uuid_id_index)
alter_table(:dynflow_steps) do
drop_index [:execution_plan_uuid, :id]
end
end
end

Expand Down
25 changes: 25 additions & 0 deletions test/persistence_migrations_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require_relative 'test_helper'

describe 'Sequel persistence migrations' do
let(:db) { Sequel.connect('sqlite:/') }
let(:migrations_path) { Dynflow::PersistenceAdapters::Sequel.migrations_path }

after do
db.disconnect
end

it 'tolerates duplicate indexes that are already absent' do
Sequel::Migrator.run(db, migrations_path, table: 'dynflow_schema_info', target: 19)
db.alter_table(:dynflow_actions) do
drop_index [:execution_plan_uuid, :id]
end

Sequel::Migrator.run(db, migrations_path, table: 'dynflow_schema_info', target: 20)

_(db.indexes(:dynflow_actions)).wont_include :dynflow_actions_execution_plan_uuid_id_index
_(db.indexes(:dynflow_execution_plans)).wont_include :dynflow_execution_plans_uuid_index
_(db.indexes(:dynflow_steps)).wont_include :dynflow_steps_execution_plan_uuid_id_index
end
end