Delete tracking records on partitioning rollback
What does this MR do?
Related issue: #218428 (closed)
MR !35913 (merged) added tracking for background migrations in the background_migration_jobs
table. The partitioning migration helpers will be the first background migration to use the new code to track execution of background jobs. In the event of a rollback of a partitioning migration, the database should be restored to the state prior to the migration, but the initial implementation did not handle that cleanup.
This MR implements the missing functionality to delete the matching rows from background_migration_jobs
.
Delete statement
DELETE FROM "background_migration_jobs" WHERE "background_migration_jobs"."class_name" = 'Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable' AND (arguments ->> 2 = 'audit_events')
With the partial index:
Delete on background_migration_jobs (cost=0.12..8.25 rows=2 width=6)
-> Index Scan using index_background_migration_jobs_for_partitioning_migrations on background_migration_jobs (cost=0.12..8.25 rows=2 width=6)
Index Cond: ((arguments ->> 2) = 'audit_events'::text)
Filter: (class_name = 'Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable'::text)
The index isn't strictly needed at this time for the single migration we have, but will be useful to have later. The initial audit_events
migration will have ~6300 entries in the background_migration_jobs
table.
Migration
A new index was added to support lookup of partitioning migration jobs, and the outputs for the execution are displayed below. The non-concurrent forms of add/remove index can safely be used since the table is empty at this time.
up
rails db:migrate:up VERSION=20200713152443
== 20200713152443 AddBackgroundMigrationJobIndexForPartitioningMigrations: migrating
-- add_index(:background_migration_jobs, "((arguments ->> 2))", {:name=>"index_background_migration_jobs_for_partitioning_migrations", :where=>"class_name = 'Gitlab::Database::PartitioningMigrationHelpers::BackfillPartitionedTable'"})
-> 0.0246s
== 20200713152443 AddBackgroundMigrationJobIndexForPartitioningMigrations: migrated (0.0247s)
down
rails db:migrate:down VERSION=20200713152443
== 20200713152443 AddBackgroundMigrationJobIndexForPartitioningMigrations: reverting
-- remove_index(:background_migration_jobs, {:name=>"index_background_migration_jobs_for_partitioning_migrations"})
-> 0.0012s
== 20200713152443 AddBackgroundMigrationJobIndexForPartitioningMigrations: reverted (0.0012s)
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. -
Tested in all supported browsers - [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
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