Skip to content

Commit d9499e9

Browse files
Gargronhiyuki2578
authored andcommitted
Change identities id column to a bigint (mastodon#9371)
* fix: change Identity's id column to a bigint This appears to be the last model created using a 5.0 migration, where column types defaulted to `integer` rather than `bigint`. This migration changes the column type to match that of all of the other ID columns. * Change user_id column in identities to bigint and fix down-migration
1 parent bea7f6a commit d9499e9

3 files changed

Lines changed: 33 additions & 6 deletions

File tree

app/models/identity.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#
44
# Table name: identities
55
#
6-
# id :integer not null, primary key
7-
# user_id :integer
86
# provider :string default(""), not null
97
# uid :string default(""), not null
108
# created_at :datetime not null
119
# updated_at :datetime not null
10+
# id :bigint(8) not null, primary key
11+
# user_id :bigint(8)
1212
#
1313

1414
class Identity < ApplicationRecord
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
require Rails.root.join('lib', 'mastodon', 'migration_helpers')
2+
3+
class IdentityIdToBigint < ActiveRecord::Migration[5.2]
4+
include Mastodon::MigrationHelpers
5+
6+
disable_ddl_transaction!
7+
8+
def up
9+
safety_assured do
10+
change_column_type_concurrently :identities, :id, :bigint
11+
cleanup_concurrent_column_type_change :identities, :id
12+
13+
change_column_type_concurrently :identities, :user_id, :bigint
14+
cleanup_concurrent_column_type_change :identities, :user_id
15+
end
16+
end
17+
18+
def down
19+
safety_assured do
20+
change_column_type_concurrently :identities, :id, :integer
21+
cleanup_concurrent_column_type_change :identities, :id
22+
23+
change_column_type_concurrently :identities, :user_id, :integer
24+
cleanup_concurrent_column_type_change :identities, :user_id
25+
end
26+
end
27+
end

db/schema.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema.define(version: 2018_11_22_090024) do
13+
ActiveRecord::Schema.define(version: 2018_11_27_130500) do
1414

1515
# These are extensions that must be enabled in order to support this database
1616
enable_extension "plpgsql"
@@ -236,12 +236,12 @@
236236
t.index ["target_account_id"], name: "index_follows_on_target_account_id"
237237
end
238238

239-
create_table "identities", id: :serial, force: :cascade do |t|
240-
t.integer "user_id"
239+
create_table "identities", force: :cascade do |t|
241240
t.string "provider", default: "", null: false
242241
t.string "uid", default: "", null: false
243242
t.datetime "created_at", null: false
244243
t.datetime "updated_at", null: false
244+
t.bigint "user_id"
245245
t.index ["user_id"], name: "index_identities_on_user_id"
246246
end
247247

@@ -652,7 +652,7 @@
652652
add_foreign_key "follow_requests", "accounts", name: "fk_76d644b0e7", on_delete: :cascade
653653
add_foreign_key "follows", "accounts", column: "target_account_id", name: "fk_745ca29eac", on_delete: :cascade
654654
add_foreign_key "follows", "accounts", name: "fk_32ed1b5560", on_delete: :cascade
655-
add_foreign_key "identities", "users", on_delete: :cascade
655+
add_foreign_key "identities", "users", name: "fk_bea040f377", on_delete: :cascade
656656
add_foreign_key "imports", "accounts", name: "fk_6db1b6e408", on_delete: :cascade
657657
add_foreign_key "invites", "users", on_delete: :cascade
658658
add_foreign_key "list_accounts", "accounts", on_delete: :cascade

0 commit comments

Comments
 (0)