From 21b1afb07602f4eecdeee8814ae250f3f53a12dd Mon Sep 17 00:00:00 2001 From: Molly Struve Date: Sat, 25 Jul 2020 16:11:26 -0500 Subject: [PATCH] [deploy] Optimization:Change Mentions, Notes, Podcasts, Roles Related Ids To Bigints (#9477) --- ...s_podcasts_roles_related_ids_to_bigints.rb | 41 +++++++++++++++++++ db/schema.rb | 12 +++--- 2 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20200723203155_change_mentions_notes_podcasts_roles_related_ids_to_bigints.rb diff --git a/db/migrate/20200723203155_change_mentions_notes_podcasts_roles_related_ids_to_bigints.rb b/db/migrate/20200723203155_change_mentions_notes_podcasts_roles_related_ids_to_bigints.rb new file mode 100644 index 000000000..1d0c57329 --- /dev/null +++ b/db/migrate/20200723203155_change_mentions_notes_podcasts_roles_related_ids_to_bigints.rb @@ -0,0 +1,41 @@ +class ChangeMentionsNotesPodcastsRolesRelatedIdsToBigints < ActiveRecord::Migration[6.0] + def up + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.mentions") + safety_assured { change_column :mentions, :user_id, :bigint } + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.notes") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE notes + ALTER COLUMN author_id TYPE bigint, + ALTER COLUMN noteable_id TYPE bigint + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.podcasts") + safety_assured { change_column :podcasts, :creator_id, :bigint } + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.roles") + safety_assured { change_column :roles, :resource_id, :bigint } + end + + def down + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.mentions") + safety_assured { change_column :mentions, :user_id, :int } + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.notes") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE notes + ALTER COLUMN author_id TYPE int, + ALTER COLUMN noteable_id TYPE int + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.podcasts") + safety_assured { change_column :podcasts, :creator_id, :int } + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.roles") + safety_assured { change_column :roles, :resource_id, :int } + end +end diff --git a/db/schema.rb b/db/schema.rb index 3e27f5133..0e4e1bbbf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_07_23_180841) do +ActiveRecord::Schema.define(version: 2020_07_23_203155) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -639,7 +639,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_180841) do t.integer "mentionable_id" t.string "mentionable_type" t.datetime "updated_at", null: false - t.integer "user_id" + t.bigint "user_id" t.index ["user_id", "mentionable_id", "mentionable_type"], name: "index_mentions_on_user_id_and_mentionable_id_mentionable_type", unique: true end @@ -657,10 +657,10 @@ ActiveRecord::Schema.define(version: 2020_07_23_180841) do end create_table "notes", force: :cascade do |t| - t.integer "author_id" + t.bigint "author_id" t.text "content" t.datetime "created_at", null: false - t.integer "noteable_id" + t.bigint "noteable_id" t.string "noteable_type" t.string "reason" t.datetime "updated_at", null: false @@ -859,7 +859,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_180841) do create_table "podcasts", force: :cascade do |t| t.string "android_url" t.datetime "created_at", null: false - t.integer "creator_id" + t.bigint "creator_id" t.text "description" t.string "feed_url", null: false t.string "image", null: false @@ -981,7 +981,7 @@ ActiveRecord::Schema.define(version: 2020_07_23_180841) do create_table "roles", force: :cascade do |t| t.datetime "created_at" t.string "name" - t.integer "resource_id" + t.bigint "resource_id" t.string "resource_type" t.datetime "updated_at" t.index ["name", "resource_type", "resource_id"], name: "index_roles_on_name_and_resource_type_and_resource_id"