diff --git a/CHANGELOG.md b/CHANGELOG.md index 39c59c4..90f0b08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## master (unreleased) +- Fix `add_refernce_concurrently` when adding non polymorphic references - Fix progress for background migrations with small number of records ## 0.19.5 (2024-09-20) diff --git a/lib/online_migrations/schema_statements.rb b/lib/online_migrations/schema_statements.rb index 4f9e29c..c63dee3 100644 --- a/lib/online_migrations/schema_statements.rb +++ b/lib/online_migrations/schema_statements.rb @@ -655,7 +655,7 @@ def add_reference_concurrently(table_name, ref_name, **options) add_column(table_name, column_name, type, null: allow_null) end - if !column_exists?(table_name, type_column_name) + if options[:polymorphic] && !column_exists?(table_name, type_column_name) allow_null = options[:polymorphic].is_a?(Hash) ? options[:polymorphic][:null] : true add_column(table_name, type_column_name, :string, null: allow_null) end diff --git a/test/schema_statements/add_reference_concurrently_test.rb b/test/schema_statements/add_reference_concurrently_test.rb index 1039f63..add71f6 100644 --- a/test/schema_statements/add_reference_concurrently_test.rb +++ b/test/schema_statements/add_reference_concurrently_test.rb @@ -32,6 +32,7 @@ def test_add_reference_concurrently Milestone.reset_column_information assert_includes Milestone.column_names, "project_id" + assert_not_includes Milestone.column_names, "project_type" end def test_add_reference_concurrently_adds_index