diff --git a/db/migrate/20200803193841_update_user_follow_identity_reaction_pks_to_bigints.rb b/db/migrate/20200803193841_update_user_follow_identity_reaction_pks_to_bigints.rb new file mode 100644 index 000000000..a90250476 --- /dev/null +++ b/db/migrate/20200803193841_update_user_follow_identity_reaction_pks_to_bigints.rb @@ -0,0 +1,70 @@ +class UpdateUserFollowIdentityReactionPksToBigints < ActiveRecord::Migration[6.0] + def up + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.follows") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE follows + ALTER COLUMN id TYPE bigint, + ALTER COLUMN followable_id TYPE bigint, + ALTER COLUMN follower_id TYPE bigint + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.identities") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE identities + ALTER COLUMN id TYPE bigint, + ALTER COLUMN user_id TYPE bigint + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.reactions") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE reactions + ALTER COLUMN id TYPE bigint, + ALTER COLUMN reactable_id TYPE bigint, + ALTER COLUMN user_id TYPE bigint + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.users") + safety_assured { change_column :users, :id, :bigint } + end + + def down + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.follows") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE follows + ALTER COLUMN id TYPE int, + ALTER COLUMN followable_id TYPE int, + ALTER COLUMN follower_id TYPE int + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.identities") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE identities + ALTER COLUMN id TYPE int, + ALTER COLUMN user_id TYPE int + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.reactions") + ActiveRecord::Base.connection.execute( + <<-SQL + ALTER TABLE reactions + ALTER COLUMN id TYPE int, + ALTER COLUMN reactable_id TYPE int, + ALTER COLUMN user_id TYPE int + SQL + ) + + ActiveRecord::Base.connection.execute("DROP VIEW IF EXISTS hypershield.users") + safety_assured { change_column :users, :id, :int } + end +end + diff --git a/db/schema.rb b/db/schema.rb index 2b0b35239..4a5bd643f 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -545,12 +545,12 @@ ActiveRecord::Schema.define(version: 2020_08_05_050048) do t.index ["feature_key", "key", "value"], name: "index_flipper_gates_on_feature_key_and_key_and_value", unique: true end - create_table "follows", id: :serial, force: :cascade do |t| + create_table "follows", force: :cascade do |t| t.boolean "blocked", default: false, null: false t.datetime "created_at" - t.integer "followable_id", null: false + t.bigint "followable_id", null: false t.string "followable_type", null: false - t.integer "follower_id", null: false + t.bigint "follower_id", null: false t.string "follower_type", null: false t.float "points", default: 1.0 t.string "subscription_status", default: "all_articles", null: false @@ -622,7 +622,7 @@ ActiveRecord::Schema.define(version: 2020_08_05_050048) do t.index ["name"], name: "index_html_variants_on_name", unique: true end - create_table "identities", id: :serial, force: :cascade do |t| + create_table "identities", force: :cascade do |t| t.text "auth_data_dump" t.datetime "created_at", null: false t.string "provider" @@ -630,7 +630,7 @@ ActiveRecord::Schema.define(version: 2020_08_05_050048) do t.string "token" t.string "uid" t.datetime "updated_at", null: false - t.integer "user_id" + t.bigint "user_id" t.index ["provider", "uid"], name: "index_identities_on_provider_and_uid", unique: true t.index ["provider", "user_id"], name: "index_identities_on_provider_and_user_id", unique: true end @@ -958,15 +958,15 @@ ActiveRecord::Schema.define(version: 2020_08_05_050048) do t.index ["user_id"], name: "index_rating_votes_on_user_id" end - create_table "reactions", id: :serial, force: :cascade do |t| + create_table "reactions", force: :cascade do |t| t.string "category" t.datetime "created_at", null: false t.float "points", default: 1.0 - t.integer "reactable_id" + t.bigint "reactable_id" t.string "reactable_type" t.string "status", default: "valid" t.datetime "updated_at", null: false - t.integer "user_id" + t.bigint "user_id" t.index ["category"], name: "index_reactions_on_category" t.index ["created_at"], name: "index_reactions_on_created_at" t.index ["points"], name: "index_reactions_on_points" @@ -1149,7 +1149,7 @@ ActiveRecord::Schema.define(version: 2020_08_05_050048) do t.index ["user_subscription_sourceable_type", "user_subscription_sourceable_id"], name: "index_on_user_subscription_sourcebable_type_and_id" end - create_table "users", id: :serial, force: :cascade do |t| + create_table "users", force: :cascade do |t| t.integer "articles_count", default: 0, null: false t.string "available_for" t.integer "badge_achievements_count", default: 0, null: false