Skip to content

Introduce new ProjectCiCdSettings model with group_runners_enabled

Dylan Griffith requested to merge 10244-add-project-ci-cd-settings into master

This MR adds a new table for storing CI/CD settings: project_ci_cd_settings. This allows us to gradually moving project settings out of the projects table and into context specific tables.

Migration Output

From staging:

==  CreateProjectCiCdSettings: migrating ======================================
-- create_table(:project_ci_cd_settings)
   -> 0.0230s
-- execute("SET statement_timeout TO 0")
   -> 0.0008s
-- execute("INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects")
   -> 10.5467s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0009s
-- index_exists?(:project_ci_cd_settings, :project_id, {:unique=>true, :algorithm=>:concurrently})
   -> 0.0017s
-- add_index(:project_ci_cd_settings, :project_id, {:unique=>true, :algorithm=>:concurrently})
   -> 12.2145s
-- execute("DELETE FROM project_ci_cd_settings\nWHERE NOT EXISTS (\n  SELECT 1\n  FROM projects\n  WHERE projects.id = project_ci_cd_settings.project_id\n)\n")
   -> 3.1133s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0008s
-- foreign_keys(:project_ci_cd_settings)
   -> 0.0030s
Foreign key not created because it exists already (this may be due to an aborted migration or similar): source: project_ci_cd_settings, target: projects, column: project_id
-- execute("ALTER TABLE project_ci_cd_settings\nADD CONSTRAINT fk_24c15d2f2e\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 4.0969s
-- execute("ALTER TABLE project_ci_cd_settings VALIDATE CONSTRAINT fk_24c15d2f2e;")
   -> 2.6767s
==  CreateProjectCiCdSettings: migrated (32.6803s) ============================

=> nil
[ stg ] production> CreateProjectCiCdSettings.new.migrate(:down)
==  CreateProjectCiCdSettings: reverting ======================================
-- drop_table(:project_ci_cd_settings)
   -> 3.6861s
==  CreateProjectCiCdSettings: reverted (3.6863s) =============================

From production:

==  CreateProjectCiCdSettings: migrating ======================================
-- table_exists?(:project_ci_cd_settings)
   -> 0.0018s
-- create_table(:project_ci_cd_settings)
   -> 0.0564s
-- execute("SET statement_timeout TO 0")
   -> 0.0006s
-- execute("INSERT INTO project_ci_cd_settings (project_id) SELECT id FROM projects")
   -> 21.7300s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0014s
-- add_index(:project_ci_cd_settings, :project_id, {:unique=>true, :algorithm=>:concurrently})
   -> 24.9029s
-- execute("DELETE FROM project_ci_cd_settings\nWHERE NOT EXISTS (\n  SELECT 1\n  FROM projects\n  WHERE projects.id = project_ci_cd_settings.project_id\n)\n")
   -> 6.6351s
-- transaction_open?()
   -> 0.0000s
-- execute("SET statement_timeout TO 0")
   -> 0.0005s
-- execute("ALTER TABLE project_ci_cd_settings\nADD CONSTRAINT fk_24c15d2f2e\nFOREIGN KEY (project_id)\nREFERENCES projects (id)\nON DELETE CASCADE\nNOT VALID;\n")
   -> 0.2777s
-- execute("ALTER TABLE project_ci_cd_settings VALIDATE CONSTRAINT fk_24c15d2f2e;")
   -> 5.9862s
==  CreateProjectCiCdSettings: migrated (59.5940s) ============================

And the resulting table size:

gitlabhq_production=# select pg_size_pretty(pg_total_relation_size('project_ci_cd_settings'));
 pg_size_pretty 
----------------
 369 MB
(1 row)

Database Checklist

When adding migrations:

  • Updated db/schema.rb
  • Added a down method so the migration can be reverted
  • Added the output of the migration(s) to the MR body

When adding tables:

  • Ordered columns based on the Ordering Table Columns guidelines
  • Added foreign keys to any columns pointing to data in other tables
  • Added indexes for fields that are used in statements such as WHERE, ORDER BY, GROUP BY, and JOINs

General Checklist

Related Issues

Edited by Kamil Trzciński

Merge request reports