diff --git a/.rubocop.yml b/.rubocop.yml index ab5efd6c8..1210063b4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -129,3 +129,4 @@ AllCops: - 'config/environments/**/*' - 'tmp/**/*' - 'storage/**/*' + - 'db/migrate/20200225162150_init_schema.rb' diff --git a/Gemfile b/Gemfile index 86a8e65b3..c448fad36 100644 --- a/Gemfile +++ b/Gemfile @@ -97,6 +97,9 @@ group :development do # used in swagger build gem 'json_refs', git: 'https://github.com/tzmfreedom/json_refs', ref: 'e32deb0' + + # When we want to squash migrations + gem 'squasher' end group :test do diff --git a/Gemfile.lock b/Gemfile.lock index 2ef8c6297..f3a479db7 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -488,6 +488,7 @@ GEM actionpack (>= 4.0) activesupport (>= 4.0) sprockets (>= 3.0.0) + squasher (0.6.2) statsd-ruby (1.4.0) telegram-bot-ruby (0.12.0) faraday @@ -620,6 +621,7 @@ DEPENDENCIES slack-ruby-client spring spring-watcher-listen + squasher telegram-bot-ruby telephone_number time_diff diff --git a/db/migrate/20161022055031_create_accounts.rb b/db/migrate/20161022055031_create_accounts.rb deleted file mode 100644 index 81a3bd338..000000000 --- a/db/migrate/20161022055031_create_accounts.rb +++ /dev/null @@ -1,9 +0,0 @@ -class CreateAccounts < ActiveRecord::Migration[5.0] - def change - create_table :accounts do |t| - t.string :name - - t.timestamps - end - end -end diff --git a/db/migrate/20161022060602_create_inboxes.rb b/db/migrate/20161022060602_create_inboxes.rb deleted file mode 100644 index eab8c400d..000000000 --- a/db/migrate/20161022060602_create_inboxes.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateInboxes < ActiveRecord::Migration[5.0] - def change - create_table :inboxes do |t| - t.integer :channel_id - t.integer :account_id - t.string :name - t.timestamps - end - end -end diff --git a/db/migrate/20161022061641_create_contacts.rb b/db/migrate/20161022061641_create_contacts.rb deleted file mode 100644 index 9313aae44..000000000 --- a/db/migrate/20161022061641_create_contacts.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateContacts < ActiveRecord::Migration[5.0] - def change - create_table :contacts do |t| - t.string :name - t.string :email - t.string :phone_number - t.integer :channel_id - t.integer :account_id - - t.timestamps - end - end -end diff --git a/db/migrate/20161022062829_create_conversations.rb b/db/migrate/20161022062829_create_conversations.rb deleted file mode 100644 index d10b31a6f..000000000 --- a/db/migrate/20161022062829_create_conversations.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateConversations < ActiveRecord::Migration[5.0] - def change - create_table :conversations do |t| - t.integer :account_id - t.integer :channel_id - t.integer :inbox_id - t.integer :status - t.integer :assignee_id - - t.timestamps - end - end -end diff --git a/db/migrate/20161022072124_create_messages.rb b/db/migrate/20161022072124_create_messages.rb deleted file mode 100644 index 8e29d3ad8..000000000 --- a/db/migrate/20161022072124_create_messages.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateMessages < ActiveRecord::Migration[5.0] - def change - create_table :messages do |t| - t.text :content - t.integer :account_id - t.integer :channel_id - t.integer :inbox_id - t.integer :conversation_id - t.integer :type - t.timestamps - end - end -end diff --git a/db/migrate/20161022073137_add_sender_to_conversation.rb b/db/migrate/20161022073137_add_sender_to_conversation.rb deleted file mode 100644 index 1ddb55536..000000000 --- a/db/migrate/20161022073137_add_sender_to_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddSenderToConversation < ActiveRecord::Migration[5.0] - def change - add_column :conversations, :sender_id, :integer - end -end diff --git a/db/migrate/20161022080042_create_inbox_members.rb b/db/migrate/20161022080042_create_inbox_members.rb deleted file mode 100644 index ffa01b3b1..000000000 --- a/db/migrate/20161022080042_create_inbox_members.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateInboxMembers < ActiveRecord::Migration[5.0] - def change - create_table :inbox_members do |t| - t.integer :user_id - t.integer :inbox_id - - t.timestamps - end - end -end diff --git a/db/migrate/20161025063304_dropchannels.rb b/db/migrate/20161025063304_dropchannels.rb deleted file mode 100644 index df2791fa1..000000000 --- a/db/migrate/20161025063304_dropchannels.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Dropchannels < ActiveRecord::Migration[5.0] - def change - # drop_table :channels - end -end diff --git a/db/migrate/20161025063510_addchanneltype.rb b/db/migrate/20161025063510_addchanneltype.rb deleted file mode 100644 index b0612b3a9..000000000 --- a/db/migrate/20161025063510_addchanneltype.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Addchanneltype < ActiveRecord::Migration[5.0] - def change - add_column :inboxes, :channel_type, :string - end -end diff --git a/db/migrate/20161025064031_create_facebook_pages.rb b/db/migrate/20161025064031_create_facebook_pages.rb deleted file mode 100644 index 193bfb6cc..000000000 --- a/db/migrate/20161025064031_create_facebook_pages.rb +++ /dev/null @@ -1,13 +0,0 @@ -class CreateFacebookPages < ActiveRecord::Migration[5.0] - def change - create_table :facebook_pages do |t| - t.string :name - 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.integer :inbox_id, null: false - t.timestamps - end - end -end diff --git a/db/migrate/20161025070152_removechannelsfrommodels.rb b/db/migrate/20161025070152_removechannelsfrommodels.rb deleted file mode 100644 index 5d162a0fc..000000000 --- a/db/migrate/20161025070152_removechannelsfrommodels.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Removechannelsfrommodels < ActiveRecord::Migration[5.0] - def change - remove_column :contacts, :channel_id - add_column :contacts, :inbox_id, :integer - end -end diff --git a/db/migrate/20161025070645_remchannel.rb b/db/migrate/20161025070645_remchannel.rb deleted file mode 100644 index 563bf0c43..000000000 --- a/db/migrate/20161025070645_remchannel.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Remchannel < ActiveRecord::Migration[5.0] - def change - remove_column :conversations, :channel_id - remove_column :messages, :channel_id - end -end diff --git a/db/migrate/20161029151508_change_type_to_message_type.rb b/db/migrate/20161029151508_change_type_to_message_type.rb deleted file mode 100644 index dcdd9ed19..000000000 --- a/db/migrate/20161029151508_change_type_to_message_type.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeTypeToMessageType < ActiveRecord::Migration[5.0] - def change - rename_column :messages, :type, :message_type - end -end diff --git a/db/migrate/20161110102609_removeinboxid.rb b/db/migrate/20161110102609_removeinboxid.rb deleted file mode 100644 index 9fe0bef46..000000000 --- a/db/migrate/20161110102609_removeinboxid.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Removeinboxid < ActiveRecord::Migration[5.0] - def change - remove_column :facebook_pages, :inbox_id - end -end diff --git a/db/migrate/20161113074313_change_integer_limit_of_sender_id.rb b/db/migrate/20161113074313_change_integer_limit_of_sender_id.rb deleted file mode 100644 index 87c816061..000000000 --- a/db/migrate/20161113074313_change_integer_limit_of_sender_id.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeIntegerLimitOfSenderId < ActiveRecord::Migration[5.0] - def change - change_column :conversations, :sender_id, :integer, limit: 8 - end -end diff --git a/db/migrate/20161114101802_create_telegram_bots.rb b/db/migrate/20161114101802_create_telegram_bots.rb deleted file mode 100644 index 1c32ef273..000000000 --- a/db/migrate/20161114101802_create_telegram_bots.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateTelegramBots < ActiveRecord::Migration[5.0] - def change - create_table :telegram_bots do |t| - t.string :name - t.string :auth_key - t.integer :account_id - t.timestamps - end - end -end diff --git a/db/migrate/20161123131628_devise_token_auth_create_users.rb b/db/migrate/20161123131628_devise_token_auth_create_users.rb deleted file mode 100644 index 78e002162..000000000 --- a/db/migrate/20161123131628_devise_token_auth_create_users.rb +++ /dev/null @@ -1,54 +0,0 @@ -class DeviseTokenAuthCreateUsers < ActiveRecord::Migration[5.0] - def change - create_table(:users) do |t| - ## Required - t.string :provider, null: false, default: 'email' - t.string :uid, null: false, default: '' - - ## Database authenticatable - 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.string :current_sign_in_ip - t.string :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 - - ## User Info - t.string :name - t.string :nickname - t.string :image - t.string :email - - ## Tokens - t.json :tokens - t.integer :account_id, null: false - t.timestamps - end - - add_index :users, :email - add_index :users, [:uid, :provider], unique: true - add_index :users, :reset_password_token, unique: true - # add_index :users, :confirmation_token, :unique => true - # add_index :users, :unlock_token, :unique => true - end -end diff --git a/db/migrate/20170124104836_change_contact_to_bigint.rb b/db/migrate/20170124104836_change_contact_to_bigint.rb deleted file mode 100644 index 0df992bd8..000000000 --- a/db/migrate/20170124104836_change_contact_to_bigint.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeContactToBigint < ActiveRecord::Migration[5.0] - def change - change_column :contacts, :id, :bigint - end -end diff --git a/db/migrate/20170131132031_addprivatemessages.rb b/db/migrate/20170131132031_addprivatemessages.rb deleted file mode 100644 index 2f0bfeaf7..000000000 --- a/db/migrate/20170131132031_addprivatemessages.rb +++ /dev/null @@ -1,5 +0,0 @@ -class Addprivatemessages < ActiveRecord::Migration[5.0] - def change - add_column :messages, :private, :boolean, default: false - end -end diff --git a/db/migrate/20170207092002_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb b/db/migrate/20170207092002_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb deleted file mode 100644 index bddadb7d3..000000000 --- a/db/migrate/20170207092002_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,30 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 1) -class ActsAsTaggableOnMigration < ActiveRecord::Migration[5.0] - def self.up - create_table :tags do |t| - t.string :name - end - - create_table :taggings do |t| - t.references :tag - - # You should make sure that the column created is - # long enough to store the required class names. - t.references :taggable, polymorphic: true - t.references :tagger, polymorphic: true - - # Limit is created to prevent MySQL error on index - # length for MyISAM table type: http://bit.ly/vgW2Ql - t.string :context, limit: 128 - - t.datetime :created_at - end - - add_index :taggings, [:taggable_id, :taggable_type, :context] - end - - def self.down - drop_table :taggings - drop_table :tags - end -end diff --git a/db/migrate/20170207092003_add_missing_unique_indices.acts_as_taggable_on_engine.rb b/db/migrate/20170207092003_add_missing_unique_indices.acts_as_taggable_on_engine.rb deleted file mode 100644 index b846a8d54..000000000 --- a/db/migrate/20170207092003_add_missing_unique_indices.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,21 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 2) -class AddMissingUniqueIndices < ActiveRecord::Migration[5.0] - def self.up - add_index :tags, :name, unique: true - - remove_index :taggings, :tag_id if index_exists?(:taggings, :tag_id) - remove_index :taggings, [:taggable_id, :taggable_type, :context] - add_index :taggings, - [:tag_id, :taggable_id, :taggable_type, :context, :tagger_id, :tagger_type], - unique: true, name: 'taggings_idx' - end - - def self.down - remove_index :tags, :name - - remove_index :taggings, name: 'taggings_idx' - - add_index :taggings, :tag_id unless index_exists?(:taggings, :tag_id) - add_index :taggings, [:taggable_id, :taggable_type, :context] - end -end diff --git a/db/migrate/20170207092004_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb b/db/migrate/20170207092004_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb deleted file mode 100644 index 48f05b78b..000000000 --- a/db/migrate/20170207092004_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,15 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 3) -class AddTaggingsCounterCacheToTags < ActiveRecord::Migration[5.0] - def self.up - add_column :tags, :taggings_count, :integer, default: 0 - - ActsAsTaggableOn::Tag.reset_column_information - ActsAsTaggableOn::Tag.find_each do |tag| - ActsAsTaggableOn::Tag.reset_counters(tag.id, :taggings) - end - end - - def self.down - remove_column :tags, :taggings_count - end -end diff --git a/db/migrate/20170207092005_add_missing_taggable_index.acts_as_taggable_on_engine.rb b/db/migrate/20170207092005_add_missing_taggable_index.acts_as_taggable_on_engine.rb deleted file mode 100644 index d099b4cba..000000000 --- a/db/migrate/20170207092005_add_missing_taggable_index.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,10 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 4) -class AddMissingTaggableIndex < ActiveRecord::Migration[5.0] - def self.up - add_index :taggings, [:taggable_id, :taggable_type, :context] - end - - def self.down - remove_index :taggings, [:taggable_id, :taggable_type, :context] - end -end diff --git a/db/migrate/20170207092006_change_collation_for_tag_names.acts_as_taggable_on_engine.rb b/db/migrate/20170207092006_change_collation_for_tag_names.acts_as_taggable_on_engine.rb deleted file mode 100644 index 74468141b..000000000 --- a/db/migrate/20170207092006_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,8 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 5) -# This migration is added to circumvent issue #623 and have special characters -# work properly -class ChangeCollationForTagNames < ActiveRecord::Migration[5.0] - def up - execute('ALTER TABLE tags MODIFY name varchar(255) CHARACTER SET utf8 COLLATE utf8_bin;') if ActsAsTaggableOn::Utils.using_mysql? - end -end diff --git a/db/migrate/20170207092007_add_missing_indexes.acts_as_taggable_on_engine.rb b/db/migrate/20170207092007_add_missing_indexes.acts_as_taggable_on_engine.rb deleted file mode 100644 index e4fa12da2..000000000 --- a/db/migrate/20170207092007_add_missing_indexes.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,13 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 6) -class AddMissingIndexes < ActiveRecord::Migration[5.0] - def change - add_index :taggings, :tag_id - add_index :taggings, :taggable_id - add_index :taggings, :taggable_type - add_index :taggings, :tagger_id - add_index :taggings, :context - - add_index :taggings, [:tagger_id, :tagger_type] - add_index :taggings, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' - end -end diff --git a/db/migrate/20170211092121_addallnametousers.rb b/db/migrate/20170211092121_addallnametousers.rb deleted file mode 100644 index fafd9079a..000000000 --- a/db/migrate/20170211092121_addallnametousers.rb +++ /dev/null @@ -1,8 +0,0 @@ -class Addallnametousers < ActiveRecord::Migration[5.0] - def change - User.all.each do |u| - u.name = 'Subash' - u.save! - end - end -end diff --git a/db/migrate/20170211092540_notnullableusers.rb b/db/migrate/20170211092540_notnullableusers.rb deleted file mode 100644 index 003be7b8d..000000000 --- a/db/migrate/20170211092540_notnullableusers.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Notnullableusers < ActiveRecord::Migration[5.0] - def change - change_column :users, :name, :string, null: false - change_column :users, :account_id, :integer, null: false - end -end diff --git a/db/migrate/20170301135937_add_channel_to_user.rb b/db/migrate/20170301135937_add_channel_to_user.rb deleted file mode 100644 index f438e51af..000000000 --- a/db/migrate/20170301135937_add_channel_to_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddChannelToUser < ActiveRecord::Migration[5.0] - def change - add_column :users, :channel, :string - end -end diff --git a/db/migrate/20170329132640_create_canned_responses.rb b/db/migrate/20170329132640_create_canned_responses.rb deleted file mode 100644 index 2280f317d..000000000 --- a/db/migrate/20170329132640_create_canned_responses.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateCannedResponses < ActiveRecord::Migration[5.0] - def change - create_table :canned_responses do |t| - t.integer :account_id - t.string :short_code - t.text :content - - t.timestamps - end - end -end diff --git a/db/migrate/20170330152347_add_user_id_to_message.rb b/db/migrate/20170330152347_add_user_id_to_message.rb deleted file mode 100644 index 9e20c67f6..000000000 --- a/db/migrate/20170330152347_add_user_id_to_message.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddUserIdToMessage < ActiveRecord::Migration[5.0] - def change - add_column :messages, :user_id, :integer - end -end diff --git a/db/migrate/20170402124536_add_role_to_user.rb b/db/migrate/20170402124536_add_role_to_user.rb deleted file mode 100644 index f78a19275..000000000 --- a/db/migrate/20170402124536_add_role_to_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddRoleToUser < ActiveRecord::Migration[5.0] - def change - add_column :users, :role, :integer, default: 0 - end -end diff --git a/db/migrate/20170403095203_contactadder.rb b/db/migrate/20170403095203_contactadder.rb deleted file mode 100644 index e53781e6c..000000000 --- a/db/migrate/20170403095203_contactadder.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Contactadder < ActiveRecord::Migration[5.0] - def change - change_column :contacts, :id, :integer - add_column :contacts, :source_id, :bigserial - end -end diff --git a/db/migrate/20170403140816_attachments_table.rb b/db/migrate/20170403140816_attachments_table.rb deleted file mode 100644 index fde20050c..000000000 --- a/db/migrate/20170403140816_attachments_table.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AttachmentsTable < ActiveRecord::Migration[5.0] - def change - add_column :contacts, :avatar, :string - end -end diff --git a/db/migrate/20170404095857_add_index_on_fb_page.rb b/db/migrate/20170404095857_add_index_on_fb_page.rb deleted file mode 100644 index 660dd56d8..000000000 --- a/db/migrate/20170404095857_add_index_on_fb_page.rb +++ /dev/null @@ -1,10 +0,0 @@ -class AddIndexOnFbPage < ActiveRecord::Migration[5.0] - def change - add_index :facebook_pages, :page_id - add_index :conversations, :account_id - add_index :contacts, :account_id - add_index :inbox_members, :inbox_id - add_index :inboxes, :account_id - add_index :messages, :conversation_id - end -end diff --git a/db/migrate/20170406091955_add_display_id_to_conversations.rb b/db/migrate/20170406091955_add_display_id_to_conversations.rb deleted file mode 100644 index 974945735..000000000 --- a/db/migrate/20170406091955_add_display_id_to_conversations.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddDisplayIdToConversations < ActiveRecord::Migration[5.0] - def change - add_column :conversations, :display_id, :integer - add_index :conversations, [:account_id, :display_id] - end -end diff --git a/db/migrate/20170406092426_add_display_id.rb b/db/migrate/20170406092426_add_display_id.rb deleted file mode 100644 index 197c957ab..000000000 --- a/db/migrate/20170406092426_add_display_id.rb +++ /dev/null @@ -1,8 +0,0 @@ -class AddDisplayId < ActiveRecord::Migration[5.0] - def change - Conversation.all.each do |conversation| - conversation.display_id = Conversation.where(account_id: conversation.account_id).maximum('display_id').to_i + 1 - conversation.save! - end - end -end diff --git a/db/migrate/20170406095417_create_trigger_conversations_insert.rb b/db/migrate/20170406095417_create_trigger_conversations_insert.rb deleted file mode 100644 index 545a5650e..000000000 --- a/db/migrate/20170406095417_create_trigger_conversations_insert.rb +++ /dev/null @@ -1,7 +0,0 @@ -class CreateTriggerConversationsInsert < ActiveRecord::Migration[5.0] - def up - change_column :conversations, :display_id, :integer, null: false - end - - def down; end -end diff --git a/db/migrate/20170406100716_add_unique_display_id.rb b/db/migrate/20170406100716_add_unique_display_id.rb deleted file mode 100644 index 6786df7ff..000000000 --- a/db/migrate/20170406100716_add_unique_display_id.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddUniqueDisplayId < ActiveRecord::Migration[5.0] - def change - remove_index(:conversations, name: 'index_conversations_on_account_id_and_display_id') - add_index :conversations, [:account_id, :display_id], unique: true - end -end diff --git a/db/migrate/20170406104018_add_default_status_conv.rb b/db/migrate/20170406104018_add_default_status_conv.rb deleted file mode 100644 index dbfd3e958..000000000 --- a/db/migrate/20170406104018_add_default_status_conv.rb +++ /dev/null @@ -1,20 +0,0 @@ -class AddDefaultStatusConv < ActiveRecord::Migration[5.0] - def change - change_column :conversations, :status, :integer, null: false, default: 0 - change_column :conversations, :inbox_id, :integer, null: false - change_column :conversations, :account_id, :integer, null: false - change_column :contacts, :inbox_id, :integer, null: false - change_column :contacts, :account_id, :integer, null: false - change_column :canned_responses, :account_id, :integer, null: false - change_column :inbox_members, :user_id, :integer, null: false - change_column :inbox_members, :inbox_id, :integer, null: false - change_column :inboxes, :channel_id, :integer, null: false - change_column :inboxes, :account_id, :integer, null: false - change_column :inboxes, :name, :string, null: false - change_column :messages, :account_id, :integer, null: false - change_column :messages, :inbox_id, :integer, null: false - change_column :messages, :conversation_id, :integer, null: false - change_column :messages, :message_type, :integer, null: false - change_column :facebook_pages, :name, :string, null: false - end -end diff --git a/db/migrate/20170406134310_add_status_to_message.rb b/db/migrate/20170406134310_add_status_to_message.rb deleted file mode 100644 index 074beffc6..000000000 --- a/db/migrate/20170406134310_add_status_to_message.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddStatusToMessage < ActiveRecord::Migration[5.0] - def change - add_column :messages, :status, :integer, default: 0 - end -end diff --git a/db/migrate/20170406134632_add_fb_id_to_message.rb b/db/migrate/20170406134632_add_fb_id_to_message.rb deleted file mode 100644 index b1de85f4d..000000000 --- a/db/migrate/20170406134632_add_fb_id_to_message.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddFbIdToMessage < ActiveRecord::Migration[5.0] - def change - add_column :messages, :fb_id, :string - end -end diff --git a/db/migrate/20170408123445_add_last_seen_at_to_conversation.rb b/db/migrate/20170408123445_add_last_seen_at_to_conversation.rb deleted file mode 100644 index 3d376861e..000000000 --- a/db/migrate/20170408123445_add_last_seen_at_to_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddLastSeenAtToConversation < ActiveRecord::Migration[5.0] - def change - add_column :conversations, :last_seen_at, :date - end -end diff --git a/db/migrate/20170410101932_change_last_seen_at_to_date_time.rb b/db/migrate/20170410101932_change_last_seen_at_to_date_time.rb deleted file mode 100644 index 29f7d69ae..000000000 --- a/db/migrate/20170410101932_change_last_seen_at_to_date_time.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ChangeLastSeenAtToDateTime < ActiveRecord::Migration[5.0] - def change - change_column :conversations, :last_seen_at, :datetime - end -end diff --git a/db/migrate/20170424171708_create_subscriptions.rb b/db/migrate/20170424171708_create_subscriptions.rb deleted file mode 100644 index 00a9845d0..000000000 --- a/db/migrate/20170424171708_create_subscriptions.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateSubscriptions < ActiveRecord::Migration[5.0] - def change - create_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.timestamps - end - end -end diff --git a/db/migrate/20170426083945_create_attachments.rb b/db/migrate/20170426083945_create_attachments.rb deleted file mode 100644 index c247fc454..000000000 --- a/db/migrate/20170426083945_create_attachments.rb +++ /dev/null @@ -1,14 +0,0 @@ -class CreateAttachments < ActiveRecord::Migration[5.0] - def change - create_table :attachments do |t| - t.string :file - t.integer :file_type, default: 0 - t.string :external_url - t.integer :coordinates_lat, default: 0 - t.integer :coordinates_long, default: 0 - t.integer :message_id, null: false - t.integer :account_id, null: false - t.timestamps - end - end -end diff --git a/db/migrate/20170426102045_add_fallback_title_to_attachments.rb b/db/migrate/20170426102045_add_fallback_title_to_attachments.rb deleted file mode 100644 index 289b698b1..000000000 --- a/db/migrate/20170426102045_add_fallback_title_to_attachments.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddFallbackTitleToAttachments < ActiveRecord::Migration[5.0] - def change - add_column :attachments, :fallback_title, :string, default: nil - end -end diff --git a/db/migrate/20170426125410_last_seen_at_to_user_last_seen_at.rb b/db/migrate/20170426125410_last_seen_at_to_user_last_seen_at.rb deleted file mode 100644 index dee3195cd..000000000 --- a/db/migrate/20170426125410_last_seen_at_to_user_last_seen_at.rb +++ /dev/null @@ -1,5 +0,0 @@ -class LastSeenAtToUserLastSeenAt < ActiveRecord::Migration[5.0] - def change - rename_column :conversations, :last_seen_at, :user_last_seen_at - end -end diff --git a/db/migrate/20170426130050_add_agent_last_seen_at_to_conversation.rb b/db/migrate/20170426130050_add_agent_last_seen_at_to_conversation.rb deleted file mode 100644 index 230701f21..000000000 --- a/db/migrate/20170426130050_add_agent_last_seen_at_to_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAgentLastSeenAtToConversation < ActiveRecord::Migration[5.0] - def change - add_column :conversations, :agent_last_seen_at, :datetime - end -end diff --git a/db/migrate/20170503104957_add_lock_to_conversation.rb b/db/migrate/20170503104957_add_lock_to_conversation.rb deleted file mode 100644 index 304524e4e..000000000 --- a/db/migrate/20170503104957_add_lock_to_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddLockToConversation < ActiveRecord::Migration[5.0] - def change - add_column :conversations, :locked, :boolean, default: false - end -end diff --git a/db/migrate/20170503162643_create_extension_for_file.rb b/db/migrate/20170503162643_create_extension_for_file.rb deleted file mode 100644 index 1528498a2..000000000 --- a/db/migrate/20170503162643_create_extension_for_file.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'uri' -class CreateExtensionForFile < ActiveRecord::Migration[5.0] - def change - add_column :attachments, :extension, :string, default: nil - Attachment.find_each do |attachment| - if attachment.external_url && (attachment.file_type != fallback) - attachment.extension = begin - Pathname.new(URI(attachment.external_url).path).extname - rescue StandardError - nil - end - attachment.save! - end - end - end -end diff --git a/db/migrate/20170505164157_add_state_to_subscription.rb b/db/migrate/20170505164157_add_state_to_subscription.rb deleted file mode 100644 index 80b570891..000000000 --- a/db/migrate/20170505164157_add_state_to_subscription.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddStateToSubscription < ActiveRecord::Migration[5.0] - def change - add_column :subscriptions, :state, :integer, default: 0 - end -end diff --git a/db/migrate/20170511134418_latlong.rb b/db/migrate/20170511134418_latlong.rb deleted file mode 100644 index 2328f28e0..000000000 --- a/db/migrate/20170511134418_latlong.rb +++ /dev/null @@ -1,6 +0,0 @@ -class Latlong < ActiveRecord::Migration[5.0] - def change - change_column :attachments, :coordinates_lat, :float, default: 0 - change_column :attachments, :coordinates_long, :float, default: 0 - end -end diff --git a/db/migrate/20170513085726_add_payment_source_added_to_subscription.rb b/db/migrate/20170513085726_add_payment_source_added_to_subscription.rb deleted file mode 100644 index 86575099e..000000000 --- a/db/migrate/20170513085726_add_payment_source_added_to_subscription.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPaymentSourceAddedToSubscription < ActiveRecord::Migration[5.0] - def change - add_column :subscriptions, :payment_source_added, :boolean, default: false - end -end diff --git a/db/migrate/20170519085519_add_pic_to_inbox.rb b/db/migrate/20170519085519_add_pic_to_inbox.rb deleted file mode 100644 index e5f38300f..000000000 --- a/db/migrate/20170519085519_add_pic_to_inbox.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddPicToInbox < ActiveRecord::Migration[5.0] - def change - add_column :inboxes, :avatar, :string, default: nil - end -end diff --git a/db/migrate/20170519091539_add_avatar_to_fb.rb b/db/migrate/20170519091539_add_avatar_to_fb.rb deleted file mode 100644 index 17a8e06b8..000000000 --- a/db/migrate/20170519091539_add_avatar_to_fb.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddAvatarToFb < ActiveRecord::Migration[5.0] - def change - remove_column :inboxes, :avatar - add_column :facebook_pages, :avatar, :string, default: nil - end -end diff --git a/db/migrate/20170525104650_create_round_robin.rb b/db/migrate/20170525104650_create_round_robin.rb deleted file mode 100644 index 620f48007..000000000 --- a/db/migrate/20170525104650_create_round_robin.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateRoundRobin < ActiveRecord::Migration[5.0] - def change - InboxMember.find_each do |im| - round_robin_key = format(::Redis::Alfred::ROUND_ROBIN_AGENTS, inbox_id: im.inbox_id) - Redis::Alfred.lpush(round_robin_key, im.user_id) - end - end -end diff --git a/db/migrate/20171014112346_create_channel_widgets.rb b/db/migrate/20171014112346_create_channel_widgets.rb deleted file mode 100644 index 43ee49d69..000000000 --- a/db/migrate/20171014112346_create_channel_widgets.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateChannelWidgets < ActiveRecord::Migration[5.0] - def change - create_table :channel_widgets do |t| - t.string :website_name - t.string :website_url - t.integer :account_id - - t.timestamps - end - end -end diff --git a/db/migrate/20171014113353_add_chat_channel_to_contact.rb b/db/migrate/20171014113353_add_chat_channel_to_contact.rb deleted file mode 100644 index 11a909643..000000000 --- a/db/migrate/20171014113353_add_chat_channel_to_contact.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddChatChannelToContact < ActiveRecord::Migration[5.0] - def change - add_column :contacts, :chat_channel, :string - end -end diff --git a/db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb b/db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb deleted file mode 100644 index 7c3958963..000000000 --- a/db/migrate/20190819005836_add_missing_indexes_on_taggings.acts_as_taggable_on_engine.rb +++ /dev/null @@ -1,23 +0,0 @@ -# This migration comes from acts_as_taggable_on_engine (originally 6) -if ActiveRecord.gem_version >= Gem::Version.new('5.0') - class AddMissingIndexesOnTaggings < ActiveRecord::Migration[4.2]; end -else - class AddMissingIndexesOnTaggings < ActiveRecord::Migration; end -end -AddMissingIndexesOnTaggings.class_eval do - def change - add_index ActsAsTaggableOn.taggings_table, :tag_id unless index_exists? ActsAsTaggableOn.taggings_table, :tag_id - add_index ActsAsTaggableOn.taggings_table, :taggable_id unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_id - add_index ActsAsTaggableOn.taggings_table, :taggable_type unless index_exists? ActsAsTaggableOn.taggings_table, :taggable_type - add_index ActsAsTaggableOn.taggings_table, :tagger_id unless index_exists? ActsAsTaggableOn.taggings_table, :tagger_id - add_index ActsAsTaggableOn.taggings_table, :context unless index_exists? ActsAsTaggableOn.taggings_table, :context - - unless index_exists? ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] - add_index ActsAsTaggableOn.taggings_table, [:tagger_id, :tagger_type] - end - - unless index_exists? ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' - add_index ActsAsTaggableOn.taggings_table, [:taggable_id, :taggable_type, :tagger_id, :context], name: 'taggings_idy' - end - end -end diff --git a/db/migrate/20190819010457_create_channels.rb b/db/migrate/20190819010457_create_channels.rb deleted file mode 100644 index 1f8c18300..000000000 --- a/db/migrate/20190819010457_create_channels.rb +++ /dev/null @@ -1,8 +0,0 @@ -class CreateChannels < ActiveRecord::Migration[6.0] - def change - create_table :channels do |t| - t.string :name - t.timestamps - end - end -end diff --git a/db/migrate/20191014051743_add_invited_by_to_user.rb b/db/migrate/20191014051743_add_invited_by_to_user.rb deleted file mode 100644 index 376be2713..000000000 --- a/db/migrate/20191014051743_add_invited_by_to_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddInvitedByToUser < ActiveRecord::Migration[6.0] - def change - add_reference(:users, :inviter, foreign_key: { to_table: :users }) - end -end diff --git a/db/migrate/20191016211109_rename_channel_attribute_name_in_models.rb b/db/migrate/20191016211109_rename_channel_attribute_name_in_models.rb deleted file mode 100644 index 4d0054f34..000000000 --- a/db/migrate/20191016211109_rename_channel_attribute_name_in_models.rb +++ /dev/null @@ -1,9 +0,0 @@ -class RenameChannelAttributeNameInModels < ActiveRecord::Migration[6.0] - def change - rename_column :users, :channel, :pubsub_token - rename_column :contacts, :chat_channel, :pubsub_token - - add_index :users, :pubsub_token, unique: true - add_index :contacts, :pubsub_token, unique: true - end -end diff --git a/db/migrate/20191020085608_rename_old_tables.rb b/db/migrate/20191020085608_rename_old_tables.rb deleted file mode 100644 index 72958458d..000000000 --- a/db/migrate/20191020085608_rename_old_tables.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RenameOldTables < ActiveRecord::Migration[6.0] - def change - drop_table :channels - rename_table :facebook_pages, :channel_facebook_pages - rename_table :channel_widgets, :channel_web_widgets - end -end diff --git a/db/migrate/20191020173522_rename_sender_id_to_contact_in_conversation.rb b/db/migrate/20191020173522_rename_sender_id_to_contact_in_conversation.rb deleted file mode 100644 index 9bb163f8c..000000000 --- a/db/migrate/20191020173522_rename_sender_id_to_contact_in_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RenameSenderIdToContactInConversation < ActiveRecord::Migration[6.0] - def change - rename_column :conversations, :sender_id, :contact_id - end -end diff --git a/db/migrate/20191024062958_add_website_token_to_web_widget.rb b/db/migrate/20191024062958_add_website_token_to_web_widget.rb deleted file mode 100644 index feab00af5..000000000 --- a/db/migrate/20191024062958_add_website_token_to_web_widget.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddWebsiteTokenToWebWidget < ActiveRecord::Migration[6.0] - def change - add_column :channel_web_widgets, :website_token, :string - add_index :channel_web_widgets, :website_token, unique: true - end -end diff --git a/db/migrate/20191027054756_create_contact_inboxes.rb b/db/migrate/20191027054756_create_contact_inboxes.rb deleted file mode 100644 index e794858f5..000000000 --- a/db/migrate/20191027054756_create_contact_inboxes.rb +++ /dev/null @@ -1,15 +0,0 @@ -class CreateContactInboxes < ActiveRecord::Migration[6.0] - def change - create_table :contact_inboxes do |t| - t.references :contact, foreign_key: true, index: true - t.references :inbox, foreign_key: true, index: true - t.string :source_id, null: false - - t.timestamps - end - add_index :contact_inboxes, [:inbox_id, :source_id], unique: true - add_index :contact_inboxes, [:source_id] - remove_column :contacts, :inbox_id, :integer - remove_column :contacts, :source_id, :integer - end -end diff --git a/db/migrate/20191116073924_add_additional_attributes_to_conversation.rb b/db/migrate/20191116073924_add_additional_attributes_to_conversation.rb deleted file mode 100644 index 942156185..000000000 --- a/db/migrate/20191116073924_add_additional_attributes_to_conversation.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAdditionalAttributesToConversation < ActiveRecord::Migration[6.0] - def change - add_column :conversations, :additional_attributes, :jsonb - end -end diff --git a/db/migrate/20191124091232_add_widget_color_to_web_widget.rb b/db/migrate/20191124091232_add_widget_color_to_web_widget.rb deleted file mode 100644 index b67e57bab..000000000 --- a/db/migrate/20191124091232_add_widget_color_to_web_widget.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddWidgetColorToWebWidget < ActiveRecord::Migration[6.0] - def change - add_column :channel_web_widgets, :widget_color, :string, default: '#1f93ff' - end -end diff --git a/db/migrate/20191126185833_update_user_invite_foreign_key.rb b/db/migrate/20191126185833_update_user_invite_foreign_key.rb deleted file mode 100644 index d11f093a1..000000000 --- a/db/migrate/20191126185833_update_user_invite_foreign_key.rb +++ /dev/null @@ -1,6 +0,0 @@ -class UpdateUserInviteForeignKey < ActiveRecord::Migration[6.0] - def change - remove_foreign_key :users, column: :inviter_id - add_foreign_key :users, :users, column: :inviter_id, on_delete: :nullify - end -end diff --git a/db/migrate/20191130164019_add_template_type_to_messages.rb b/db/migrate/20191130164019_add_template_type_to_messages.rb deleted file mode 100644 index ec4c0e949..000000000 --- a/db/migrate/20191130164019_add_template_type_to_messages.rb +++ /dev/null @@ -1,6 +0,0 @@ -class AddTemplateTypeToMessages < ActiveRecord::Migration[6.0] - def change - add_column :messages, :content_type, :integer, default: '0' - add_column :messages, :content_attributes, :json, default: {} - end -end diff --git a/db/migrate/20191202173004_add_not_null_constraint_to_account_name.rb b/db/migrate/20191202173004_add_not_null_constraint_to_account_name.rb deleted file mode 100644 index 4b7110f29..000000000 --- a/db/migrate/20191202173004_add_not_null_constraint_to_account_name.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddNotNullConstraintToAccountName < ActiveRecord::Migration[6.0] - def change - change_column_null :accounts, :name, false - end -end diff --git a/db/migrate/20191204192301_add_index_unique_channel_facebook_page_id_account_id.rb b/db/migrate/20191204192301_add_index_unique_channel_facebook_page_id_account_id.rb deleted file mode 100644 index 88cf7be58..000000000 --- a/db/migrate/20191204192301_add_index_unique_channel_facebook_page_id_account_id.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddIndexUniqueChannelFacebookPageIdAccountId < ActiveRecord::Migration[6.0] - def change - add_index :channel_facebook_pages, [:page_id, :account_id], unique: true - end -end diff --git a/db/migrate/20191209195420_create_active_storage_tables.active_storage.rb b/db/migrate/20191209195420_create_active_storage_tables.active_storage.rb deleted file mode 100644 index abb5cc28b..000000000 --- a/db/migrate/20191209195420_create_active_storage_tables.active_storage.rb +++ /dev/null @@ -1,27 +0,0 @@ -# This migration comes from active_storage (originally 20170806125915) -class CreateActiveStorageTables < ActiveRecord::Migration[5.2] - def change - 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], unique: true - end - - create_table :active_storage_attachments do |t| - t.string :name, null: false - t.references :record, null: false, polymorphic: true, index: false - t.references :blob, null: false - - t.datetime :created_at, null: false - - t.index [:record_type, :record_id, :name, :blob_id], name: 'index_active_storage_attachments_uniqueness', unique: true - t.foreign_key :active_storage_blobs, column: :blob_id - end - end -end diff --git a/db/migrate/20191209202758_remove_image_from_user.rb b/db/migrate/20191209202758_remove_image_from_user.rb deleted file mode 100644 index 1ece3d317..000000000 --- a/db/migrate/20191209202758_remove_image_from_user.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RemoveImageFromUser < ActiveRecord::Migration[6.0] - def change - remove_column :users, :image, :string - end -end diff --git a/db/migrate/20191227191631_remove_carrier_wave_attributes.rb b/db/migrate/20191227191631_remove_carrier_wave_attributes.rb deleted file mode 100644 index e40156abf..000000000 --- a/db/migrate/20191227191631_remove_carrier_wave_attributes.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RemoveCarrierWaveAttributes < ActiveRecord::Migration[6.0] - def change - remove_column :contacts, :avatar, :string - remove_column :channel_facebook_pages, :avatar, :string - remove_column :attachments, :file, :string - end -end diff --git a/db/migrate/20200107164449_add_contact_inbox_to_conversation.rb b/db/migrate/20200107164449_add_contact_inbox_to_conversation.rb deleted file mode 100644 index 47ab3cf7a..000000000 --- a/db/migrate/20200107164449_add_contact_inbox_to_conversation.rb +++ /dev/null @@ -1,14 +0,0 @@ -class AddContactInboxToConversation < ActiveRecord::Migration[6.0] - def change - add_reference(:conversations, :contact_inbox, foreign_key: true, index: true) - - ::Conversation.all.each do |conversation| - contact_inbox = ::ContactInbox.find_by( - contact_id: conversation.contact_id, - inbox_id: conversation.inbox_id - ) - - conversation.update!(contact_inbox_id: contact_inbox.id) if contact_inbox - end - end -end diff --git a/db/migrate/20200121190900_add_notification_settings.rb b/db/migrate/20200121190900_add_notification_settings.rb deleted file mode 100644 index c8c59a021..000000000 --- a/db/migrate/20200121190900_add_notification_settings.rb +++ /dev/null @@ -1,24 +0,0 @@ -class AddNotificationSettings < ActiveRecord::Migration[6.0] - def change - return if ActiveRecord::Base.connection.data_source_exists? 'notification_settings' - - create_table :notification_settings do |t| - t.integer :account_id - t.integer :user_id - t.integer :email_flags, null: false, default: 0 - - t.timestamps - end - - add_index :notification_settings, [:account_id, :user_id], unique: true, name: 'by_account_user' - - ::User.find_in_batches do |users_batch| - users_batch.each do |user| - user_notification_setting = user.notification_settings.new(account_id: user.account_id) - user_notification_setting.conversation_creation = false - user_notification_setting.conversation_assignment = true - user_notification_setting.save! - end - end - end -end diff --git a/db/migrate/20200121190901_create_account_users.rb b/db/migrate/20200121190901_create_account_users.rb deleted file mode 100644 index 555c7cf3f..000000000 --- a/db/migrate/20200121190901_create_account_users.rb +++ /dev/null @@ -1,42 +0,0 @@ -class CreateAccountUsers < ActiveRecord::Migration[6.0] - def change - create_table :account_users do |t| - t.references :account, foreign_key: true, index: true - t.references :user, foreign_key: true, index: true - t.integer :role, default: 0 - t.bigint :inviter_id - t.timestamps - end - - migrate_to_account_users - - remove_column :users, :account_id, :bigint - remove_column :users, :role, :integer - remove_column :users, :inviter_id, :bigint - end - - def migrate_to_account_users - ::User.find_in_batches.each do |users| - users.each do |user| - account_user = ::AccountUser.find_by(account_id: user.account_id, user_id: user.id, role: user.role) - - notification_setting = ::NotificationSetting.find_by(account_id: user.account_id, user_id: user.id) - selected_email_flags = notification_setting.selected_email_flags - notification_setting.destroy! - - next if account_user.present? - - ::AccountUser.create!( - account_id: user.account_id, - user_id: user.id, - role: user[:role], # since we are overriding role method, lets fetch value from attribute - inviter_id: user.inviter_id - ) - - updated_notification_setting = ::NotificationSetting.find_by(account_id: user.account_id, user_id: user.id) - updated_notification_setting.selected_email_flags = selected_email_flags - updated_notification_setting.save! - end - end - end -end diff --git a/db/migrate/20200121220431_add_uniqueness_constraint_to_account_users.rb b/db/migrate/20200121220431_add_uniqueness_constraint_to_account_users.rb deleted file mode 100644 index 2d49c3feb..000000000 --- a/db/migrate/20200121220431_add_uniqueness_constraint_to_account_users.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddUniquenessConstraintToAccountUsers < ActiveRecord::Migration[6.0] - def change - add_index :account_users, [:account_id, :user_id], unique: true, name: 'uniq_user_id_per_account_id' - end -end diff --git a/db/migrate/20200124190208_create_channel_twitter_profiles.rb b/db/migrate/20200124190208_create_channel_twitter_profiles.rb deleted file mode 100644 index abb654669..000000000 --- a/db/migrate/20200124190208_create_channel_twitter_profiles.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateChannelTwitterProfiles < ActiveRecord::Migration[6.0] - def change - 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.timestamps - end - end -end diff --git a/db/migrate/20200206180408_add_contact_to_message.rb b/db/migrate/20200206180408_add_contact_to_message.rb deleted file mode 100644 index 5b3dc4080..000000000 --- a/db/migrate/20200206180408_add_contact_to_message.rb +++ /dev/null @@ -1,12 +0,0 @@ -class AddContactToMessage < ActiveRecord::Migration[6.0] - def change - add_reference(:messages, :contact, foreign_key: true, index: true) - - ::Message.all.each do |message| - conversation = message.conversation - next if conversation.contact.nil? - - message.update!(contact_id: conversation.contact.id) - end - end -end diff --git a/db/migrate/20200206180927_rename_fb_id_to_source_id.rb b/db/migrate/20200206180927_rename_fb_id_to_source_id.rb deleted file mode 100644 index 99d7a1eaa..000000000 --- a/db/migrate/20200206180927_rename_fb_id_to_source_id.rb +++ /dev/null @@ -1,7 +0,0 @@ -class RenameFbIdToSourceId < ActiveRecord::Migration[6.0] - def change - rename_column :messages, :fb_id, :source_id - - add_index(:messages, :source_id) - end -end diff --git a/db/migrate/20200206182948_add_additional_attributes_to_contact.rb b/db/migrate/20200206182948_add_additional_attributes_to_contact.rb deleted file mode 100644 index 34a8ca9bf..000000000 --- a/db/migrate/20200206182948_add_additional_attributes_to_contact.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddAdditionalAttributesToContact < ActiveRecord::Migration[6.0] - def change - add_column :contacts, :additional_attributes, :jsonb - end -end diff --git a/db/migrate/20200213054733_create_webhooks.rb b/db/migrate/20200213054733_create_webhooks.rb deleted file mode 100644 index 470cbe373..000000000 --- a/db/migrate/20200213054733_create_webhooks.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateWebhooks < ActiveRecord::Migration[6.0] - def change - create_table :webhooks do |t| - t.integer :account_id - t.integer :inbox_id - t.string :urls - - t.timestamps - end - end -end diff --git a/db/migrate/20200217192734_add_enable_auto_assignment_to_inboxes.rb b/db/migrate/20200217192734_add_enable_auto_assignment_to_inboxes.rb deleted file mode 100644 index 85dbc3a9b..000000000 --- a/db/migrate/20200217192734_add_enable_auto_assignment_to_inboxes.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddEnableAutoAssignmentToInboxes < ActiveRecord::Migration[6.0] - def change - add_column :inboxes, :enable_auto_assignment, :boolean, default: true - end -end diff --git a/db/migrate/20200222143100_create_agent_bots.rb b/db/migrate/20200222143100_create_agent_bots.rb deleted file mode 100644 index 896ec8a0b..000000000 --- a/db/migrate/20200222143100_create_agent_bots.rb +++ /dev/null @@ -1,12 +0,0 @@ -class CreateAgentBots < ActiveRecord::Migration[6.0] - def change - create_table :agent_bots do |t| - t.string :name - t.string :description - t.string :outgoing_url - t.string :auth_token, unique: true - - t.timestamps - end - end -end diff --git a/db/migrate/20200222143259_create_agent_bot_inboxes.rb b/db/migrate/20200222143259_create_agent_bot_inboxes.rb deleted file mode 100644 index b2d50165e..000000000 --- a/db/migrate/20200222143259_create_agent_bot_inboxes.rb +++ /dev/null @@ -1,11 +0,0 @@ -class CreateAgentBotInboxes < ActiveRecord::Migration[6.0] - def change - create_table :agent_bot_inboxes do |t| - t.integer :inbox_id - t.integer :agent_bot_id - t.integer :status, default: 0 - - t.timestamps - end - end -end diff --git a/db/migrate/20200225160650_rename_urls_to_url.rb b/db/migrate/20200225160650_rename_urls_to_url.rb deleted file mode 100644 index fa86aa059..000000000 --- a/db/migrate/20200225160650_rename_urls_to_url.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RenameUrlsToUrl < ActiveRecord::Migration[6.0] - def change - rename_column :webhooks, :urls, :url - end -end diff --git a/db/migrate/20200225162150_add_type_to_webhook.rb b/db/migrate/20200225162150_add_type_to_webhook.rb deleted file mode 100644 index 871590aee..000000000 --- a/db/migrate/20200225162150_add_type_to_webhook.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddTypeToWebhook < ActiveRecord::Migration[6.0] - def change - add_column :webhooks, :webhook_type, :integer, default: '0' - end -end diff --git a/db/migrate/20200225162150_init_schema.rb b/db/migrate/20200225162150_init_schema.rb new file mode 100644 index 000000000..9b6bd39c3 --- /dev/null +++ b/db/migrate/20200225162150_init_schema.rb @@ -0,0 +1,280 @@ +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 diff --git a/db/schema.rb b/db/schema.rb index fa9bf8959..b582ed1a1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -13,7 +13,6 @@ ActiveRecord::Schema.define(version: 2020_08_28_175931) do # These are extensions that must be enabled in order to support this database - enable_extension "pg_stat_statements" enable_extension "pgcrypto" enable_extension "plpgsql" @@ -402,9 +401,11 @@ ActiveRecord::Schema.define(version: 2020_08_28_175931) do t.index ["taggable_id", "taggable_type", "context"], name: "index_taggings_on_taggable_id_and_taggable_type_and_context" t.index ["taggable_id", "taggable_type", "tagger_id", "context"], name: "taggings_idy" t.index ["taggable_id"], name: "index_taggings_on_taggable_id" + t.index ["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 ["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 ["tagger_type", "tagger_id"], name: "index_taggings_on_tagger_type_and_tagger_id" end create_table "tags", id: :serial, force: :cascade do |t| diff --git a/lib/tasks/db_enhancements.rake b/lib/tasks/db_enhancements.rake index de2c24838..a6535c60f 100644 --- a/lib/tasks/db_enhancements.rake +++ b/lib/tasks/db_enhancements.rake @@ -1,5 +1,7 @@ # We are hooking config loader to run automatically everytime migration is executed Rake::Task['db:migrate'].enhance do - puts 'Loading Installation config' - ConfigLoader.new.process + if ActiveRecord::Base.connection.table_exists? 'installation_configs' + puts 'Loading Installation config' + ConfigLoader.new.process + end end