chore: Squash migrations till 05/2023 (#8862)

- Squash the old migrations up 05/2023 to a single file
This commit is contained in:
Sojan Jose
2024-02-06 17:00:38 +04:00
committed by GitHub
parent bee2a14620
commit a4fc28abc0
210 changed files with 879 additions and 2696 deletions

View File

@@ -203,13 +203,4 @@ AllCops:
- 'config/environments/**/*'
- 'tmp/**/*'
- 'storage/**/*'
- 'db/migrate/20200225162150_init_schema.rb'
- 'db/migrate/20210611180222_create_active_storage_variant_records.active_storage.rb'
- 'db/migrate/20210611180221_add_service_name_to_active_storage_blobs.active_storage.rb'
- db/migrate/20200309213132_add_account_id_to_agent_bot_inboxes.rb
- db/migrate/20200331095710_add_identifier_to_contact.rb
- db/migrate/20200429082655_add_medium_to_twilio_sms.rb
- db/migrate/20200503151130_add_account_feature_flag.rb
- db/migrate/20200927135222_add_last_activity_at_to_conversation.rb
- db/migrate/20210306170117_add_last_activity_at_to_contacts.rb
- db/migrate/20220809104508_revert_cascading_indexes.rb
- 'db/migrate/20230426130150_init_schema.rb'

View File

@@ -1,280 +0,0 @@
class InitSchema < ActiveRecord::Migration[6.0]
def up
# These are extensions that must be enabled in order to support this database
enable_extension 'plpgsql'
create_table 'account_users' do |t|
t.bigint 'account_id'
t.bigint 'user_id'
t.integer 'role', default: 0
t.bigint 'inviter_id'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.index %w[account_id user_id], name: 'uniq_user_id_per_account_id', unique: true
t.index ['account_id'], name: 'index_account_users_on_account_id'
t.index ['user_id'], name: 'index_account_users_on_user_id'
end
create_table 'accounts', id: :serial do |t|
t.string 'name', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table 'active_storage_attachments' do |t|
t.string 'name', null: false
t.string 'record_type', null: false
t.bigint 'record_id', null: false
t.bigint 'blob_id', null: false
t.datetime 'created_at', null: false
t.index ['blob_id'], name: 'index_active_storage_attachments_on_blob_id'
t.index %w[record_type record_id name blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true
end
create_table 'active_storage_blobs' do |t|
t.string 'key', null: false
t.string 'filename', null: false
t.string 'content_type'
t.text 'metadata'
t.bigint 'byte_size', null: false
t.string 'checksum', null: false
t.datetime 'created_at', null: false
t.index ['key'], name: 'index_active_storage_blobs_on_key', unique: true
end
create_table 'agent_bot_inboxes' do |t|
t.integer 'inbox_id'
t.integer 'agent_bot_id'
t.integer 'status', default: 0
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
end
create_table 'agent_bots' do |t|
t.string 'name'
t.string 'description'
t.string 'outgoing_url'
t.string 'auth_token'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
end
create_table 'attachments', id: :serial do |t|
t.integer 'file_type', default: 0
t.string 'external_url'
t.float 'coordinates_lat', default: 0.0
t.float 'coordinates_long', default: 0.0
t.integer 'message_id', null: false
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'fallback_title'
t.string 'extension'
end
create_table 'canned_responses', id: :serial do |t|
t.integer 'account_id', null: false
t.string 'short_code'
t.text 'content'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table 'channel_facebook_pages', id: :serial do |t|
t.string 'name', null: false
t.string 'page_id', null: false
t.string 'user_access_token', null: false
t.string 'page_access_token', null: false
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index %w[page_id account_id], name: 'index_channel_facebook_pages_on_page_id_and_account_id', unique: true
t.index ['page_id'], name: 'index_channel_facebook_pages_on_page_id'
end
create_table 'channel_twitter_profiles' do |t|
t.string 'name'
t.string 'profile_id', null: false
t.string 'twitter_access_token', null: false
t.string 'twitter_access_token_secret', null: false
t.integer 'account_id', null: false
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
end
create_table 'channel_web_widgets', id: :serial do |t|
t.string 'website_name'
t.string 'website_url'
t.integer 'account_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'website_token'
t.string 'widget_color', default: '#1f93ff'
t.index ['website_token'], name: 'index_channel_web_widgets_on_website_token', unique: true
end
create_table 'contact_inboxes' do |t|
t.bigint 'contact_id'
t.bigint 'inbox_id'
t.string 'source_id', null: false
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.index ['contact_id'], name: 'index_contact_inboxes_on_contact_id'
t.index %w[inbox_id source_id], name: 'index_contact_inboxes_on_inbox_id_and_source_id', unique: true
t.index ['inbox_id'], name: 'index_contact_inboxes_on_inbox_id'
t.index ['source_id'], name: 'index_contact_inboxes_on_source_id'
end
create_table 'contacts', id: :serial do |t|
t.string 'name'
t.string 'email'
t.string 'phone_number'
t.integer 'account_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'pubsub_token'
t.jsonb 'additional_attributes'
t.index ['account_id'], name: 'index_contacts_on_account_id'
t.index ['pubsub_token'], name: 'index_contacts_on_pubsub_token', unique: true
end
create_table 'conversations', id: :serial do |t|
t.integer 'account_id', null: false
t.integer 'inbox_id', null: false
t.integer 'status', default: 0, null: false
t.integer 'assignee_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.bigint 'contact_id'
t.integer 'display_id', null: false
t.datetime 'user_last_seen_at'
t.datetime 'agent_last_seen_at'
t.boolean 'locked', default: false
t.jsonb 'additional_attributes'
t.bigint 'contact_inbox_id'
t.index %w[account_id display_id], name: 'index_conversations_on_account_id_and_display_id', unique: true
t.index ['account_id'], name: 'index_conversations_on_account_id'
t.index ['contact_inbox_id'], name: 'index_conversations_on_contact_inbox_id'
end
create_table 'inbox_members', id: :serial do |t|
t.integer 'user_id', null: false
t.integer 'inbox_id', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.index ['inbox_id'], name: 'index_inbox_members_on_inbox_id'
end
create_table 'inboxes', id: :serial do |t|
t.integer 'channel_id', null: false
t.integer 'account_id', null: false
t.string 'name', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'channel_type'
t.boolean 'enable_auto_assignment', default: true
t.index ['account_id'], name: 'index_inboxes_on_account_id'
end
create_table 'messages', id: :serial do |t|
t.text 'content'
t.integer 'account_id', null: false
t.integer 'inbox_id', null: false
t.integer 'conversation_id', null: false
t.integer 'message_type', null: false
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.boolean 'private', default: false
t.integer 'user_id'
t.integer 'status', default: 0
t.string 'source_id'
t.integer 'content_type', default: 0
t.json 'content_attributes', default: {}
t.bigint 'contact_id'
t.index ['contact_id'], name: 'index_messages_on_contact_id'
t.index ['conversation_id'], name: 'index_messages_on_conversation_id'
t.index ['source_id'], name: 'index_messages_on_source_id'
end
create_table 'notification_settings' do |t|
t.integer 'account_id'
t.integer 'user_id'
t.integer 'email_flags', default: 0, null: false
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.index %w[account_id user_id], name: 'by_account_user', unique: true
end
create_table 'subscriptions', id: :serial do |t|
t.string 'pricing_version'
t.integer 'account_id'
t.datetime 'expiry'
t.string 'billing_plan', default: 'trial'
t.string 'stripe_customer_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.integer 'state', default: 0
t.boolean 'payment_source_added', default: false
end
create_table 'taggings', id: :serial do |t|
t.integer 'tag_id'
t.string 'taggable_type'
t.integer 'taggable_id'
t.string 'tagger_type'
t.integer 'tagger_id'
t.string 'context', limit: 128
t.datetime 'created_at'
t.index ['context'], name: 'index_taggings_on_context'
t.index %w[tag_id taggable_id taggable_type context tagger_id tagger_type], name: 'taggings_idx', unique: true
t.index ['tag_id'], name: 'index_taggings_on_tag_id'
t.index %w[taggable_id taggable_type context], name: 'index_taggings_on_taggable_id_and_taggable_type_and_context'
t.index %w[taggable_id taggable_type tagger_id context], name: 'taggings_idy'
t.index ['taggable_id'], name: 'index_taggings_on_taggable_id'
t.index %w[taggable_type taggable_id], name: 'index_taggings_on_taggable_type_and_taggable_id'
t.index ['taggable_type'], name: 'index_taggings_on_taggable_type'
t.index %w[tagger_id tagger_type], name: 'index_taggings_on_tagger_id_and_tagger_type'
t.index ['tagger_id'], name: 'index_taggings_on_tagger_id'
t.index %w[tagger_type tagger_id], name: 'index_taggings_on_tagger_type_and_tagger_id'
end
create_table 'tags', id: :serial do |t|
t.string 'name'
t.integer 'taggings_count', default: 0
t.index ['name'], name: 'index_tags_on_name', unique: true
end
create_table 'telegram_bots', id: :serial do |t|
t.string 'name'
t.string 'auth_key'
t.integer 'account_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
end
create_table 'users', id: :serial do |t|
t.string 'provider', default: 'email', null: false
t.string 'uid', default: '', null: false
t.string 'encrypted_password', default: '', null: false
t.string 'reset_password_token'
t.datetime 'reset_password_sent_at'
t.datetime 'remember_created_at'
t.integer 'sign_in_count', default: 0, null: false
t.datetime 'current_sign_in_at'
t.datetime 'last_sign_in_at'
t.string 'current_sign_in_ip'
t.string 'last_sign_in_ip'
t.string 'confirmation_token'
t.datetime 'confirmed_at'
t.datetime 'confirmation_sent_at'
t.string 'unconfirmed_email'
t.string 'name', null: false
t.string 'nickname'
t.string 'email'
t.json 'tokens'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.string 'pubsub_token'
t.index ['email'], name: 'index_users_on_email'
t.index ['pubsub_token'], name: 'index_users_on_pubsub_token', unique: true
t.index ['reset_password_token'], name: 'index_users_on_reset_password_token', unique: true
t.index %w[uid provider], name: 'index_users_on_uid_and_provider', unique: true
end
create_table 'webhooks' do |t|
t.integer 'account_id'
t.integer 'inbox_id'
t.string 'url'
t.datetime 'created_at', precision: 6, null: false
t.datetime 'updated_at', precision: 6, null: false
t.integer 'webhook_type', default: 0
end
add_foreign_key 'account_users', 'accounts'
add_foreign_key 'account_users', 'users'
add_foreign_key 'active_storage_attachments', 'active_storage_blobs', column: 'blob_id'
add_foreign_key 'contact_inboxes', 'contacts'
add_foreign_key 'contact_inboxes', 'inboxes'
add_foreign_key 'conversations', 'contact_inboxes'
add_foreign_key 'messages', 'contacts'
end
def down
raise ActiveRecord::IrreversibleMigration, 'The initial migration is not revertable'
end
end

View File

@@ -1,23 +0,0 @@
class CreateAccessTokens < ActiveRecord::Migration[6.0]
def change
create_table :access_tokens do |t|
t.references :owner, polymorphic: true, index: true
t.string :token, index: { unique: true }
t.timestamps
end
remove_column :agent_bots, :auth_token, :string
[::User, ::AgentBot].each do |access_tokenable|
generate_access_tokens(access_tokenable)
end
end
def generate_access_tokens(access_tokenable)
access_tokenable.find_in_batches do |record_batch|
record_batch.each do |record|
record.create_access_token if record.access_token.blank?
end
end
end
end

View File

@@ -1,10 +0,0 @@
class AddAccountIdToAgentBotInboxes < ActiveRecord::Migration[6.0]
def change
add_column :agent_bot_inboxes, :account_id, :integer, index: true
AgentBotInbox.all.each do |agent_bot_inbox|
agent_bot_inbox.account_id = agent_bot_inbox.inbox.account_id
agent_bot_inbox.save!
end
end
end

View File

@@ -1,14 +0,0 @@
class CreateEvents < ActiveRecord::Migration[6.0]
def change
create_table :events do |t|
t.string :name
t.float :value
t.integer :account_id
t.integer :inbox_id
t.integer :user_id
t.integer :conversation_id
t.timestamps
end
end
end

View File

@@ -1,9 +0,0 @@
class AddIndexToEvent < ActiveRecord::Migration[6.0]
def change
add_index :events, :name
add_index :events, :created_at
add_index :events, :account_id
add_index :events, :inbox_id
add_index :events, :user_id
end
end

View File

@@ -1,7 +0,0 @@
class AddIndexToMessage < ActiveRecord::Migration[6.0]
def change
add_index :messages, :account_id
add_index :messages, :inbox_id
add_index :messages, :user_id
end
end

View File

@@ -1,5 +0,0 @@
class AddLocaleToAccount < ActiveRecord::Migration[6.0]
def change
add_column :accounts, :locale, :integer, default: 0
end
end

View File

@@ -1,11 +0,0 @@
class CreateChannelTwilioSms < ActiveRecord::Migration[6.0]
def change
create_table :channel_twilio_sms do |t|
t.string :phone_number, null: false
t.string :auth_token, null: false
t.string :account_sid, null: false
t.integer :account_id, null: false
t.timestamps
end
end
end

View File

@@ -1,14 +0,0 @@
# This migration comes from action_mailbox (originally 20180917164000)
class CreateActionMailboxTables < ActiveRecord::Migration[6.0]
def change
create_table :action_mailbox_inbound_emails do |t|
t.integer :status, default: 0, null: false
t.string :message_id, null: false
t.string :message_checksum, null: false
t.timestamps
t.index [:message_id, :message_checksum], name: 'index_action_mailbox_inbound_emails_uniqueness', unique: true
end
end
end

View File

@@ -1,7 +0,0 @@
class AddIdentifierToContact < ActiveRecord::Migration[6.0]
def change
add_column :contacts, :identifier, :string, index: true, default: nil
add_index :contacts, ['identifier', :account_id], unique: true, name: 'uniq_identifier_per_account_contact'
add_index :contacts, ['email', :account_id], unique: true, name: 'uniq_email_per_account_contact'
end
end

View File

@@ -1,6 +0,0 @@
class AddConversationUuid < ActiveRecord::Migration[6.0]
def change
enable_extension 'pgcrypto'
add_column :conversations, :uuid, :uuid, default: 'gen_random_uuid()', null: false
end
end

View File

@@ -1,7 +0,0 @@
class AddUniqueValidationIndex < ActiveRecord::Migration[6.0]
def change
add_index :channel_twitter_profiles, [:account_id, :profile_id], unique: true
add_index :channel_twilio_sms, [:account_id, :phone_number], unique: true
add_index :webhooks, [:account_id, :url], unique: true
end
end

View File

@@ -1,45 +0,0 @@
# frozen_string_literal: true
class DeviseCreateSuperAdmins < ActiveRecord::Migration[6.0]
def change
return if ActiveRecord::Base.connection.table_exists? 'super_admins'
create_table :super_admins do |t|
## Database authenticatable
t.string :email, null: false, default: ''
t.string :encrypted_password, null: false, default: ''
## Recoverable
# t.string :reset_password_token
# t.datetime :reset_password_sent_at
## Rememberable
t.datetime :remember_created_at
## Trackable
t.integer :sign_in_count, default: 0, null: false
t.datetime :current_sign_in_at
t.datetime :last_sign_in_at
t.inet :current_sign_in_ip
t.inet :last_sign_in_ip
## Confirmable
# t.string :confirmation_token
# t.datetime :confirmed_at
# t.datetime :confirmation_sent_at
# t.string :unconfirmed_email # Only if using reconfirmable
## Lockable
# t.integer :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts
# t.string :unlock_token # Only if unlock strategy is :email or :both
# t.datetime :locked_at
t.timestamps null: false
end
add_index :super_admins, :email, unique: true
# add_index :super_admins, :reset_password_token, unique: true
# add_index :super_admins, :confirmation_token, unique: true
# add_index :super_admins, :unlock_token, unique: true
end
end

View File

@@ -1,9 +0,0 @@
class AddDomainToAccounts < ActiveRecord::Migration[6.0]
def change
change_table :accounts, bulk: true do |t|
t.string :domain, limit: 100
t.string :support_email, limit: 100
t.integer :settings_flags, default: 0, null: false
end
end
end

View File

@@ -1,35 +0,0 @@
class RemoveNameFromChannels < ActiveRecord::Migration[6.0]
def change
remove_column :channel_facebook_pages, :name, :string
remove_column :channel_twitter_profiles, :name, :string
migrate_web_widget_name_to_inbox
remove_column :channel_web_widgets, :website_name, :string
add_column :channel_web_widgets, :welcome_title, :string
add_column :channel_web_widgets, :welcome_tagline, :string
add_column :channel_web_widgets, :agent_away_message, :string
purge_orphan_facebook_pages
remove_avatars_from_channel_to_inbox
end
def purge_orphan_facebook_pages
Channel::FacebookPage.all.each do |facebook_page|
facebook_page.destroy! if facebook_page.inbox.nil?
end
end
def migrate_web_widget_name_to_inbox
Channel::WebWidget.all.each do |widget|
widget.inbox.name = widget.website_name
widget.save!
end
end
def remove_avatars_from_channel_to_inbox
Channel::FacebookPage.all.each do |facebook_page|
next unless facebook_page.avatar
facebook_page.avatar.purge
end
end
end

View File

@@ -1,23 +0,0 @@
class AddSenderToMessages < ActiveRecord::Migration[6.0]
def change
add_reference :messages, :sender, polymorphic: true, index: true
add_sender_from_message
remove_index :messages, name: 'index_messages_on_contact_id', column: 'contact_id'
remove_index :messages, name: 'index_messages_on_user_id', column: 'user_id'
remove_column :messages, :user_id, :integer
remove_column :messages, :contact_id, :integer
end
def add_sender_from_message
::Message.find_in_batches do |messages_batch|
Rails.logger.info "migrated till #{messages_batch.first.id}\n"
messages_batch.each do |message|
# rubocop:disable Rails/SkipsModelValidations
message.update_columns(sender_id: message.user.id, sender_type: 'User') if message.user.present?
message.update_columns(sender_id: message.contact.id, sender_type: 'Contact') if message.contact.present?
message.update_columns(sender_id: message.conversation.contact.id, sender_type: 'Contact') if message.sender.nil? && message.incoming?
# rubocop:enable Rails/SkipsModelValidations
end
end
end
end

View File

@@ -1,34 +0,0 @@
class CreateNotifications < ActiveRecord::Migration[6.0]
def change
create_table :notifications do |t|
t.references :account, index: true, null: false
t.references :user, index: true, null: false
t.integer :notification_type, null: false
t.references :primary_actor, polymorphic: true, null: false, index: { name: 'uniq_primary_actor_per_account_notifications' }
t.references :secondary_actor, polymorphic: true, index: { name: 'uniq_secondary_actor_per_account_notifications' }
t.timestamp :read_at, default: nil
t.timestamps
end
create_table :notification_subscriptions do |t|
t.references :user, index: true, null: false
t.integer :subscription_type, null: false
t.jsonb :subscription_attributes, null: false, default: '{}'
t.timestamps
end
add_column :notification_settings, :push_flags, :integer, default: 0, null: false
add_push_settings_to_users
end
def add_push_settings_to_users
::User.find_in_batches do |users_batch|
users_batch.each do |user|
user_notification_setting = user.notification_settings.first
user_notification_setting.push_conversation_assignment = true
user_notification_setting.save!
end
end
end
end

View File

@@ -1,5 +0,0 @@
class AddMediumToTwilioSms < ActiveRecord::Migration[6.0]
def change
add_column :channel_twilio_sms, :medium, :integer, index: true, default: 0
end
end

View File

@@ -1,15 +0,0 @@
class CreateIntegrationsHooks < ActiveRecord::Migration[6.0]
def change
create_table :integrations_hooks do |t|
t.integer :status, default: 0
t.integer :inbox_id
t.integer :account_id
t.string :app_id
t.text :settings
t.integer :hook_type, default: 0
t.string :reference_id
t.string :access_token
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class AddAccountFeatureFlag < ActiveRecord::Migration[6.0]
def change
add_column :accounts, :feature_flags, :integer, index: true, default: 0, null: false
end
end

View File

@@ -1,6 +0,0 @@
class AddIndexOnNotificationSubscriptions < ActiveRecord::Migration[6.0]
def change
add_column :notification_subscriptions, :identifier, :string
add_index :notification_subscriptions, :identifier, unique: true
end
end

View File

@@ -1,5 +0,0 @@
class AddHideInputFlagToBotConfig < ActiveRecord::Migration[6.0]
def change
add_column :agent_bots, :hide_input_for_bot_conversations, :boolean, default: false
end
end

View File

@@ -1,13 +0,0 @@
class CreateInstallationConfig < ActiveRecord::Migration[6.0]
def change
create_table :installation_configs do |t|
t.string :name, null: false
t.jsonb :serialized_value, null: false, default: '{}'
t.timestamps
end
add_index :installation_configs, [:name, :created_at], unique: true
ConfigLoader.new.process
end
end

View File

@@ -1,5 +0,0 @@
class AddReferenceIdToConversation < ActiveRecord::Migration[6.0]
def change
add_column :conversations, :reference_id, :string
end
end

View File

@@ -1,5 +0,0 @@
class AddActiveAtToAccountUsers < ActiveRecord::Migration[6.0]
def change
add_column :account_users, :active_at, :datetime, default: nil
end
end

View File

@@ -1,5 +0,0 @@
class ReloadConfig < ActiveRecord::Migration[6.0]
def change
ConfigLoader.new.process
end
end

View File

@@ -1,21 +0,0 @@
class AgentAwayMessageToAutoReply < ActiveRecord::Migration[6.0]
def change
add_column :inboxes, :greeting_enabled, :boolean, default: false
add_column :inboxes, :greeting_message, :string
migrate_agent_away_to_greeting
remove_column :channel_web_widgets, :agent_away_message, :string
end
def migrate_agent_away_to_greeting
::Channel::WebWidget.find_in_batches do |widget_batch|
widget_batch.each do |widget|
inbox = widget.inbox
inbox.greeting_enabled = true
inbox.greeting_message = widget.agent_away_message
widget.save!
end
end
end
end

View File

@@ -1,13 +0,0 @@
class CreateLabels < ActiveRecord::Migration[6.0]
def change
create_table :labels do |t|
t.string :title
t.text :description
t.string :color
t.boolean :show_on_sidebar
t.references :account, index: true
t.timestamps
end
end
end

View File

@@ -1,15 +0,0 @@
class RemoveSubscriptions < ActiveRecord::Migration[6.0]
def change
drop_table :subscriptions do |t|
t.string 'pricing_version'
t.integer 'account_id'
t.datetime 'expiry'
t.string 'billing_plan', default: 'trial'
t.string 'stripe_customer_id'
t.datetime 'created_at', null: false
t.datetime 'updated_at', null: false
t.integer 'state', default: 0
t.boolean 'payment_source_added', default: false
end
end
end

View File

@@ -1,5 +0,0 @@
class RenameReferenceId < ActiveRecord::Migration[6.0]
def change
rename_column :conversations, :reference_id, :identifier
end
end

View File

@@ -1,20 +0,0 @@
class MigrateAndAddUniqueIndexToLabels < ActiveRecord::Migration[6.0]
def change
add_index :labels, [:title, :account_id], unique: true
migrate_existing_tags
end
private
def migrate_existing_tags
::ActsAsTaggableOn::Tag.all.each do |tag|
tag.taggings.each do |tagging|
ensure_label_for_account(tag.name, tagging.taggable.account)
end
end
end
def ensure_label_for_account(name, account)
account.labels.where(title: name.downcase).first_or_create
end
end

View File

@@ -1,11 +0,0 @@
class AddDefaultValueToColor < ActiveRecord::Migration[6.0]
def up
Label.where(color: nil).find_each { |u| u.update(color: '#1f93ff') }
change_column :labels, :color, :string, default: '#1f93ff', null: false
end
def down
change_column :labels, :color, :string, default: nil, null: true
end
end

View File

@@ -1,9 +0,0 @@
class CreateApiChannel < ActiveRecord::Migration[6.0]
def change
create_table :channel_api do |t|
t.integer :account_id, null: false
t.string :webhook_url, null: false
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class AddAvailabilityToUser < ActiveRecord::Migration[6.0]
def change
add_column :users, :availability, :integer, default: 0
end
end

View File

@@ -1,17 +0,0 @@
class CreateKbasePortals < ActiveRecord::Migration[6.0]
def change
create_table :kbase_portals do |t|
t.integer :account_id, null: false
t.string :name, null: false
t.string :slug, null: false
t.string :custom_domain
t.string :color
t.string :homepage_link
t.string :page_title
t.text :header_text
t.index :slug, unique: true
t.timestamps
end
end
end

View File

@@ -1,13 +0,0 @@
class CreateKbaseCategories < ActiveRecord::Migration[6.0]
def change
create_table :kbase_categories do |t|
t.integer :account_id, null: false
t.integer :portal_id, null: false
t.string :name
t.text :description
t.integer :position
t.timestamps
end
end
end

View File

@@ -1,11 +0,0 @@
class CreateKbaseFolders < ActiveRecord::Migration[6.0]
def change
create_table :kbase_folders do |t|
t.integer :account_id, null: false
t.integer :category_id, null: false
t.string :name
t.timestamps
end
end
end

View File

@@ -1,18 +0,0 @@
class CreateKbaseArticles < ActiveRecord::Migration[6.0]
def change
create_table :kbase_articles do |t|
t.integer :account_id, null: false
t.integer :portal_id, null: false
t.integer :category_id
t.integer :folder_id
t.integer :author_id
t.string :title
t.text :description
t.text :content
t.integer :status
t.integer :views
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class AddTwitterFeatureFlag < ActiveRecord::Migration[6.0]
def change
ConfigLoader.new.process
end
end

View File

@@ -1,21 +0,0 @@
class RemoveMultipleFeatureFlags < ActiveRecord::Migration[6.0]
def change
current_config = InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').last
InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').where.not(id: current_config.id).destroy_all
ConfigLoader.new.process
update_existing_accounts
end
def update_existing_accounts
feature_config = InstallationConfig.find_by(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS')
facebook_config = feature_config.value.find { |value| value['name'] == 'channel_facebook' }
twitter_config = feature_config.value.find { |value| value['name'] == 'channel_twitter' }
Account.find_in_batches do |account_batch|
account_batch.each do |account|
account.enable_features('channel_facebook') if facebook_config['enabled']
account.enable_features('channel_twitter') if twitter_config['enabled']
account.save!
end
end
end
end

View File

@@ -1,10 +0,0 @@
class CreateEmailChannel < ActiveRecord::Migration[6.0]
def change
create_table :channel_email do |t|
t.integer :account_id, null: false
t.string :email, null: false, index: { unique: true }
t.string :forward_to_address, null: false, index: { unique: true }
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class RenameNickNameToDisplayName < ActiveRecord::Migration[6.0]
def change
rename_column :users, :nickname, :display_name
end
end

View File

@@ -1,13 +0,0 @@
class CreateEmailTemplates < ActiveRecord::Migration[6.0]
def change
create_table :email_templates do |t|
t.string :name, null: false
t.text :body, null: false
t.integer :account_id, null: true
t.integer :template_type, default: 1
t.integer :locale, default: 0, null: false
t.timestamps
end
add_index :email_templates, [:name, :account_id], unique: true
end
end

View File

@@ -1,5 +0,0 @@
class AddFeatureSettingToWebsiteInbox < ActiveRecord::Migration[6.0]
def change
add_column :channel_web_widgets, :feature_flags, :integer, default: 3, null: false
end
end

View File

@@ -1,7 +0,0 @@
class ResetAgentLastSeenAt < ActiveRecord::Migration[6.0]
def change
# rubocop:disable Rails/SkipsModelValidations
::Conversation.where('agent_last_seen_at > ?', DateTime.now.utc).update_all(agent_last_seen_at: DateTime.now.utc)
# rubocop:enable Rails/SkipsModelValidations
end
end

View File

@@ -1,5 +0,0 @@
class AddCustomAttributesToContacts < ActiveRecord::Migration[6.0]
def change
add_column :contacts, :custom_attributes, :jsonb, default: {}
end
end

View File

@@ -1,16 +0,0 @@
class AddExternalSourceIdsToMessages < ActiveRecord::Migration[6.0]
def change
add_column :messages, :external_source_ids, :jsonb, default: {}
migrate_slack_external_source_ids
end
def migrate_slack_external_source_ids
Message.where('source_id LIKE ?', 'slack_%').find_in_batches do |message_batch|
message_batch.each do |message|
message.external_source_id_slack = message.source_id.split('slack_')[1]
message.source_id = nil
message.save!
end
end
end
end

View File

@@ -1,5 +0,0 @@
class RenameUserLastSeen < ActiveRecord::Migration[6.0]
def change
rename_column :conversations, :user_last_seen_at, :contact_last_seen_at
end
end

View File

@@ -1,5 +0,0 @@
class AddReplyTimeToWebWidget < ActiveRecord::Migration[6.0]
def change
add_column :channel_web_widgets, :reply_time, :integer, default: 0
end
end

View File

@@ -1,35 +0,0 @@
class AddLastActivityAtToConversation < ActiveRecord::Migration[6.0]
def up
add_column :conversations,
:last_activity_at,
:datetime,
default: -> { 'CURRENT_TIMESTAMP' },
index: true
add_last_activity_at_to_conversations
change_column_null(:conversations, :last_activity_at, false)
end
def down
remove_column(:conversations, :last_activity_at)
end
private
def add_last_activity_at_to_conversations
::Conversation.find_in_batches do |conversation_batch|
Rails.logger.info "Migrated till #{conversation_batch.first.id}\n"
conversation_batch.each do |conversation|
# rubocop:disable Rails/SkipsModelValidations
last_activity_at = if conversation.messages.last
conversation.messages.last.created_at
else
conversation.created_at
end
conversation.update_columns(last_activity_at: last_activity_at)
# rubocop:enable Rails/SkipsModelValidations
end
end
end
end

View File

@@ -1,5 +0,0 @@
class AddAutoResolveDurationToAccount < ActiveRecord::Migration[6.0]
def change
add_column :accounts, :auto_resolve_duration, :integer
end
end

View File

@@ -1,9 +0,0 @@
class AddEmailAddressToInbox < ActiveRecord::Migration[6.0]
def up
add_column :inboxes, :email_address, :string
end
def down
remove_column(:inboxes, :email_address)
end
end

View File

@@ -1,8 +0,0 @@
class AddDefaultValueToJsonbColums < ActiveRecord::Migration[6.0]
def change
change_column_default :contacts, :additional_attributes, from: nil, to: {}
change_column_default :conversations, :additional_attributes, from: nil, to: {}
change_column_default :installation_configs, :serialized_value, from: '{}', to: {}
change_column_default :notification_subscriptions, :subscription_attributes, from: '{}', to: {}
end
end

View File

@@ -1,40 +0,0 @@
class CreateWorkingHours < ActiveRecord::Migration[6.0]
def change
create_table :working_hours do |t|
t.belongs_to :inbox
t.belongs_to :account
t.integer :day_of_week, null: false
t.boolean :closed_all_day, default: false
t.integer :open_hour
t.integer :open_minutes
t.integer :close_hour
t.integer :close_minutes
t.timestamps
end
add_column :accounts, :timezone, :string, default: 'UTC'
change_table :inboxes, bulk: true do |t|
t.boolean :working_hours_enabled, default: false
t.string :out_of_office_message
end
Inbox.where.not(id: WorkingHour.select(:inbox_id)).each do |inbox|
create_working_hours_for_inbox(inbox)
end
end
private
def create_working_hours_for_inbox(inbox)
inbox.working_hours.create!(day_of_week: 1, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 2, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 3, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 4, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 5, open_hour: 9, open_minutes: 0, close_hour: 17, close_minutes: 0)
inbox.working_hours.create!(day_of_week: 6, closed_all_day: true)
inbox.working_hours.create!(day_of_week: 7, closed_all_day: true)
end
end

View File

@@ -1,8 +0,0 @@
class CreatePlatformApps < ActiveRecord::Migration[6.0]
def change
create_table :platform_apps do |t|
t.string :name, null: false
t.timestamps
end
end
end

View File

@@ -1,11 +0,0 @@
class CreatePlatformAppPermissibles < ActiveRecord::Migration[6.0]
def change
create_table :platform_app_permissibles do |t|
t.references :platform_app, index: true, null: false
t.references :permissible, null: false, polymorphic: true, index: { name: :index_platform_app_permissibles_on_permissibles }
t.timestamps
end
add_index :platform_app_permissibles, [:platform_app_id, :permissible_id, :permissible_type], unique: true, name: 'unique_permissibles_index'
end
end

View File

@@ -1,27 +0,0 @@
# This migration was auto-generated via `rake db:generate_trigger_migration'.
# While you can edit this file, any changes you make to the definitions here
# will be undone by the next auto-generated trigger migration.
class CreateTriggersAccountsInsertOrConversationsInsert < ActiveRecord::Migration[6.0]
def up
create_trigger('accounts_after_insert_row_tr', generated: true, compatibility: 1)
.on('accounts')
.after(:insert)
.for_each(:row) do
"execute format('create sequence IF NOT EXISTS conv_dpid_seq_%s', NEW.id);"
end
create_trigger('conversations_before_insert_row_tr', generated: true, compatibility: 1)
.on('conversations')
.before(:insert)
.for_each(:row) do
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
end
end
def down
drop_trigger('accounts_after_insert_row_tr', 'accounts', generated: true)
drop_trigger('conversations_before_insert_row_tr', 'conversations', generated: true)
end
end

View File

@@ -1,21 +0,0 @@
class ConvDpidSeqForExistingAccnts < ActiveRecord::Migration[6.0]
def up
::Account.find_in_batches do |accounts_batch|
Rails.logger.info "migrated till #{accounts_batch.first.id}\n"
accounts_batch.each do |account|
display_id = Conversation.where(account_id: account.id).maximum('display_id')
display_id ||= 0 # for accounts with out conversations
ActiveRecord::Base.connection.exec_query("create sequence IF NOT EXISTS conv_dpid_seq_#{account.id} START #{display_id + 1}")
end
end
end
def down
::Account.find_in_batches do |accounts_batch|
Rails.logger.info "migrated till #{accounts_batch.first.id}\n"
accounts_batch.each do |account|
ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS conv_dpid_seq_#{account.id}")
end
end
end
end

View File

@@ -1,5 +0,0 @@
class EnablePgStatsExtention < ActiveRecord::Migration[6.0]
def change
enable_extension 'pg_stat_statements'
end
end

View File

@@ -1,9 +0,0 @@
class AddUiSettingsToUsers < ActiveRecord::Migration[6.0]
def up
add_column :users, :ui_settings, :jsonb, default: {}
end
def down
remove_column :users, :ui_settings, :jsonb
end
end

View File

@@ -1,15 +0,0 @@
class AddHmacTokenToInbox < ActiveRecord::Migration[6.0]
def change
add_column :channel_web_widgets, :hmac_token, :string
add_index :channel_web_widgets, :hmac_token, unique: true
set_up_existing_webwidgets
add_column :contact_inboxes, :hmac_verified, :boolean, default: false
end
def set_up_existing_webwidgets
::Channel::WebWidget.find_in_batches do |webwidgets_batch|
Rails.logger.info "migrated till #{webwidgets_batch.first.id}\n"
webwidgets_batch.map(&:regenerate_hmac_token)
end
end
end

View File

@@ -1,26 +0,0 @@
class AddLockedAttributeToInstallationConfig < ActiveRecord::Migration[6.0]
def up
add_column :installation_configs, :locked, :boolean, default: true, null: false
purge_duplicates
add_index :installation_configs, :name, unique: true
end
def down
remove_column :installation_configs, :locked
remove_index :installation_configs, :name
end
def purge_duplicates
config_names = InstallationConfig.all.map(&:name).uniq
config_names.each do |name|
ids = InstallationConfig.where(name: name).pluck(&:id)
next if ids.size <= 1
# preserve the last config and destroy rest
ids.sort!
ids.pop
InstallationConfig.where(id: ids).destroy_all
end
end
end

View File

@@ -1,20 +0,0 @@
class CreateTeams < ActiveRecord::Migration[6.0]
def change
create_table :teams do |t|
t.string :name, null: false
t.text :description
t.boolean :allow_auto_assign, default: true
t.references :account, null: false, foreign_key: true
t.timestamps
end
create_table :team_members do |t|
t.references :team, null: false, foreign_key: true
t.references :user, null: false, foreign_key: true
t.timestamps
end
add_reference :conversations, :team, foreign_key: true
end
end

View File

@@ -1,6 +0,0 @@
class AdduniqueIndexToTeamMembers < ActiveRecord::Migration[6.0]
def change
add_index :teams, [:name, :account_id], unique: true
add_index :team_members, [:team_id, :user_id], unique: true
end
end

View File

@@ -1,14 +0,0 @@
class CreateDataImports < ActiveRecord::Migration[6.0]
def change
create_table :data_imports do |t|
t.references :account, null: false, foreign_key: true
t.string :data_type, null: false
t.integer :status, null: false, default: 0
t.text :processing_errors
t.integer :total_records
t.integer :processed_records
t.timestamps
end
end
end

View File

@@ -1,15 +0,0 @@
class AddRequestForEmailOnChannelWebWidget < ActiveRecord::Migration[6.0]
def up
change_table :channel_web_widgets, bulk: true do |t|
t.column :pre_chat_form_enabled, :boolean, default: false
t.column :pre_chat_form_options, :jsonb, default: {}
end
end
def down
change_table :channel_web_widgets, bulk: true do |t|
t.remove :pre_chat_form_enabled
t.remove :pre_chat_form_options
end
end
end

View File

@@ -1,13 +0,0 @@
class RemoveOrphanInboxMembersFromInboxes < ActiveRecord::Migration[6.0]
def change
Account.all.map do |account|
user_ids = account.users.all.map(&:id)
inboxes = account.inboxes
inboxes.each do |inbox|
inbox.inbox_members.each do |inbox_member|
inbox_member.destroy! unless user_ids.include?(inbox_member.user_id)
end
end
end
end
end

View File

@@ -1,5 +0,0 @@
class RemoveOldNotifications < ActiveRecord::Migration[6.0]
def change
Notification.where(notification_type: 'assigned_conversation_new_message').destroy_all
end
end

View File

@@ -1,11 +0,0 @@
class ChangeWorkingHoursToZero < ActiveRecord::Migration[6.0]
# rubocop:disable Rails/SkipsModelValidations
def up
WorkingHour.where(day_of_week: 7).update_all(day_of_week: 0)
end
def down
WorkingHour.where(day_of_week: 0).update_all(day_of_week: 7)
end
# rubocop:enable Rails/SkipsModelValidations
end

View File

@@ -1,6 +0,0 @@
class SwitchTimeZoneFromAccountToInbox < ActiveRecord::Migration[6.0]
def change
remove_column :accounts, :timezone, :string, default: 'UTC'
add_column :inboxes, :timezone, :string, default: 'UTC'
end
end

View File

@@ -1,5 +0,0 @@
class RenameChannelEmailForwardAddress < ActiveRecord::Migration[6.0]
def change
rename_column :channel_email, :forward_to_address, :forward_to_email
end
end

View File

@@ -1,22 +0,0 @@
class AddLastActivityAtToContacts < ActiveRecord::Migration[6.0]
def up
# rubocop:disable Rails/SkipsModelValidations
add_column :contacts, :last_activity_at, :datetime, index: true, default: nil
Conversation.find_in_batches do |conversation_batch|
conversation_batch.each do |conversation|
contact = conversation.contact
if contact.last_activity_at.nil? || conversation.updated_at > contact.last_activity_at
contact.update_columns(last_activity_at: conversation.updated_at)
end
end
end
Contact.where(additional_attributes: nil).update_all(additional_attributes: {})
Contact.where(phone_number: '').update_all(phone_number: nil)
# rubocop:enable Rails/SkipsModelValidations
end
def down
remove_column :contacts, :last_activity_at, :datetime, index: true, default: nil
end
end

View File

@@ -1,17 +0,0 @@
class EnableEmailChannel < ActiveRecord::Migration[6.0]
def change
current_config = InstallationConfig.where(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS').last
current_config.value.each { |v| v['enabled'] = true if %w[inbound_emails channel_email].include?(v['name']) }
current_config.save!
ConfigLoader.new.process
Account.find_in_batches do |account_batch|
account_batch.each do |account|
account.enable_features('inbound_emails')
account.enable_features('channel_email')
account.save!
end
end
end
end

View File

@@ -1,6 +0,0 @@
class ConvertIntegrationHookSettingsField < ActiveRecord::Migration[6.0]
def change
remove_column :integrations_hooks, :settings, :text
add_column :integrations_hooks, :settings, :jsonb, default: {}
end
end

View File

@@ -1,5 +0,0 @@
class MigrationRemoveLockedFromConversation < ActiveRecord::Migration[6.0]
def change
remove_column :conversations, :locked, :boolean
end
end

View File

@@ -1,18 +0,0 @@
class AddCampaigns < ActiveRecord::Migration[6.0]
def change
create_table :campaigns do |t|
t.integer :display_id, null: false
t.string :title, null: false
t.text :description
t.text :content, null: false
t.integer :sender_id
t.boolean :enabled, default: true
t.references :account, null: false, foreign_key: true
t.references :inbox, null: false, foreign_key: true
t.column :trigger_rules, :jsonb, default: {}
t.timestamps
end
add_reference :conversations, :campaign, foreign_key: true
end
end

View File

@@ -1,28 +0,0 @@
# This migration was auto-generated via `rake db:generate_trigger_migration'.
# While you can edit this file, any changes you make to the definitions here
# will be undone by the next auto-generated trigger migration.
class CreateTriggersAccountsInsertOrCampaignsInsert < ActiveRecord::Migration[6.0]
def up
create_trigger('camp_dpid_before_insert', generated: true, compatibility: 1)
.on('accounts')
.name('camp_dpid_before_insert')
.after(:insert)
.for_each(:row) do
"execute format('create sequence IF NOT EXISTS camp_dpid_seq_%s', NEW.id);"
end
create_trigger('campaigns_before_insert_row_tr', generated: true, compatibility: 1)
.on('campaigns')
.before(:insert)
.for_each(:row) do
"NEW.display_id := nextval('camp_dpid_seq_' || NEW.account_id);"
end
end
def down
drop_trigger('camp_dpid_before_insert', 'accounts', generated: true)
drop_trigger('campaigns_before_insert_row_tr', 'campaigns', generated: true)
end
end

View File

@@ -1,20 +0,0 @@
class AddCampDpIdSeqForExistingAccounts < ActiveRecord::Migration[6.0]
def up
::Account.find_in_batches do |accounts_batch|
Rails.logger.info "migrated till #{accounts_batch.first.id}\n"
accounts_batch.each do |account|
display_id = account.campaigns.count
ActiveRecord::Base.connection.exec_query("create sequence IF NOT EXISTS camp_dpid_seq_#{account.id} START #{display_id + 1}")
end
end
end
def down
::Account.find_in_batches do |accounts_batch|
Rails.logger.info "migrated till #{accounts_batch.first.id}\n"
accounts_batch.each do |account|
ActiveRecord::Base.connection.exec_query("drop sequence IF EXISTS camp_dpid_seq_#{account.id}")
end
end
end
end

View File

@@ -1,5 +0,0 @@
class RenameCampaignContentToMessage < ActiveRecord::Migration[6.0]
def change
rename_column :campaigns, :content, :message
end
end

View File

@@ -1,5 +0,0 @@
class RemoveNotNullFromWebhookUrlChannelApi < ActiveRecord::Migration[6.0]
def change
change_column :channel_api, :webhook_url, :string, null: true
end
end

View File

@@ -1,5 +0,0 @@
class RenameEventsToReportEvents < ActiveRecord::Migration[6.0]
def change
rename_table :events, :reporting_events
end
end

View File

@@ -1,6 +0,0 @@
class AddAccountIdToAgentBots < ActiveRecord::Migration[6.0]
def change
remove_column :agent_bots, :hide_input_for_bot_conversations, :boolean
add_reference :agent_bots, :account, foreign_key: true
end
end

View File

@@ -1,5 +0,0 @@
class RemoveSuperAdminAccessTokes < ActiveRecord::Migration[6.0]
def change
AccessToken.where(owner_type: 'SuperAdmin').destroy_all
end
end

View File

@@ -1,19 +0,0 @@
class AddHmacToApiChannel < ActiveRecord::Migration[6.0]
def change
add_column :channel_api, :identifier, :string
add_index :channel_api, :identifier, unique: true
add_column :channel_api, :hmac_token, :string
add_index :channel_api, :hmac_token, unique: true
add_column :channel_api, :hmac_mandatory, :boolean, default: false
add_column :channel_web_widgets, :hmac_mandatory, :boolean, default: false
set_up_existing_api_channels
end
def set_up_existing_api_channels
::Channel::Api.find_in_batches do |api_channels_batch|
Rails.logger.info "migrated till #{api_channels_batch.first.id}\n"
api_channels_batch.map(&:regenerate_hmac_token)
api_channels_batch.map(&:regenerate_identifier)
end
end
end

View File

@@ -1,5 +0,0 @@
class AddEmailCollectToInboxes < ActiveRecord::Migration[6.0]
def change
add_column :inboxes, :enable_email_collect, :boolean, default: true
end
end

View File

@@ -1,18 +0,0 @@
# This migration comes from active_storage (originally 20190112182829)
class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
def up
unless column_exists?(:active_storage_blobs, :service_name)
add_column :active_storage_blobs, :service_name, :string
if configured_service = ActiveStorage::Blob.service.name
ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
end
change_column :active_storage_blobs, :service_name, :string, null: false
end
end
def down
remove_column :active_storage_blobs, :service_name
end
end

View File

@@ -1,12 +0,0 @@
# This migration comes from active_storage (originally 20191206030411)
class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
def change
create_table :active_storage_variant_records do |t|
t.belongs_to :blob, null: false, index: false
t.string :variation_digest, null: false
t.index %i[blob_id variation_digest], name: 'index_active_storage_variant_records_uniqueness', unique: true
t.foreign_key :active_storage_blobs, column: :blob_id
end
end
end

View File

@@ -1,11 +0,0 @@
class CreateNotes < ActiveRecord::Migration[6.0]
def change
create_table :notes do |t|
t.text :content, null: false
t.references :account, foreign_key: true, null: false
t.references :contact, foreign_key: true, null: false
t.references :user, foreign_key: true
t.timestamps
end
end
end

View File

@@ -1,5 +0,0 @@
class AddCsatToggleForInbox < ActiveRecord::Migration[6.0]
def change
add_column :inboxes, :csat_survey_enabled, :boolean, default: false
end
end

View File

@@ -1,12 +0,0 @@
class CreateCustomFilters < ActiveRecord::Migration[6.0]
def change
create_table :custom_filters do |t|
t.string :name, null: false
t.integer :filter_type, null: false, default: 0
t.jsonb :query, null: false, default: '{}'
t.references :account, index: true, null: false
t.references :user, index: true, null: false
t.timestamps
end
end
end

View File

@@ -1,15 +0,0 @@
class CreateCsatSurveyResponses < ActiveRecord::Migration[6.0]
def change
create_table :csat_survey_responses do |t|
t.references :account, null: false, foreign_key: true
t.references :conversation, null: false, foreign_key: true
t.references :message, null: false, foreign_key: true, index: { unique: true }
t.integer :rating, null: false
t.text :feedback_message
t.references :contact, null: false, foreign_key: true
t.references :assigned_agent, foreign_key: { to_table: :users }
t.timestamps
end
end
end

View File

@@ -1,10 +0,0 @@
class AddCampaignTypeToCampaigns < ActiveRecord::Migration[6.0]
def change
change_table :campaigns, bulk: true do |t|
t.integer :campaign_type, default: 0, null: false, index: true
t.integer :campaign_status, default: 0, null: false, index: true
t.jsonb :audience, default: []
t.datetime :scheduled_at, index: true
end
end
end

View File

@@ -1,9 +0,0 @@
class RemoveNotificationsWithoutPrimaryActor < ActiveRecord::Migration[6.0]
def change
deleted_ids = []
Notification.where(primary_actor_type: 'Conversation').pluck(:primary_actor_id).uniq.each_slice(1000) do |id_list|
deleted_ids << (id_list - Conversation.where(id: id_list).pluck(:id))
end
Notification.where(primary_actor_type: 'Conversation', primary_actor_id: deleted_ids).destroy_all
end
end

View File

@@ -1,12 +0,0 @@
class RemoveDuplicateAccessTokensForExistingUsers < ActiveRecord::Migration[6.0]
def up
# find all models and group them on owner
grouped_tokens = AccessToken.all.group_by(&:owner)
grouped_tokens.each_value do |duplicates|
# we want to keep the latest token as it is being used in all requests
duplicates.pop
# Remaining ones are duplicates, delete them all
duplicates.each { |duplicate| AccessToken.find_by(id: duplicate).destroy }
end
end
end

View File

@@ -1,5 +0,0 @@
class AddSnoozedUntilToConversations < ActiveRecord::Migration[6.0]
def change
add_column :conversations, :snoozed_until, :datetime
end
end

View File

@@ -1,16 +0,0 @@
class AddCustomAttributeDefinition < ActiveRecord::Migration[6.0]
def change
create_table :custom_attribute_definitions do |t|
t.string :attribute_display_name
t.string :attribute_key
t.integer :attribute_display_type, default: 0
t.integer :default_value
t.integer :attribute_model, default: 0
t.references :account, index: true
t.timestamps
end
add_index :custom_attribute_definitions, [:attribute_key, :attribute_model], unique: true, name: 'attribute_key_model_index'
end
end

View File

@@ -1,6 +0,0 @@
class AddIndexToConversations < ActiveRecord::Migration[6.0]
def change
add_index :conversations, [:status, :account_id]
add_index :conversations, [:assignee_id, :account_id]
end
end

View File

@@ -1,5 +0,0 @@
class AddIndexToContacts < ActiveRecord::Migration[6.0]
def change
add_index :contacts, [:phone_number, :account_id]
end
end

View File

@@ -1,5 +0,0 @@
class AddDescriptionToCustomAttributeDefinition < ActiveRecord::Migration[6.1]
def change
add_column :custom_attribute_definitions, :attribute_description, :text
end
end

Some files were not shown because too many files have changed in this diff Show More