migration to remove old unused invitation columns from users table
This commit is contained in:
parent
16618e1054
commit
6cf1cd5d76
2 changed files with 77 additions and 30 deletions
|
|
@ -0,0 +1,74 @@
|
|||
class CleanupInvitationColumnsFromUsers < ActiveRecord::Migration
|
||||
class User < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def change
|
||||
remove_index :users, column: %i(invitation_service invitation_identifier),
|
||||
name: :index_users_on_invitation_service_and_invitation_identifier,
|
||||
unique: true, length: {invitation_service: 64}
|
||||
remove_index :users, column: :invitation_token, name: :index_users_on_invitation_token
|
||||
remove_index :users, column: :email, name: :index_users_on_email, length: 191
|
||||
|
||||
username_not_null
|
||||
|
||||
remove_column :users, :invitation_token, :string, limit: 60
|
||||
remove_column :users, :invitation_sent_at, :datetime
|
||||
remove_column :users, :invitation_service, :string, limit: 127
|
||||
remove_column :users, :invitation_identifier, :string, limit: 127
|
||||
remove_column :users, :invitation_limit, :integer
|
||||
remove_column :users, :invited_by_type, :string
|
||||
|
||||
add_index :users, :email, name: :index_users_on_email, unique: true, length: 191
|
||||
|
||||
drop_invitations_table
|
||||
end
|
||||
|
||||
def username_not_null
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
User.delete_all(username: nil)
|
||||
change_column :users, :username, :string, null: false
|
||||
end
|
||||
|
||||
dir.down do
|
||||
change_column :users, :username, :string, null: true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def drop_invitations_table
|
||||
reversible do |dir|
|
||||
dir.up do
|
||||
drop_table :invitations
|
||||
end
|
||||
|
||||
dir.down do
|
||||
create_invitations_table
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_invitations_table
|
||||
# rubocop:disable Style/ExtraSpacing
|
||||
create_table :invitations, force: :cascade do |t|
|
||||
t.text :message, limit: 65_535
|
||||
t.integer :sender_id, limit: 4
|
||||
t.integer :recipient_id, limit: 4
|
||||
t.integer :aspect_id, limit: 4
|
||||
t.datetime :created_at, null: false
|
||||
t.datetime :updated_at, null: false
|
||||
t.string :service, limit: 255
|
||||
t.string :identifier, limit: 255
|
||||
t.boolean :admin, default: false
|
||||
t.string :language, limit: 255, default: "en"
|
||||
end
|
||||
# rubocop:enable Style/ExtraSpacing
|
||||
|
||||
add_index :invitations, :aspect_id, name: :index_invitations_on_aspect_id, using: :btree
|
||||
add_index :invitations, :recipient_id, name: :index_invitations_on_recipient_id, using: :btree
|
||||
add_index :invitations, :sender_id, name: :index_invitations_on_sender_id, using: :btree
|
||||
|
||||
add_foreign_key :invitations, :users, column: :recipient_id, name: :invitations_recipient_id_fk, on_delete: :cascade
|
||||
add_foreign_key :invitations, :users, column: :sender_id, name: :invitations_sender_id_fk, on_delete: :cascade
|
||||
end
|
||||
end
|
||||
33
db/schema.rb
33
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20160807212443) do
|
||||
ActiveRecord::Schema.define(version: 20160810230114) do
|
||||
|
||||
create_table "account_deletions", force: :cascade do |t|
|
||||
t.string "diaspora_handle", limit: 255
|
||||
|
|
@ -178,23 +178,6 @@ ActiveRecord::Schema.define(version: 20160807212443) do
|
|||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "invitations", force: :cascade do |t|
|
||||
t.text "message", limit: 65535
|
||||
t.integer "sender_id", limit: 4
|
||||
t.integer "recipient_id", limit: 4
|
||||
t.integer "aspect_id", limit: 4
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "service", limit: 255
|
||||
t.string "identifier", limit: 255
|
||||
t.boolean "admin", default: false
|
||||
t.string "language", limit: 255, default: "en"
|
||||
end
|
||||
|
||||
add_index "invitations", ["aspect_id"], name: "index_invitations_on_aspect_id", using: :btree
|
||||
add_index "invitations", ["recipient_id"], name: "index_invitations_on_recipient_id", using: :btree
|
||||
add_index "invitations", ["sender_id"], name: "index_invitations_on_sender_id", using: :btree
|
||||
|
||||
create_table "like_signatures", id: false, force: :cascade do |t|
|
||||
t.integer "like_id", limit: 4, null: false
|
||||
t.text "author_signature", limit: 65535, null: false
|
||||
|
|
@ -624,15 +607,13 @@ ActiveRecord::Schema.define(version: 20160807212443) do
|
|||
end
|
||||
|
||||
create_table "users", force: :cascade do |t|
|
||||
t.string "username", limit: 255
|
||||
t.string "username", limit: 255, null: false
|
||||
t.text "serialized_private_key", limit: 65535
|
||||
t.boolean "getting_started", default: true, null: false
|
||||
t.boolean "disable_mail", default: false, null: false
|
||||
t.string "language", limit: 255
|
||||
t.string "email", limit: 255, default: "", null: false
|
||||
t.string "encrypted_password", limit: 255, default: "", null: false
|
||||
t.string "invitation_token", limit: 60
|
||||
t.datetime "invitation_sent_at"
|
||||
t.string "reset_password_token", limit: 255
|
||||
t.datetime "remember_created_at"
|
||||
t.integer "sign_in_count", limit: 4, default: 0
|
||||
|
|
@ -642,11 +623,7 @@ ActiveRecord::Schema.define(version: 20160807212443) do
|
|||
t.string "last_sign_in_ip", limit: 255
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "invitation_service", limit: 127
|
||||
t.string "invitation_identifier", limit: 127
|
||||
t.integer "invitation_limit", limit: 4
|
||||
t.integer "invited_by_id", limit: 4
|
||||
t.string "invited_by_type", limit: 255
|
||||
t.string "authentication_token", limit: 30
|
||||
t.string "unconfirmed_email", limit: 255
|
||||
t.string "confirm_email_token", limit: 30
|
||||
|
|
@ -669,9 +646,7 @@ ActiveRecord::Schema.define(version: 20160807212443) do
|
|||
end
|
||||
|
||||
add_index "users", ["authentication_token"], name: "index_users_on_authentication_token", unique: true, using: :btree
|
||||
add_index "users", ["email"], name: "index_users_on_email", length: {"email"=>191}, using: :btree
|
||||
add_index "users", ["invitation_service", "invitation_identifier"], name: "index_users_on_invitation_service_and_invitation_identifier", unique: true, length: {"invitation_service"=>64, "invitation_identifier"=>nil}, using: :btree
|
||||
add_index "users", ["invitation_token"], name: "index_users_on_invitation_token", using: :btree
|
||||
add_index "users", ["email"], name: "index_users_on_email", unique: true, length: {"email"=>191}, using: :btree
|
||||
add_index "users", ["username"], name: "index_users_on_username", unique: true, length: {"username"=>191}, using: :btree
|
||||
|
||||
add_foreign_key "aspect_memberships", "aspects", name: "aspect_memberships_aspect_id_fk", on_delete: :cascade
|
||||
|
|
@ -687,8 +662,6 @@ ActiveRecord::Schema.define(version: 20160807212443) do
|
|||
add_foreign_key "conversation_visibilities", "people", name: "conversation_visibilities_person_id_fk", on_delete: :cascade
|
||||
add_foreign_key "conversations", "people", column: "author_id", name: "conversations_author_id_fk", on_delete: :cascade
|
||||
add_foreign_key "id_tokens", "authorizations"
|
||||
add_foreign_key "invitations", "users", column: "recipient_id", name: "invitations_recipient_id_fk", on_delete: :cascade
|
||||
add_foreign_key "invitations", "users", column: "sender_id", name: "invitations_sender_id_fk", on_delete: :cascade
|
||||
add_foreign_key "like_signatures", "likes", name: "like_signatures_like_id_fk", on_delete: :cascade
|
||||
add_foreign_key "like_signatures", "signature_orders", name: "like_signatures_signature_orders_id_fk"
|
||||
add_foreign_key "likes", "people", column: "author_id", name: "likes_author_id_fk", on_delete: :cascade
|
||||
|
|
|
|||
Loading…
Reference in a new issue