Add post_migrate to remove invalid record
What does this MR do and why?
Add post_migrate to remove invalid record
We remove any gitlab_subscription_histories
records that does not have namespace_id
. The table itself is used as event logging for the parent/main table gitlab_subscription
.
After this migration we will add NOT NULL
constraints on namespace_id
for this table.
Database
- There are total
616
records on production that will be deleted. See detail explanation.
[ gprd ] production> GitlabSubscriptionHistory.where(namespace_id: nil).count
=> 616
- The new records will always have
namespace_id
asNOT NULL
constraints check was added to its parentgitlab_subscriptions
table - Currently there are zero records with
namespace_id
NULL ongitlab_subscription
table.
[ gprd ] production> GitlabSubscription.where(namespace_id: nil).count
=> 0
[ gprd ] production>
SQL query plan
DELETE FROM "gitlab_subscription_histories" WHERE "gitlab_subscription_histories"."namespace_id" IS NULL AND "gitlab_subscription_histories"."id" >= 176390 and "gitlab_subscription_histories"."id" < 177000
PostgresAI: https://console.postgres.ai/gitlab/gitlab-production-main/sessions/28995/commands/90858
The results of test-database pipeline: !156518 (comment 1955053380)
Duration: 15.4 s
Another approach MR where we delete all directly: Draft: Add post_migrate to remove invalid recor... (!156541 - closed) with duration ~5 seconds
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Related to #462598