ALTER TABLE toloka_mgr.task DROP CONSTRAINT task_type_id_fkey;

ALTER TABLE toloka_mgr.task_type_info DROP CONSTRAINT task_type_info_pkey;
ALTER TABLE toloka_mgr.task_type_info ADD PRIMARY KEY (type_id, platform);


ALTER TABLE toloka_mgr.task ALTER COLUMN platform SET NOT NULL;

ALTER TABLE toloka_mgr.task
ADD CONSTRAINT task_type_id_fkey FOREIGN KEY (platform, type_id)
    REFERENCES toloka_mgr.task_type_info(platform, type_id);


ALTER INDEX toloka_mgr.task_known_solutions_idx
    RENAME TO task_known_solutions_idx_old;
ALTER INDEX toloka_mgr.task_type_id_status_idx
    RENAME TO task_type_id_status_idx_old;

ALTER TABLE toloka_mgr.toloka_task ALTER COLUMN platform SET NOT NULL;
ALTER TABLE toloka_mgr.toloka_task DROP CONSTRAINT toloka_task_pkey;
ALTER TABLE toloka_mgr.toloka_task ADD PRIMARY KEY (platform, task_suite_id, task_index);

ALTER TABLE toloka_mgr.toloka_task_suite ALTER COLUMN platform SET NOT NULL;
ALTER INDEX toloka_mgr.toloka_task_suite_id_idx
    RENAME TO toloka_task_suite_id_idx_old;
