Skip to content

Add NOT NULL constraint on ci_runner_taggings.tag_name

NOTE: This MR is set to only merge after %18.5 is released, but I want to start reviews since I'll be on PTO for a large portion of %18.6.

What does this MR do and why?

This MR adds a NOT NULL constraint on the ci_runner_taggings.tag_name column to enforce data integrity at the database level.

The tag_name field is a critical identifier for runner tags and should never be NULL. While we have application-level validations, adding a database-level constraint provides an additional layer of data integrity protection and ensures consistency across all data access paths.

Changes included:

  • Add NOT NULL constraint to ci_runner_taggings.tag_name for the main table and all partitions
  • Update model validation to remove the on: [:create, :update] condition (constraint now applies at all times)
  • Update schema and tests accordingly

Changelog: other

References

Closes #573111, #549027, #549028

How to set up and validate locally

Prerequisites

Ensure your local database is up to date.

Validation steps:

  1. Run the migration:

    bundle exec rails db:migrate
  2. Verify the constraint was added:

    # In a Rails console or psql
    SELECT conname, contype, pg_get_constraintdef(oid)
    FROM pg_constraint
    WHERE conname = 'check_tag_name_not_null';

    Expected output should show the NOT NULL constraint on tag_name.

  3. Test the constraint enforcement:

    # In Rails console
    runner = create(:ci_runner, :project)
    tag = create(:ci_tag)
    
    # This should fail at the database level
    Ci::RunnerTagging.create!(runner: runner, tag: tag, tag_name: nil, runner_type: runner.runner_type)

    Expected: Should raise a database constraint violation error.

  4. Verify rollback:

    bundle exec rails db:migrate:down VERSION=20251008165644

    Ensure the constraint is properly removed.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Database review

  • Database review completed

  • Database testing pipeline executed and reviewed

  • No NULL values exist in production data (verified before merge)

    gitlabhq_dblab> SELECT COUNT(*) FROM ci_runner_taggings WHERE tag_name IS NULL
    +-------+
    | count |
    |-------|
    | 0     |
    +-------+
    SELECT 1
    Time: 0.472s

Merge request reports

Loading