github.com/muhammadn/cortex@v1.9.1-0.20220510110439-46bb7000d03d/cmd/cortex/migrations/002_immutable_configs.up.sql (about)

     1  -- NB: Incompatible schema change. Normally we would follow a more incremental
     2  -- process (as exemplified in users/db/migrations/006 to 010), but currently
     3  -- there are no data in production and only one row in dev.
     4  
     5  -- https://github.com/mattes/migrate/tree/master/database/postgres#upgrading-from-v1
     6  -- Wrap all commands in BEGIN and COMMIT to accommodate upgrade
     7  BEGIN;
     8  
     9  -- The existing id, type columns are the id & type of the entity that owns the
    10  -- config.
    11  ALTER TABLE configs RENAME COLUMN id TO owner_id;
    12  ALTER TABLE configs RENAME COLUMN type TO owner_type;
    13  
    14  -- Add a new auto-incrementing id.
    15  ALTER TABLE configs ADD COLUMN id SERIAL;
    16  
    17  ALTER TABLE configs DROP CONSTRAINT configs_pkey;
    18  ALTER TABLE configs ADD PRIMARY KEY (id, owner_id, owner_type, subsystem);
    19  
    20  COMMIT;