Skip to content

Commit

Permalink
Fix add_reference_concurrently adding type for non-polymorphic ref (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jyeb authored Sep 26, 2024
1 parent cdd5dc4 commit a1cece4
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion lib/online_migrations/schema_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/schema_statements/add_reference_concurrently_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a1cece4

Please sign in to comment.