Skip to content

Prevent adding columns to wide tables

Mayra Cabrera requested to merge prevent-adding-columns-to-wide-tables into master

What does this MR do?

Prevents adding columns to wide tables by adding a new migration cop.

On GitLab.com, tables ordered by number of columns are:

gitlabhq_production=> SELECT table_name, COUNT(*) AS column_count                                                                                                                                                                                                               FROM information_schema.columns                                                                                                                                                                                                                                                 WHERE table_schema='public'                                                                                                                                                                                                                                                     GROUP BY table_name ORDER BY column_count DESC                                                                                                                                                                                                                                  LIMIT(10);
                table_name                | column_count
------------------------------------------+--------------
 application_settings                     |          231
 users                                    |           85
 projects                                 |           82
 geo_node_statuses                        |           54
 ci_builds                                |           51
 namespaces                               |           46
 merge_requests                           |           39
 conversational_development_index_metrics |           33
 epics                                    |           33
 issues                                   |           31
(10 rows)

Based on that information, I took 50 as a limit, meaning tables above 50 columns are considered wide tables. I didn't include application_settings nor geo_node_statuses as they barely have records, so I don't think it's necessary to blacklisted them:

gitlabhq_production=> select count(*) from application_settings;
 count
-------
     1
(1 row)

gitlabhq_production=> select count(*) from geo_node_statuses;                                                                                                                                                                                                                    count
-------
     0
(1 row)

This new cop is only preventing adding columns to users, projects and ci_builds. We can add more tables later if necessary.

Related to #201933 (closed)

Screenshots

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

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
Edited by Mayra Cabrera

Merge request reports