Migration changes

This commit is contained in:
Kira 2020-03-05 12:41:44 -08:00
parent 7f36e438a0
commit 5ce94200c3
4 changed files with 6 additions and 14 deletions

View File

@ -8,7 +8,7 @@ alter table artists add column created_at timestamp not null default now();
alter table artists add column is_banned boolean not null default false;
alter table artists add column creator_id int;
update artists set creator_id = 1;
alter table artists alter column creator_id not null;
alter table artists alter column creator_id set not null;
alter table artists alter column other_names set default '{}'::text[];
update artists set other_names = default where other_names is null;
alter table artists alter column other_names set not null;

View File

@ -7,11 +7,13 @@ alter table pools add column category character varying(30) not null default 'se
add column is_deleted boolean not null default false;
-- Update to support locking in model
alter table pools add column post_ids integer[] not null default '{}'::integer[];
create index temp_pool_posts_ids on pools_posts(pool_id);
create unique index temp_pool_ids on pools(id);
update pools set post_ids = (select coalesce(array_agg(x.post_id), '{}'::integer[]) from (select _.post_id from pools_posts _ where _.pool_id = pools.id order by _.sequence) x);
drop table pools_posts;
drop index temp_pool_ids;
alter table pool_updates rename to pool_versions;
alter table pool_versions drop column is_locked;
alter table pool_versions alter column post_ids drop default;
alter table pool_versions alter column post_ids type integer[] using (string_to_array(post_ids, ' ')::integer[]);
update pool_versions set post_ids = coalesce((select array_agg(val) from unnest(post_ids) with ordinality as t(val, idx) WHERE idx % 2 = 1), '{}'::integer[]);

View File

@ -350,14 +350,6 @@ ALTER TABLE ONLY public.tag_implications
ADD CONSTRAINT tag_implications_pkey PRIMARY KEY (id);
--
-- Name: tag_subscriptions tag_subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tag_subscriptions
ADD CONSTRAINT tag_subscriptions_pkey PRIMARY KEY (id);
--
-- Name: tag_type_versions tag_type_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--

View File

@ -119,9 +119,11 @@ ALTER TABLE public.post_versions ADD CONSTRAINT post_versions_pkey PRIMARY KEY (
-- Deduplicate
create index tmp_post_votes on post_votes(user_id, post_id);
DELETE FROM post_votes a USING post_votes b
WHERE a.id < b.id
AND a.user_id = b.user_id AND a.post_id = b.post_id;
drop index tmp_post_votes;
CREATE UNIQUE INDEX index_post_votes_on_user_id_and_post_id ON post_votes USING btree (user_id, post_id);
CREATE INDEX index_post_votes_on_post_id ON post_votes USING btree (post_id);
@ -155,11 +157,8 @@ CREATE INDEX index_tag_aliases_on_post_count ON tag_aliases USING btree (post_co
CREATE INDEX index_tag_implications_on_antecedent_name ON tag_implications USING btree (antecedent_name);
CREATE INDEX index_tag_implications_on_consequent_name ON tag_implications USING btree (consequent_name);
CREATE INDEX index_tag_implications_on_forum_post_id ON tag_implications USING btree (forum_post_id);
CREATE INDEX index_tag_subscriptions_on_creator_id ON tag_subscriptions USING btree (creator_id);
CREATE INDEX index_tag_subscriptions_on_name ON tag_subscriptions USING btree (name);
CREATE INDEX index_tag_type_versions_on_creator_id ON tag_type_versions USING btree (creator_id);
CREATE INDEX index_tag_type_versions_on_tag_id ON tag_type_versions USING btree (tag_id);
ALTER TABLE public.tag_type_versions ADD CONSTRAINT tag_type_versions_pkey PRIMARY KEY (id);
CREATE INDEX index_tag_rel_undos_on_tag_rel_type_and_tag_rel_id ON tag_rel_undos USING btree (tag_rel_type, tag_rel_id);
ALTER TABLE tag_rel_undos ADD CONSTRAINT tag_rel_undos_pkey PRIMARY KEY (id);
@ -179,7 +178,6 @@ CREATE INDEX index_user_name_change_requests_on_original_name ON user_name_chang
CREATE INDEX index_user_name_change_requests_on_user_id ON user_name_change_requests USING btree (user_id);
CREATE UNIQUE INDEX user_password_reset_nonces_pkey ON user_password_reset_nonces USING btree (id);
ALTER TABLE public.user_password_reset_nonces ADD CONSTRAINT user_password_reset_nonces_pkey PRIMARY KEY (id); -- (1);