Fix different behavior between db:migrate:up/down and redo
What does this MR do?
The rails db:migrate:redo
command has different behavior than running a rails db:migrate:down
followed by rails db:migrate:up
. When running the redo
command, the gitlab:db:clean_structure_sql
task is only run after the down
step, resulting in the final structure.sql
not being stripped of comments etc.
This is due to rake only allowing the task to be run once in an execution context, so we have to reenable
the task after it runs so it execute the second time.
Output of rails db:migrate:redo --trace
Before
** Invoke db:migrate:redo (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate:redo
** Invoke db:rollback (first_time)
** Invoke db:load_config
** Execute db:rollback
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke db:load_config
** Execute db:structure:dump
** Invoke gitlab:db:clean_structure_sql (first_time)
** Execute gitlab:db:clean_structure_sql
** Invoke db:migrate (first_time)
** Invoke db:load_config
** Invoke schema_version_check (first_time)
** Invoke environment
** Execute schema_version_check
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke db:load_config
** Execute db:structure:dump
** Invoke gitlab:db:clean_structure_sql
After
** Invoke db:migrate:redo (first_time)
** Invoke db:load_config (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:load_config
** Execute db:migrate:redo
** Invoke db:rollback (first_time)
** Invoke db:load_config
** Execute db:rollback
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke db:load_config
** Execute db:structure:dump
** Invoke gitlab:db:clean_structure_sql (first_time)
** Execute gitlab:db:clean_structure_sql
** Invoke db:migrate (first_time)
** Invoke db:load_config
** Invoke schema_version_check (first_time)
** Invoke environment
** Execute schema_version_check
** Execute db:migrate
** Invoke db:_dump (first_time)
** Execute db:_dump
** Invoke db:structure:dump (first_time)
** Invoke db:load_config
** Execute db:structure:dump
** Invoke gitlab:db:clean_structure_sql (first_time)
** Execute gitlab:db:clean_structure_sql
Related issue: #212883 (closed)
Does this MR meet the acceptance criteria?
Conformity
-
Changelog entry -
Documentation (if required) -
Code review guidelines -
Merge request performance guidelines -
Style guides -
Database guides -
Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. -
Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Edited by 🤖 GitLab Bot 🤖