Chore: Squash previous migrations (#1107)

Fixes: #784
Co-authored-by: Pranav Raj S <pranav@thoughtwoot.com>
This commit is contained in:
Sojan Jose 2020-09-07 15:19:41 +05:30 committed by GitHub
parent 3544514470
commit 3ffb29bf4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
95 changed files with 292 additions and 857 deletions

View file

@ -129,3 +129,4 @@ AllCops:
- 'config/environments/**/*'
- 'tmp/**/*'
- 'storage/**/*'
- 'db/migrate/20200225162150_init_schema.rb'

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddSenderToConversation < ActiveRecord::Migration[5.0]
def change
add_column :conversations, :sender_id, :integer
end
end

View file

@ -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

View file

@ -1,5 +0,0 @@
class Dropchannels < ActiveRecord::Migration[5.0]
def change
# drop_table :channels
end
end

View file

@ -1,5 +0,0 @@
class Addchanneltype < ActiveRecord::Migration[5.0]
def change
add_column :inboxes, :channel_type, :string
end
end

View file

@ -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

View file

@ -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

View file

@ -1,6 +0,0 @@
class Remchannel < ActiveRecord::Migration[5.0]
def change
remove_column :conversations, :channel_id
remove_column :messages, :channel_id
end
end

View file

@ -1,5 +0,0 @@
class ChangeTypeToMessageType < ActiveRecord::Migration[5.0]
def change
rename_column :messages, :type, :message_type
end
end

View file

@ -1,5 +0,0 @@
class Removeinboxid < ActiveRecord::Migration[5.0]
def change
remove_column :facebook_pages, :inbox_id
end
end

View file

@ -1,5 +0,0 @@
class ChangeIntegerLimitOfSenderId < ActiveRecord::Migration[5.0]
def change
change_column :conversations, :sender_id, :integer, limit: 8
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class ChangeContactToBigint < ActiveRecord::Migration[5.0]
def change
change_column :contacts, :id, :bigint
end
end

View file

@ -1,5 +0,0 @@
class Addprivatemessages < ActiveRecord::Migration[5.0]
def change
add_column :messages, :private, :boolean, default: false
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddChannelToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :channel, :string
end
end

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddUserIdToMessage < ActiveRecord::Migration[5.0]
def change
add_column :messages, :user_id, :integer
end
end

View file

@ -1,5 +0,0 @@
class AddRoleToUser < ActiveRecord::Migration[5.0]
def change
add_column :users, :role, :integer, default: 0
end
end

View file

@ -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

View file

@ -1,5 +0,0 @@
class AttachmentsTable < ActiveRecord::Migration[5.0]
def change
add_column :contacts, :avatar, :string
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddStatusToMessage < ActiveRecord::Migration[5.0]
def change
add_column :messages, :status, :integer, default: 0
end
end

View file

@ -1,5 +0,0 @@
class AddFbIdToMessage < ActiveRecord::Migration[5.0]
def change
add_column :messages, :fb_id, :string
end
end

View file

@ -1,5 +0,0 @@
class AddLastSeenAtToConversation < ActiveRecord::Migration[5.0]
def change
add_column :conversations, :last_seen_at, :date
end
end

View file

@ -1,5 +0,0 @@
class ChangeLastSeenAtToDateTime < ActiveRecord::Migration[5.0]
def change
change_column :conversations, :last_seen_at, :datetime
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddFallbackTitleToAttachments < ActiveRecord::Migration[5.0]
def change
add_column :attachments, :fallback_title, :string, default: nil
end
end

View file

@ -1,5 +0,0 @@
class LastSeenAtToUserLastSeenAt < ActiveRecord::Migration[5.0]
def change
rename_column :conversations, :last_seen_at, :user_last_seen_at
end
end

View file

@ -1,5 +0,0 @@
class AddAgentLastSeenAtToConversation < ActiveRecord::Migration[5.0]
def change
add_column :conversations, :agent_last_seen_at, :datetime
end
end

View file

@ -1,5 +0,0 @@
class AddLockToConversation < ActiveRecord::Migration[5.0]
def change
add_column :conversations, :locked, :boolean, default: false
end
end

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddStateToSubscription < ActiveRecord::Migration[5.0]
def change
add_column :subscriptions, :state, :integer, default: 0
end
end

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddPaymentSourceAddedToSubscription < ActiveRecord::Migration[5.0]
def change
add_column :subscriptions, :payment_source_added, :boolean, default: false
end
end

View file

@ -1,5 +0,0 @@
class AddPicToInbox < ActiveRecord::Migration[5.0]
def change
add_column :inboxes, :avatar, :string, default: nil
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddChatChannelToContact < ActiveRecord::Migration[5.0]
def change
add_column :contacts, :chat_channel, :string
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddInvitedByToUser < ActiveRecord::Migration[6.0]
def change
add_reference(:users, :inviter, foreign_key: { to_table: :users })
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class RenameSenderIdToContactInConversation < ActiveRecord::Migration[6.0]
def change
rename_column :conversations, :sender_id, :contact_id
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddAdditionalAttributesToConversation < ActiveRecord::Migration[6.0]
def change
add_column :conversations, :additional_attributes, :jsonb
end
end

View file

@ -1,5 +0,0 @@
class AddWidgetColorToWebWidget < ActiveRecord::Migration[6.0]
def change
add_column :channel_web_widgets, :widget_color, :string, default: '#1f93ff'
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddNotNullConstraintToAccountName < ActiveRecord::Migration[6.0]
def change
change_column_null :accounts, :name, false
end
end

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class RemoveImageFromUser < ActiveRecord::Migration[6.0]
def change
remove_column :users, :image, :string
end
end

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class AddAdditionalAttributesToContact < ActiveRecord::Migration[6.0]
def change
add_column :contacts, :additional_attributes, :jsonb
end
end

View file

@ -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

View file

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

View file

@ -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

View file

@ -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

View file

@ -1,5 +0,0 @@
class RenameUrlsToUrl < ActiveRecord::Migration[6.0]
def change
rename_column :webhooks, :urls, :url
end
end

View file

@ -1,5 +0,0 @@
class AddTypeToWebhook < ActiveRecord::Migration[6.0]
def change
add_column :webhooks, :webhook_type, :integer, default: '0'
end
end

View file

@ -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

View file

@ -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|

View file

@ -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