126 lines
5.8 KiB
SQL
126 lines
5.8 KiB
SQL
-- I was planning on migrating strapi database to postgrest and also migrating from INT to UUID.
|
|
-- Doing both at once proved far too complex, so I'm reverting the schmea to use INT ids in order to migrate.
|
|
-- Once that is done we can switch to uuids, but the two steps should be separate
|
|
|
|
DO $$
|
|
BEGIN
|
|
-- api.builds
|
|
ALTER TABLE api.builds DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.builds ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.builds DROP COLUMN vod_id CASCADE;
|
|
ALTER TABLE api.builds ADD COLUMN vod_id INT;
|
|
|
|
-- api.contributors
|
|
ALTER TABLE api.contributors DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.contributors ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
-- api.discord_interactions
|
|
ALTER TABLE api.discord_interactions DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.discord_interactions ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
-- api.mux_assets
|
|
ALTER TABLE api.mux_assets DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.mux_assets ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
-- api.patrons
|
|
ALTER TABLE api.patrons DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.patrons ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
-- api.recordings
|
|
ALTER TABLE api.recordings DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.recordings ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.recordings DROP COLUMN discord_interaction_id CASCADE;
|
|
ALTER TABLE api.recordings ADD COLUMN discord_interaction_id INT;
|
|
|
|
-- api.s3_files
|
|
ALTER TABLE api.s3_files DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.s3_files ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
-- api.segments
|
|
ALTER TABLE api.segments DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.segments ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.segments DROP COLUMN vod_id CASCADE;
|
|
ALTER TABLE api.segments ADD COLUMN vod_id INT;
|
|
|
|
-- api.segments_vod_links
|
|
ALTER TABLE api.segments_vod_links DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.segments_vod_links ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.segments_vod_links DROP COLUMN segment_id CASCADE;
|
|
ALTER TABLE api.segments_vod_links ADD COLUMN segment_id INT;
|
|
ALTER TABLE api.segments_vod_links DROP COLUMN vod_id CASCADE;
|
|
ALTER TABLE api.segments_vod_links ADD COLUMN vod_id INT;
|
|
|
|
-- api.streams
|
|
ALTER TABLE api.streams DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.streams ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.streams DROP COLUMN vtuber CASCADE;
|
|
ALTER TABLE api.streams ADD COLUMN vtuber INT;
|
|
|
|
-- api.tags
|
|
ALTER TABLE api.tags DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.tags ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.tags DROP COLUMN toy_id CASCADE;
|
|
ALTER TABLE api.tags ADD COLUMN toy_id INT;
|
|
|
|
-- api.tags_vods
|
|
ALTER TABLE api.tags_vods DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.tags_vods ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.tags_vods DROP COLUMN tag_id CASCADE;
|
|
ALTER TABLE api.tags_vods ADD COLUMN tag_id INT;
|
|
ALTER TABLE api.tags_vods DROP COLUMN vod_id CASCADE;
|
|
ALTER TABLE api.tags_vods ADD COLUMN vod_id INT;
|
|
|
|
-- api.toys
|
|
ALTER TABLE api.toys DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.toys ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.toys DROP COLUMN created_by_id CASCADE;
|
|
ALTER TABLE api.toys ADD COLUMN created_by_id INT;
|
|
ALTER TABLE api.toys DROP COLUMN updated_by_id CASCADE;
|
|
ALTER TABLE api.toys ADD COLUMN updated_by_id INT;
|
|
|
|
-- api.toys_tags
|
|
ALTER TABLE api.toys_tags DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.toys_tags ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.toys_tags DROP COLUMN tag_id CASCADE;
|
|
ALTER TABLE api.toys_tags ADD COLUMN tag_id INT;
|
|
ALTER TABLE api.toys_tags DROP COLUMN toy_id CASCADE;
|
|
ALTER TABLE api.toys_tags ADD COLUMN toy_id INT;
|
|
|
|
-- api.toys_vtubers
|
|
ALTER TABLE api.toys_vtubers DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.toys_vtubers ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.toys_vtubers DROP COLUMN toy_id CASCADE;
|
|
ALTER TABLE api.toys_vtubers ADD COLUMN toy_id INT;
|
|
ALTER TABLE api.toys_vtubers DROP COLUMN vtuber_id CASCADE;
|
|
ALTER TABLE api.toys_vtubers ADD COLUMN vtuber_id INT;
|
|
|
|
-- api.vods
|
|
ALTER TABLE api.vods DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.vods DROP COLUMN mux_asset CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN mux_asset INT;
|
|
ALTER TABLE api.vods DROP COLUMN recording_id CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN recording_id INT;
|
|
ALTER TABLE api.vods DROP COLUMN s3_file CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN s3_file INT;
|
|
ALTER TABLE api.vods DROP COLUMN stream_id CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN stream_id INT;
|
|
ALTER TABLE api.vods DROP COLUMN thumbnail CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN thumbnail INT;
|
|
ALTER TABLE api.vods DROP COLUMN vtuber CASCADE;
|
|
ALTER TABLE api.vods ADD COLUMN vtuber INT;
|
|
|
|
-- api.vods_s3_files_joins
|
|
ALTER TABLE api.vods_s3_files_joins DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.vods_s3_files_joins ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
ALTER TABLE api.vods_s3_files_joins DROP COLUMN s3_file_id CASCADE;
|
|
ALTER TABLE api.vods_s3_files_joins ADD COLUMN s3_file_id INT;
|
|
ALTER TABLE api.vods_s3_files_joins DROP COLUMN vod_id CASCADE;
|
|
ALTER TABLE api.vods_s3_files_joins ADD COLUMN vod_id INT;
|
|
|
|
-- api.vtubers
|
|
ALTER TABLE api.vtubers DROP COLUMN id CASCADE;
|
|
ALTER TABLE api.vtubers ADD COLUMN id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY;
|
|
|
|
END $$;
|