From 169a3d78d25831db1aeeadc625cd4d8cd3db4d75 Mon Sep 17 00:00:00 2001 From: Jakub Duchek Date: Wed, 19 Aug 2026 20:28:57 +0200 Subject: [PATCH] Fixes #471 - Tolerate absent duplicate indexes Migration 020 now treats an already missing duplicate index as the desired state and continues removing the remaining redundant indexes. Assisted-By: Codex 5.6 Sol High --- .../020_drop_duplicate_indices.rb | 18 ++++++++----- test/persistence_migrations_test.rb | 25 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 test/persistence_migrations_test.rb diff --git a/lib/dynflow/persistence_adapters/sequel_migrations/020_drop_duplicate_indices.rb b/lib/dynflow/persistence_adapters/sequel_migrations/020_drop_duplicate_indices.rb index 8b8b87be..30351ab3 100644 --- a/lib/dynflow/persistence_adapters/sequel_migrations/020_drop_duplicate_indices.rb +++ b/lib/dynflow/persistence_adapters/sequel_migrations/020_drop_duplicate_indices.rb @@ -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) + 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 diff --git a/test/persistence_migrations_test.rb b/test/persistence_migrations_test.rb new file mode 100644 index 00000000..347564eb --- /dev/null +++ b/test/persistence_migrations_test.rb @@ -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