chore: Clean up migrations (#3613)

Fixes: #3530
This commit is contained in:
Sojan Jose 2021-12-19 09:47:07 +05:30 committed by GitHub
parent 5ee209c079
commit 8d65608666
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 114 additions and 46 deletions

View file

@ -87,6 +87,7 @@ Naming/VariableNumber:
Metrics/MethodLength:
Exclude:
- 'db/migrate/20161123131628_devise_token_auth_create_users.rb'
- 'db/migrate/20211219031453_update_foreign_keys_on_delete.rb'
Rails/CreateTableWithTimestamps:
Exclude:
- 'db/migrate/20170207092002_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb'
@ -102,6 +103,7 @@ Metrics/AbcSize:
- 'db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb'
- 'db/migrate/20161123131628_devise_token_auth_create_users.rb'
- 'app/controllers/api/v1/accounts/inboxes_controller.rb'
- 'db/migrate/20211219031453_update_foreign_keys_on_delete.rb'
Metrics/CyclomaticComplexity:
Max: 7
Exclude:

View file

@ -21,8 +21,8 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (user_id => users.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
# fk_rails_... (user_id => users.id) ON DELETE => cascade
#
class AccountUser < ApplicationRecord

View file

@ -16,7 +16,7 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
#
class AgentBot < ApplicationRecord

View file

@ -30,8 +30,8 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (inbox_id => inboxes.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
# fk_rails_... (inbox_id => inboxes.id) ON DELETE => cascade
#
class Campaign < ApplicationRecord
validates :account_id, presence: true

View file

@ -21,8 +21,8 @@
#
# Foreign Keys
#
# fk_rails_... (contact_id => contacts.id)
# fk_rails_... (inbox_id => inboxes.id)
# fk_rails_... (contact_id => contacts.id) ON DELETE => cascade
# fk_rails_... (inbox_id => inboxes.id) ON DELETE => cascade
#
class ContactInbox < ApplicationRecord

View file

@ -36,9 +36,9 @@
#
# Foreign Keys
#
# fk_rails_... (campaign_id => campaigns.id)
# fk_rails_... (contact_inbox_id => contact_inboxes.id)
# fk_rails_... (team_id => teams.id)
# fk_rails_... (campaign_id => campaigns.id) ON DELETE => cascade
# fk_rails_... (contact_inbox_id => contact_inboxes.id) ON DELETE => cascade
# fk_rails_... (team_id => teams.id) ON DELETE => cascade
#
class Conversation < ApplicationRecord

View file

@ -23,11 +23,11 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (assigned_agent_id => users.id)
# fk_rails_... (contact_id => contacts.id)
# fk_rails_... (conversation_id => conversations.id)
# fk_rails_... (message_id => messages.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
# fk_rails_... (assigned_agent_id => users.id) ON DELETE => cascade
# fk_rails_... (contact_id => contacts.id) ON DELETE => cascade
# fk_rails_... (conversation_id => conversations.id) ON DELETE => cascade
# fk_rails_... (message_id => messages.id) ON DELETE => cascade
#
class CsatSurveyResponse < ApplicationRecord
belongs_to :account

View file

@ -18,7 +18,7 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
#
class DataImport < ApplicationRecord
belongs_to :account

View file

@ -19,8 +19,8 @@
#
# Foreign Keys
#
# fk_rails_... (conversation_id => conversations.id)
# fk_rails_... (user_id => users.id)
# fk_rails_... (conversation_id => conversations.id) ON DELETE => cascade
# fk_rails_... (user_id => users.id) ON DELETE => cascade
#
class Mention < ApplicationRecord
before_validation :ensure_account_id

View file

@ -18,9 +18,9 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (contact_id => contacts.id)
# fk_rails_... (user_id => users.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
# fk_rails_... (contact_id => contacts.id) ON DELETE => cascade
# fk_rails_... (user_id => users.id) ON DELETE => cascade
#
class Note < ApplicationRecord
before_validation :ensure_account_id

View file

@ -17,7 +17,7 @@
#
# Foreign Keys
#
# fk_rails_... (account_id => accounts.id)
# fk_rails_... (account_id => accounts.id) ON DELETE => cascade
#
class Team < ApplicationRecord
belongs_to :account

View file

@ -16,8 +16,8 @@
#
# Foreign Keys
#
# fk_rails_... (team_id => teams.id)
# fk_rails_... (user_id => users.id)
# fk_rails_... (team_id => teams.id) ON DELETE => cascade
# fk_rails_... (user_id => users.id) ON DELETE => cascade
#
class TeamMember < ApplicationRecord
belongs_to :user

View file

@ -0,0 +1,66 @@
class UpdateForeignKeysOnDelete < ActiveRecord::Migration[6.1]
def change
remove_foreign_key 'account_users', 'accounts'
add_foreign_key 'account_users', 'accounts', on_delete: :cascade
remove_foreign_key 'account_users', 'users'
add_foreign_key 'account_users', 'users', on_delete: :cascade
remove_foreign_key 'agent_bots', 'accounts'
add_foreign_key 'agent_bots', 'accounts', on_delete: :cascade
remove_foreign_key 'campaigns', 'accounts'
add_foreign_key 'campaigns', 'accounts', on_delete: :cascade
remove_foreign_key 'campaigns', 'inboxes'
add_foreign_key 'campaigns', 'inboxes', on_delete: :cascade
remove_foreign_key 'conversations', 'campaigns'
add_foreign_key 'conversations', 'campaigns', on_delete: :cascade
remove_foreign_key 'conversations', 'teams'
add_foreign_key 'conversations', 'teams', on_delete: :cascade
remove_foreign_key 'csat_survey_responses', 'accounts'
add_foreign_key 'csat_survey_responses', 'accounts', on_delete: :cascade
remove_foreign_key 'csat_survey_responses', 'contacts'
add_foreign_key 'csat_survey_responses', 'contacts', on_delete: :cascade
remove_foreign_key 'csat_survey_responses', 'conversations'
add_foreign_key 'csat_survey_responses', 'conversations', on_delete: :cascade
remove_foreign_key 'csat_survey_responses', 'messages'
add_foreign_key 'csat_survey_responses', 'messages', on_delete: :cascade
remove_foreign_key 'csat_survey_responses', 'users', column: 'assigned_agent_id'
add_foreign_key 'csat_survey_responses', 'users', column: 'assigned_agent_id', on_delete: :cascade
remove_foreign_key 'data_imports', 'accounts'
add_foreign_key 'data_imports', 'accounts', on_delete: :cascade
remove_foreign_key 'mentions', 'conversations'
add_foreign_key 'mentions', 'conversations', on_delete: :cascade
remove_foreign_key 'mentions', 'users'
add_foreign_key 'mentions', 'users', on_delete: :cascade
remove_foreign_key 'notes', 'accounts'
add_foreign_key 'notes', 'accounts', on_delete: :cascade
remove_foreign_key 'notes', 'contacts'
add_foreign_key 'notes', 'contacts', on_delete: :cascade
remove_foreign_key 'notes', 'users'
add_foreign_key 'notes', 'users', on_delete: :cascade
remove_foreign_key 'team_members', 'teams'
add_foreign_key 'team_members', 'teams', on_delete: :cascade
remove_foreign_key 'team_members', 'users'
add_foreign_key 'team_members', 'users', on_delete: :cascade
remove_foreign_key 'teams', 'accounts'
add_foreign_key 'teams', 'accounts', on_delete: :cascade
end
end

View file

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_12_08_085931) do
ActiveRecord::Schema.define(version: 2021_12_19_031453) do
# These are extensions that must be enabled in order to support this database
enable_extension "pg_stat_statements"
@ -761,32 +761,32 @@ ActiveRecord::Schema.define(version: 2021_12_08_085931) do
t.index ["inbox_id"], name: "index_working_hours_on_inbox_id"
end
add_foreign_key "account_users", "accounts"
add_foreign_key "account_users", "users"
add_foreign_key "account_users", "accounts", on_delete: :cascade
add_foreign_key "account_users", "users", on_delete: :cascade
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
add_foreign_key "agent_bots", "accounts"
add_foreign_key "campaigns", "accounts"
add_foreign_key "campaigns", "inboxes"
add_foreign_key "agent_bots", "accounts", on_delete: :cascade
add_foreign_key "campaigns", "accounts", on_delete: :cascade
add_foreign_key "campaigns", "inboxes", on_delete: :cascade
add_foreign_key "contact_inboxes", "contacts", on_delete: :cascade
add_foreign_key "contact_inboxes", "inboxes", on_delete: :cascade
add_foreign_key "conversations", "campaigns"
add_foreign_key "conversations", "campaigns", on_delete: :cascade
add_foreign_key "conversations", "contact_inboxes", on_delete: :cascade
add_foreign_key "conversations", "teams"
add_foreign_key "csat_survey_responses", "accounts"
add_foreign_key "csat_survey_responses", "contacts"
add_foreign_key "csat_survey_responses", "conversations"
add_foreign_key "csat_survey_responses", "messages"
add_foreign_key "csat_survey_responses", "users", column: "assigned_agent_id"
add_foreign_key "data_imports", "accounts"
add_foreign_key "mentions", "conversations"
add_foreign_key "mentions", "users"
add_foreign_key "notes", "accounts"
add_foreign_key "notes", "contacts"
add_foreign_key "notes", "users"
add_foreign_key "team_members", "teams"
add_foreign_key "team_members", "users"
add_foreign_key "teams", "accounts"
add_foreign_key "conversations", "teams", on_delete: :cascade
add_foreign_key "csat_survey_responses", "accounts", on_delete: :cascade
add_foreign_key "csat_survey_responses", "contacts", on_delete: :cascade
add_foreign_key "csat_survey_responses", "conversations", on_delete: :cascade
add_foreign_key "csat_survey_responses", "messages", on_delete: :cascade
add_foreign_key "csat_survey_responses", "users", column: "assigned_agent_id", on_delete: :cascade
add_foreign_key "data_imports", "accounts", on_delete: :cascade
add_foreign_key "mentions", "conversations", on_delete: :cascade
add_foreign_key "mentions", "users", on_delete: :cascade
add_foreign_key "notes", "accounts", on_delete: :cascade
add_foreign_key "notes", "contacts", on_delete: :cascade
add_foreign_key "notes", "users", on_delete: :cascade
add_foreign_key "team_members", "teams", on_delete: :cascade
add_foreign_key "team_members", "users", on_delete: :cascade
add_foreign_key "teams", "accounts", on_delete: :cascade
create_trigger("accounts_after_insert_row_tr", :generated => true, :compatibility => 1).
on("accounts").
after(:insert).