Merge pull request #3989 from evazion/fix-3987

Wiki pages: convert other_names column to array (#3987)
This commit is contained in:
Albert Yi
2018-11-19 16:23:32 -08:00
committed by GitHub
27 changed files with 238 additions and 181 deletions

View File

@@ -0,0 +1,26 @@
class ChangeStringsToArraysOnWikiPages < ActiveRecord::Migration[5.2]
def up
WikiPage.without_timeout do
change_column :wiki_pages, :other_names, "text[]", using: "string_to_array(other_names, ' ')::text[]", default: "{}"
change_column :wiki_page_versions, :other_names, "text[]", using: "string_to_array(other_names, ' ')::text[]", default: "{}"
remove_column :wiki_pages, :other_names_index
execute "DROP TRIGGER trigger_wiki_pages_on_update_for_other_names ON wiki_pages"
add_index :wiki_pages, :other_names, using: :gin
end
end
def down
WikiPage.without_timeout do
remove_index :wiki_pages, :other_names
add_column :wiki_pages, :other_names_index, :tsvector
add_index :wiki_pages, :other_names_index, using: :gin
execute "CREATE TRIGGER trigger_wiki_pages_on_update_for_other_names BEFORE INSERT OR UPDATE ON wiki_pages FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names')"
change_column :wiki_pages, :other_names, "text", using: "array_to_string(other_names, ' ')", default: nil
change_column :wiki_page_versions, :other_names, "text", using: "array_to_string(other_names, ' ')", default: nil
end
end
end

View File

@@ -0,0 +1,13 @@
class ChangeDescendantNamesToArrayOnTagImplications < ActiveRecord::Migration[5.2]
def up
TagImplication.without_timeout do
change_column :tag_implications, :descendant_names, "text[]", using: "string_to_array(descendant_names, ' ')::text[]", default: "{}"
end
end
def down
TagImplication.without_timeout do
change_column :tag_implications, :descendant_names, "text", using: "array_to_string(descendant_names, ' ')", default: nil
end
end
end

View File

@@ -0,0 +1,19 @@
class ChangeStringsToArraysOnArtistVersions < ActiveRecord::Migration[5.2]
def up
ArtistVersion.without_timeout do
change_column :artist_versions, :other_names, "text[]", using: "array_remove(regexp_split_to_array(other_names, '\\s+'), '')", default: "{}"
change_column :artist_versions, :url_string, "text[]", using: "array_remove(regexp_split_to_array(url_string, '\\s+'), '')", default: "{}"
rename_column :artist_versions, :url_string, :urls
end
end
def down
ArtistVersion.without_timeout do
rename_column :artist_versions, :urls, :url_string
change_column :artist_versions, :url_string, "text", using: "array_to_string(url_string, '\\n')", default: nil
change_column :artist_versions, :other_names, "text", using: "array_to_string(other_names, ' ')", default: nil
end
end
end

View File

@@ -0,0 +1,23 @@
class ChangeOtherNamesToArrayOnArtists < ActiveRecord::Migration[5.2]
def up
Artist.without_timeout do
remove_index :artists, name: "index_artists_on_other_names_trgm"
change_column :artists, :other_names, "text[]", using: "array_remove(regexp_split_to_array(other_names, '\\s+'), '')", default: "{}"
add_index :artists, :other_names, using: :gin
remove_column :artists, :other_names_index
execute "DROP TRIGGER trigger_artists_on_update ON artists"
end
end
def down
Artist.without_timeout do
remove_index :artists, :other_names
change_column :artists, :other_names, "text", using: "array_to_string(other_names, ' ')", default: nil
add_index :artists, :other_names, name: "index_artists_on_other_names_trgm", using: :gin, opclass: :gin_trgm_ops
add_column :artists, :other_names_index, :tsvector
execute "CREATE TRIGGER trigger_artists_on_update BEFORE INSERT OR UPDATE ON artists FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names')"
end
end
end

View File

@@ -718,9 +718,9 @@ CREATE TABLE public.artist_versions (
updater_id integer NOT NULL,
updater_ip_addr inet NOT NULL,
is_active boolean DEFAULT true NOT NULL,
other_names text,
other_names text[] DEFAULT '{}'::text[],
group_name character varying,
url_string text,
urls text[] DEFAULT '{}'::text[],
is_banned boolean DEFAULT false NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
@@ -756,8 +756,7 @@ CREATE TABLE public.artists (
creator_id integer NOT NULL,
is_active boolean DEFAULT true NOT NULL,
is_banned boolean DEFAULT false NOT NULL,
other_names text,
other_names_index tsvector,
other_names text[] DEFAULT '{}'::text[],
group_name character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone
@@ -2971,7 +2970,7 @@ CREATE TABLE public.tag_implications (
id integer NOT NULL,
antecedent_name character varying NOT NULL,
consequent_name character varying NOT NULL,
descendant_names text NOT NULL,
descendant_names text[] DEFAULT '{}'::text[] NOT NULL,
creator_id integer NOT NULL,
creator_ip_addr inet NOT NULL,
forum_topic_id integer,
@@ -3314,7 +3313,7 @@ CREATE TABLE public.wiki_page_versions (
is_locked boolean NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
other_names text,
other_names text[] DEFAULT '{}'::text[],
is_deleted boolean DEFAULT false NOT NULL
);
@@ -3352,8 +3351,7 @@ CREATE TABLE public.wiki_pages (
created_at timestamp without time zone,
updated_at timestamp without time zone,
updater_id integer,
other_names text,
other_names_index tsvector,
other_names text[] DEFAULT '{}'::text[],
is_deleted boolean DEFAULT false NOT NULL
);
@@ -5028,17 +5026,10 @@ CREATE INDEX index_artists_on_name_trgm ON public.artists USING gin (name public
--
-- Name: index_artists_on_other_names_index; Type: INDEX; Schema: public; Owner: -
-- Name: index_artists_on_other_names; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_artists_on_other_names_index ON public.artists USING gin (other_names_index);
--
-- Name: index_artists_on_other_names_trgm; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_artists_on_other_names_trgm ON public.artists USING gin (other_names public.gin_trgm_ops);
CREATE INDEX index_artists_on_other_names ON public.artists USING gin (other_names);
--
@@ -7261,10 +7252,10 @@ CREATE INDEX index_wiki_pages_on_body_index_index ON public.wiki_pages USING gin
--
-- Name: index_wiki_pages_on_other_names_index; Type: INDEX; Schema: public; Owner: -
-- Name: index_wiki_pages_on_other_names; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_wiki_pages_on_other_names_index ON public.wiki_pages USING gin (other_names_index);
CREATE INDEX index_wiki_pages_on_other_names ON public.wiki_pages USING gin (other_names);
--
@@ -7295,13 +7286,6 @@ CREATE INDEX index_wiki_pages_on_updated_at ON public.wiki_pages USING btree (up
CREATE TRIGGER insert_favorites_trigger BEFORE INSERT ON public.favorites FOR EACH ROW EXECUTE PROCEDURE public.favorites_insert_trigger();
--
-- Name: artists trigger_artists_on_update; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER trigger_artists_on_update BEFORE INSERT OR UPDATE ON public.artists FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names');
--
-- Name: comments trigger_comments_on_update; Type: TRIGGER; Schema: public; Owner: -
--
@@ -7351,13 +7335,6 @@ CREATE TRIGGER trigger_posts_on_tag_index_update BEFORE INSERT OR UPDATE ON publ
CREATE TRIGGER trigger_wiki_pages_on_update BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('body_index', 'public.danbooru', 'body', 'title');
--
-- Name: wiki_pages trigger_wiki_pages_on_update_for_other_names; Type: TRIGGER; Schema: public; Owner: -
--
CREATE TRIGGER trigger_wiki_pages_on_update_for_other_names BEFORE INSERT OR UPDATE ON public.wiki_pages FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('other_names_index', 'public.danbooru', 'other_names');
--
-- PostgreSQL database dump complete
--
@@ -7528,6 +7505,10 @@ INSERT INTO "schema_migrations" (version) VALUES
('20180913184128'),
('20180916002448'),
('20181108162204'),
('20181108205842');
('20181108205842'),
('20181113174914'),
('20181114180205'),
('20181114185032'),
('20181114202744');