Ensure uploads.id has the correct default

What does this MR do and why?

For some instances uploads_id_seq was not owned by uploads.id which resulted in the new partitioned uploads table to not have default set for id after !218827 (merged).

This ensures the columns has the correct default and is the sequence's owner. There is no change if this is already the case.

References

How to set up and validate locally

  1. Reproduce the problem for the main database
    gdk psql -d gitlabhq_development
    # alter table uploads alter column id set default null;
    ALTER TABLE
    Time: 41.803 ms
    gitlabhq_development=# alter sequence uploads_id_seq owned by none;
    ALTER SEQUENCE
    Time: 3.217 ms
  2. Confirm the problem exists
    gdk psql -d gitlabhq_development
    # \d uploads
                             Partitioned table "public.uploads"
           Column        |            Type             | Collation | Nullable | Default 
    ---------------------+-----------------------------+-----------+----------+---------
     id                  | bigint                      |           | not null | 
    
    # \d project_uploads
                               Table "public.project_uploads"
           Column        |            Type             | Collation | Nullable | Default 
    ---------------------+-----------------------------+-----------+----------+---------
     id                  | bigint                      |           | not null | 
    
    # select pg_get_serial_sequence('uploads', 'id');
     pg_get_serial_sequence 
    ------------------------
     ø
    (1 row)
  3. On this branch execute the migration
    bundle exec rails db:migrate
  4. Confirm the problem is fixed
    gdk psql -d gitlabhq_development
        \d uploads
                                           Partitioned table "public.uploads"
           Column        |            Type             | Collation | Nullable |               Default               
    ---------------------+-----------------------------+-----------+----------+-------------------------------------
     id                  | bigint                      |           | not null | nextval('uploads_id_seq'::regclass)
    
    # \d project_uploads
                                             Table "public.project_uploads"
           Column        |            Type             | Collation | Nullable |               Default               
    ---------------------+-----------------------------+-----------+----------+-------------------------------------
     id                  | bigint                      |           | not null | nextval('uploads_id_seq'::regclass)
    
    # select pg_get_serial_sequence('uploads', 'id');
     pg_get_serial_sequence 
    ------------------------
     public.uploads_id_seq
    (1 row)
  5. Using same commands confirm the state is correct if there was no issue at all:
    gdk psql -d gitlabhq_development_ci

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.

Edited by Krasimir Angelov

Merge request reports

Loading