Skip to content

Ensure BacthedMigration and BatchedJob always have pause_ms attribute

Krasimir Angelov requested to merge 328816-pause-ms-attribute into master

What does this MR do?

Define pause_ms attribute for both BatchedMigration and BatchedJob models to make sure older migrations will execute even if the column is not created in the DB yet.

Thanks to ActiveRecord's Attributes API, if the database column is missing then pause_ms is a virtual attribute, if the column exists, then pause_ms is fetched from/ saved to the database. This way we do not have to do check like responds_to? or has_attribute? everywhere we want to use the attribute.

See #328816 (closed).

I did not find a good way to write tests for this, and did not want to mess with dropping columns inside specs, so tested the following variants manually (by calling BatchedMigration#create_batched_job! in console).

Migration
20210413155324_add_pause_seconds_to_batched_background_migrations.rb Up Up Down Down
20210414045322_add_pause_seconds_to_batched_background_migration_jobs.rb Up Down Down Up
Result

Screenshots (strongly suggested)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • Label as security and @ mention @gitlab-com/gl-security/appsec
  • The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • Security reports checked/validated by a reviewer from the AppSec team

Related to #328816 (closed)

Edited by Krasimir Angelov

Merge request reports