BEGIN;

ALTER TABLE statistics.year_in_music ADD COLUMN year SMALLINT;

ALTER TABLE statistics.year_in_music ADD COLUMN id INTEGER GENERATED BY DEFAULT AS IDENTITY NOT NULL;
ALTER TABLE statistics.year_in_music DROP CONSTRAINT stats_year_in_music_pkey;
ALTER TABLE statistics.year_in_music ADD CONSTRAINT stats_year_in_music_pkey PRIMARY KEY (id);

-- update existing year in music rows to 2021
UPDATE statistics.year_in_music SET year = 2021;

ALTER TABLE statistics.year_in_music ALTER COLUMN year SET NOT NULL;

CREATE UNIQUE INDEX user_id_year_in_music_uniq_idx ON statistics.year_in_music (user_id, year);

COMMIT;
