Rails5 MySQL fix rename_column as part of cleanup_concurrent_column_type_change for timestamps
What does this MR do?
There was a problem with CleanupAddTimezoneToIssuesClosedAt
post migration on Rails 5 MySQL. The rename_column
as part of cleanup_concurrent_column_type_change
was executing ALTER TABLE `issues` CHANGE `closed_at_for_type_change` `closed_at` datetime
so changing the new timestamp
column back to a datetime
(introduced here in rename_column_sql
).
This change disables the aliasing of timestamp
to datetime
as part of new_column_definition
. It now executes ALTER TABLE `issues` CHANGE `closed_at_for_type_change` `closed_at` timestamp NULL
This can easily be tested by running: RAILS5=1 bin/rspec spec/migrations/migrate_issues_to_ghost_user_spec.rb:20 spec/lib/gitlab/database/migration_helpers_spec.rb:1184
which will failed with
1) Gitlab::Database::MigrationHelpers#rename_column_using_background_migration renames a column using a background migration
Failure/Error:
add_column(table, new_column, new_type,
limit: old_col.limit,
precision: old_col.precision,
scale: old_col.scale)
#<ActiveRecord::Migration:0x00005591a6888438 @name="ActiveRecord::Migration", @version=nil, @connection=nil> received :add_column with unexpected arguments
expected: ("issues", :closed_at_timestamp, :datetime_with_timezone, {:limit=>anything, :precision=>anything, :scale=>anything})
got: ("issues", :closed_at_timestamp, :datetime, {:limit=>nil, :precision=>0, :scale=>nil})
Diff:
@@ -1,5 +1,5 @@
["issues",
:closed_at_timestamp,
- :datetime_with_timezone,
- {:limit=>anything, :precision=>anything, :scale=>anything}]
+ :datetime,
+ {:limit=>nil, :precision=>0, :scale=>nil}]
# ./lib/gitlab/database/migration_helpers.rb:642:in `rename_column_using_background_migration'
# ./spec/lib/gitlab/database/migration_helpers_spec.rb:1228:in `block (3 levels) in <top (required)>'
See https://gitlab.com/jlemaes/gitlab-ce/-/jobs/80193979
Are there points in the code the reviewer needs to double check?
Is there a better way than this monkey patch? Should I add specs for this?
Why was this MR needed?
rails5 upgrade
Screenshots (if relevant)
Does this MR meet the acceptance criteria?
-
Changelog entry added, if necessary - Conform by the code review guidelines
-
Has been reviewed by a Backend maintainer -
Has been reviewed by a Database specialist
-
-
Conform by the merge request performance guides -
Conform by the style guides -
Conform by the database guides -
If you have multiple commits, please combine them into a few logically organized commits by squashing them -
End-to-end tests pass ( package-and-qa
manual pipeline job)