From bfe2eabc6d63ac92db97798432f0de8d5b464271 Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 14 Sep 2022 16:22:46 -0500 Subject: [PATCH] db: change ids from bigint to integer on various tables. Change ID columns from `bigint` (64-bits) to `integer` (32-bits) on various tables. Rails 6.0 switched the default from bigint to integer for IDs on new tables, so now we have a mix of tables with integer IDs and bigint IDs. Switch back to integer IDs on certain tables because we're going to build a view that unions a bunch of tables together to build a user activity timeline, and for this purpose all the tables need to have IDs of the same type in order for Postgres to optimize the query effectively. --- ...00_change_ids_to_integer_on_user_tables.rb | 33 +++++++++++++++++++ db/structure.sql | 29 ++++++++-------- 2 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 db/migrate/20220913191300_change_ids_to_integer_on_user_tables.rb diff --git a/db/migrate/20220913191300_change_ids_to_integer_on_user_tables.rb b/db/migrate/20220913191300_change_ids_to_integer_on_user_tables.rb new file mode 100644 index 000000000..7964f22ab --- /dev/null +++ b/db/migrate/20220913191300_change_ids_to_integer_on_user_tables.rb @@ -0,0 +1,33 @@ +class ChangeIdsToIntegerOnUserTables < ActiveRecord::Migration[7.0] + def up + change_column :forum_post_votes, :id, :integer + change_column :moderation_reports, :id, :integer + change_column :moderation_reports, :model_id, :integer + change_column :tag_versions, :id, :integer + change_column :tag_versions, :tag_id, :integer + change_column :tag_versions, :previous_version_id, :integer + change_column :tag_versions, :updater_id, :integer + change_column :user_upgrades, :id, :integer + change_column :user_upgrades, :recipient_id, :integer + change_column :user_upgrades, :purchaser_id, :integer + change_column :user_events, :id, :integer + change_column :user_events, :user_id, :integer + change_column :user_events, :user_session_id, :integer + end + + def down + change_column :forum_post_votes, :id, :bigint + change_column :moderation_reports, :id, :bigint + change_column :moderation_reports, :model_id, :bigint + change_column :tag_versions, :id, :bigint + change_column :tag_versions, :tag_id, :bigint + change_column :tag_versions, :previous_version_id, :bigint + change_column :tag_versions, :updater_id, :bigint + change_column :user_upgrades, :id, :bigint + change_column :user_upgrades, :recipient_id, :bigint + change_column :user_upgrades, :purchaser_id, :bigint + change_column :user_events, :id, :bigint + change_column :user_events, :user_id, :bigint + change_column :user_events, :user_session_id, :bigint + end +end diff --git a/db/structure.sql b/db/structure.sql index a337bdaa7..2892a231e 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -664,7 +664,7 @@ ALTER SEQUENCE public.favorites_id_seq OWNED BY public.favorites.id; -- CREATE TABLE public.forum_post_votes ( - id bigint NOT NULL, + id integer NOT NULL, forum_post_id integer NOT NULL, creator_id integer NOT NULL, score integer NOT NULL, @@ -1209,11 +1209,11 @@ ALTER SEQUENCE public.mod_actions_id_seq OWNED BY public.mod_actions.id; -- CREATE TABLE public.moderation_reports ( - id bigint NOT NULL, + id integer NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, model_type character varying NOT NULL, - model_id bigint NOT NULL, + model_id integer NOT NULL, creator_id integer NOT NULL, reason text NOT NULL, status integer DEFAULT 0 NOT NULL @@ -1889,12 +1889,12 @@ ALTER SEQUENCE public.tag_implications_id_seq OWNED BY public.tag_implications.i -- CREATE TABLE public.tag_versions ( - id bigint NOT NULL, + id integer NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, - tag_id bigint NOT NULL, - updater_id bigint, - previous_version_id bigint, + tag_id integer NOT NULL, + updater_id integer, + previous_version_id integer, version integer NOT NULL, name character varying NOT NULL, category integer NOT NULL, @@ -2071,11 +2071,11 @@ ALTER SEQUENCE public.uploads_id_seq OWNED BY public.uploads.id; -- CREATE TABLE public.user_events ( - id bigint NOT NULL, + id integer NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, - user_id bigint NOT NULL, - user_session_id bigint NOT NULL, + user_id integer NOT NULL, + user_session_id integer NOT NULL, category integer NOT NULL ); @@ -2207,11 +2207,11 @@ ALTER SEQUENCE public.user_sessions_id_seq OWNED BY public.user_sessions.id; -- CREATE TABLE public.user_upgrades ( - id bigint NOT NULL, + id integer NOT NULL, created_at timestamp(6) without time zone NOT NULL, updated_at timestamp(6) without time zone NOT NULL, - recipient_id bigint NOT NULL, - purchaser_id bigint NOT NULL, + recipient_id integer NOT NULL, + purchaser_id integer NOT NULL, upgrade_type integer NOT NULL, status integer NOT NULL, transaction_id character varying, @@ -6125,6 +6125,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20220627211714'), ('20220829184824'), ('20220909205433'), -('20220909211649'); +('20220909211649'), +('20220913191300');