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.
This commit is contained in:
evazion
2022-09-14 16:22:46 -05:00
parent 86b2d25f21
commit bfe2eabc6d
2 changed files with 48 additions and 14 deletions

View File

@@ -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