Skip to content

Cleanup ci_runner_projects records with null project_id

What does this MR do and why?

This MR adds a post-deployment migration to cleanup ci_runner_projects records with nil project_id. In prod, there are only 3 old records that fit the scenario:

image

This will allow us to later on add a NOT NULL constraint on the table (see documentation)

Step MR
1. Add validations so that new invalid records cannot be created !155756 (merged)
2. Remove invalid rows !155760 (merged)
3. Mark column as NOT NULL MR to come in %17.2

Changelog: fixed

Part of #459996 (closed)

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.

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other merge requests.

n/a

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

  1. Add an offending record in the database:

    Ci::RunnerProject.new(runner_id: Ci::Runner.project_type.last.id, project_id: nil).save!
  2. Run bin/rails db:migrate.

  3. Confirm that the record was removed:

    [93] pry(main)> Ci::RunnerProject.where(project_id: nil)
      Ci::RunnerProject Load (4.9ms)  SELECT "ci_runner_projects".* FROM "ci_runner_projects" WHERE "ci_runner_projects"."project_id" IS NULL /*application:console,db_config_name:ci,console_hostname:gitlab-macbookpro.work.pombei.ro,console_username:pedropombeiro,line:bin/rails:4:in `<main>'*/
    => []

Database query plans

https://postgres.ai/console/gitlab/gitlab-production-ci/sessions/28983/commands/90386

Edited by Pedro Pombeiro

Merge request reports

Loading