favgroups: convert post_ids from string to array.
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
class ChangePostIdsToArrayOnFavoriteGroups < ActiveRecord::Migration[6.0]
|
||||
def up
|
||||
execute "set statement_timeout = 0"
|
||||
|
||||
change_column_default :favorite_groups, :post_ids, nil
|
||||
change_column :favorite_groups, :post_ids, "integer[]", using: "string_to_array(post_ids, ' ')::integer[]"
|
||||
change_column_default :favorite_groups, :post_ids, "{}"
|
||||
add_index :favorite_groups, :post_ids, using: :gin
|
||||
|
||||
remove_column :favorite_groups, :post_count
|
||||
end
|
||||
|
||||
def down
|
||||
execute "set statement_timeout = 0"
|
||||
|
||||
remove_index :favorite_groups, :post_ids
|
||||
change_column_default :favorite_groups, :post_ids, nil
|
||||
change_column :favorite_groups, :post_ids, :text, using: "array_to_string(post_ids, ' ')"
|
||||
change_column_default :favorite_groups, :post_ids, ""
|
||||
|
||||
add_column :favorite_groups, :post_count, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
@@ -921,8 +921,7 @@ CREATE TABLE public.favorite_groups (
|
||||
id integer NOT NULL,
|
||||
name text NOT NULL,
|
||||
creator_id integer NOT NULL,
|
||||
post_ids text DEFAULT ''::text NOT NULL,
|
||||
post_count integer DEFAULT 0 NOT NULL,
|
||||
post_ids integer[] DEFAULT '{}'::integer[] NOT NULL,
|
||||
created_at timestamp without time zone NOT NULL,
|
||||
updated_at timestamp without time zone NOT NULL,
|
||||
is_public boolean DEFAULT false NOT NULL
|
||||
@@ -4975,6 +4974,13 @@ CREATE INDEX index_favorite_groups_on_creator_id ON public.favorite_groups USING
|
||||
CREATE INDEX index_favorite_groups_on_lower_name ON public.favorite_groups USING btree (lower(name));
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_favorite_groups_on_post_ids; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_favorite_groups_on_post_ids ON public.favorite_groups USING gin (post_ids);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_favorites_0_on_post_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
@@ -7400,6 +7406,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20191117200404'),
|
||||
('20191119061018'),
|
||||
('20191223032633'),
|
||||
('20200114204550');
|
||||
('20200114204550'),
|
||||
('20200115010442');
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user