Restructure omni services and add Chatwoot research snapshot
This commit is contained in:
878
research/chatwoot/db/migrate/20230426130150_init_schema.rb
Normal file
878
research/chatwoot/db/migrate/20230426130150_init_schema.rb
Normal file
@@ -0,0 +1,878 @@
|
||||
class InitSchema < ActiveRecord::Migration[6.1]
|
||||
def up
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "pg_stat_statements"
|
||||
enable_extension "pg_trgm"
|
||||
enable_extension "pgcrypto"
|
||||
enable_extension "plpgsql"
|
||||
create_table "access_tokens" do |t|
|
||||
t.string "owner_type"
|
||||
t.bigint "owner_id"
|
||||
t.string "token"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["owner_type", "owner_id"], name: "index_access_tokens_on_owner_type_and_owner_id"
|
||||
t.index ["token"], name: "index_access_tokens_on_token", unique: true
|
||||
end
|
||||
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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.datetime "active_at", precision: nil
|
||||
t.integer "availability", default: 0, null: false
|
||||
t.boolean "auto_offline", default: true, null: false
|
||||
t.index ["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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.integer "locale", default: 0
|
||||
t.string "domain", limit: 100
|
||||
t.string "support_email", limit: 100
|
||||
t.integer "feature_flags", default: 0, null: false
|
||||
t.integer "auto_resolve_duration"
|
||||
t.jsonb "limits", default: {}
|
||||
t.jsonb "custom_attributes", default: {}
|
||||
t.integer "status", default: 0
|
||||
t.index ["status"], name: "index_accounts_on_status"
|
||||
end
|
||||
create_table "action_mailbox_inbound_emails" do |t|
|
||||
t.integer "status", default: 0, null: false
|
||||
t.string "message_id", null: false
|
||||
t.string "message_checksum", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["message_id", "message_checksum"], name: "index_action_mailbox_inbound_emails_uniqueness", unique: true
|
||||
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", precision: nil, null: false
|
||||
t.index ["blob_id"], name: "index_active_storage_attachments_on_blob_id"
|
||||
t.index ["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"
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.string "service_name", null: false
|
||||
t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true
|
||||
end
|
||||
create_table "active_storage_variant_records" do |t|
|
||||
t.bigint "blob_id", null: false
|
||||
t.string "variation_digest", null: false
|
||||
t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", 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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "account_id"
|
||||
end
|
||||
create_table "agent_bots" do |t|
|
||||
t.string "name"
|
||||
t.string "description"
|
||||
t.string "outgoing_url"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "account_id"
|
||||
t.integer "bot_type", default: 0
|
||||
t.jsonb "bot_config", default: {}
|
||||
t.index ["account_id"], name: "index_agent_bots_on_account_id"
|
||||
end
|
||||
create_table "articles" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.integer "portal_id", null: false
|
||||
t.integer "category_id"
|
||||
t.integer "folder_id"
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.text "content"
|
||||
t.integer "status"
|
||||
t.integer "views"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.bigint "author_id"
|
||||
t.bigint "associated_article_id"
|
||||
t.jsonb "meta", default: {}
|
||||
t.string "slug", null: false
|
||||
t.integer "position"
|
||||
t.index ["associated_article_id"], name: "index_articles_on_associated_article_id"
|
||||
t.index ["author_id"], name: "index_articles_on_author_id"
|
||||
t.index ["slug"], name: "index_articles_on_slug", unique: true
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "fallback_title"
|
||||
t.string "extension"
|
||||
t.index ["account_id"], name: "index_attachments_on_account_id"
|
||||
t.index ["message_id"], name: "index_attachments_on_message_id"
|
||||
end
|
||||
create_table "audits" do |t|
|
||||
t.bigint "auditable_id"
|
||||
t.string "auditable_type"
|
||||
t.bigint "associated_id"
|
||||
t.string "associated_type"
|
||||
t.bigint "user_id"
|
||||
t.string "user_type"
|
||||
t.string "username"
|
||||
t.string "action"
|
||||
t.jsonb "audited_changes"
|
||||
t.integer "version", default: 0
|
||||
t.string "comment"
|
||||
t.string "remote_address"
|
||||
t.string "request_uuid"
|
||||
t.datetime "created_at", precision: nil
|
||||
t.index ["associated_type", "associated_id"], name: "associated_index"
|
||||
t.index ["auditable_type", "auditable_id", "version"], name: "auditable_index"
|
||||
t.index ["created_at"], name: "index_audits_on_created_at"
|
||||
t.index ["request_uuid"], name: "index_audits_on_request_uuid"
|
||||
t.index ["user_id", "user_type"], name: "user_index"
|
||||
end
|
||||
create_table "automation_rules" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.string "name", null: false
|
||||
t.text "description"
|
||||
t.string "event_name", null: false
|
||||
t.jsonb "conditions", default: "{}", null: false
|
||||
t.jsonb "actions", default: "{}", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "active", default: true, null: false
|
||||
t.index ["account_id"], name: "index_automation_rules_on_account_id"
|
||||
end
|
||||
create_table "campaigns" do |t|
|
||||
t.integer "display_id", null: false
|
||||
t.string "title", null: false
|
||||
t.text "description"
|
||||
t.text "message", null: false
|
||||
t.integer "sender_id"
|
||||
t.boolean "enabled", default: true
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "inbox_id", null: false
|
||||
t.jsonb "trigger_rules", default: {}
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "campaign_type", default: 0, null: false
|
||||
t.integer "campaign_status", default: 0, null: false
|
||||
t.jsonb "audience", default: []
|
||||
t.datetime "scheduled_at", precision: nil
|
||||
t.boolean "trigger_only_during_business_hours", default: false
|
||||
t.index ["account_id"], name: "index_campaigns_on_account_id"
|
||||
t.index ["campaign_status"], name: "index_campaigns_on_campaign_status"
|
||||
t.index ["campaign_type"], name: "index_campaigns_on_campaign_type"
|
||||
t.index ["inbox_id"], name: "index_campaigns_on_inbox_id"
|
||||
t.index ["scheduled_at"], name: "index_campaigns_on_scheduled_at"
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
end
|
||||
create_table "categories" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.integer "portal_id", null: false
|
||||
t.string "name"
|
||||
t.text "description"
|
||||
t.integer "position"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "locale", default: "en"
|
||||
t.string "slug", null: false
|
||||
t.bigint "parent_category_id"
|
||||
t.bigint "associated_category_id"
|
||||
t.index ["associated_category_id"], name: "index_categories_on_associated_category_id"
|
||||
t.index ["locale", "account_id"], name: "index_categories_on_locale_and_account_id"
|
||||
t.index ["locale"], name: "index_categories_on_locale"
|
||||
t.index ["parent_category_id"], name: "index_categories_on_parent_category_id"
|
||||
t.index ["slug", "locale", "portal_id"], name: "index_categories_on_slug_and_locale_and_portal_id", unique: true
|
||||
end
|
||||
create_table "channel_api" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "webhook_url"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "identifier"
|
||||
t.string "hmac_token"
|
||||
t.boolean "hmac_mandatory", default: false
|
||||
t.jsonb "additional_attributes", default: {}
|
||||
t.index ["hmac_token"], name: "index_channel_api_on_hmac_token", unique: true
|
||||
t.index ["identifier"], name: "index_channel_api_on_identifier", unique: true
|
||||
end
|
||||
create_table "channel_email" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "email", null: false
|
||||
t.string "forward_to_email", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "imap_enabled", default: false
|
||||
t.string "imap_address", default: ""
|
||||
t.integer "imap_port", default: 0
|
||||
t.string "imap_login", default: ""
|
||||
t.string "imap_password", default: ""
|
||||
t.boolean "imap_enable_ssl", default: true
|
||||
t.datetime "imap_inbox_synced_at", precision: nil
|
||||
t.boolean "smtp_enabled", default: false
|
||||
t.string "smtp_address", default: ""
|
||||
t.integer "smtp_port", default: 0
|
||||
t.string "smtp_login", default: ""
|
||||
t.string "smtp_password", default: ""
|
||||
t.string "smtp_domain", default: ""
|
||||
t.boolean "smtp_enable_starttls_auto", default: true
|
||||
t.string "smtp_authentication", default: "login"
|
||||
t.string "smtp_openssl_verify_mode", default: "none"
|
||||
t.boolean "smtp_enable_ssl_tls", default: false
|
||||
t.jsonb "provider_config", default: {}
|
||||
t.string "provider"
|
||||
t.index ["email"], name: "index_channel_email_on_email", unique: true
|
||||
t.index ["forward_to_email"], name: "index_channel_email_on_forward_to_email", unique: true
|
||||
end
|
||||
create_table "channel_facebook_pages", id: :serial do |t|
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "instagram_id"
|
||||
t.index ["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_line" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "line_channel_id", null: false
|
||||
t.string "line_channel_secret", null: false
|
||||
t.string "line_channel_token", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["line_channel_id"], name: "index_channel_line_on_line_channel_id", unique: true
|
||||
end
|
||||
create_table "channel_sms" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "phone_number", null: false
|
||||
t.string "provider", default: "default"
|
||||
t.jsonb "provider_config", default: {}
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["phone_number"], name: "index_channel_sms_on_phone_number", unique: true
|
||||
end
|
||||
create_table "channel_telegram" do |t|
|
||||
t.string "bot_name"
|
||||
t.integer "account_id", null: false
|
||||
t.string "bot_token", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["bot_token"], name: "index_channel_telegram_on_bot_token", unique: true
|
||||
end
|
||||
create_table "channel_twilio_sms" do |t|
|
||||
t.string "phone_number"
|
||||
t.string "auth_token", null: false
|
||||
t.string "account_sid", null: false
|
||||
t.integer "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "medium", default: 0
|
||||
t.string "messaging_service_sid"
|
||||
t.index ["account_sid", "phone_number"], name: "index_channel_twilio_sms_on_account_sid_and_phone_number", unique: true
|
||||
t.index ["messaging_service_sid"], name: "index_channel_twilio_sms_on_messaging_service_sid", unique: true
|
||||
t.index ["phone_number"], name: "index_channel_twilio_sms_on_phone_number", unique: true
|
||||
end
|
||||
create_table "channel_twitter_profiles" do |t|
|
||||
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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "tweets_enabled", default: true
|
||||
t.index ["account_id", "profile_id"], name: "index_channel_twitter_profiles_on_account_id_and_profile_id", unique: true
|
||||
end
|
||||
create_table "channel_web_widgets", id: :serial do |t|
|
||||
t.string "website_url"
|
||||
t.integer "account_id"
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "website_token"
|
||||
t.string "widget_color", default: "#1f93ff"
|
||||
t.string "welcome_title"
|
||||
t.string "welcome_tagline"
|
||||
t.integer "feature_flags", default: 7, null: false
|
||||
t.integer "reply_time", default: 0
|
||||
t.string "hmac_token"
|
||||
t.boolean "pre_chat_form_enabled", default: false
|
||||
t.jsonb "pre_chat_form_options", default: {}
|
||||
t.boolean "hmac_mandatory", default: false
|
||||
t.boolean "continuity_via_email", default: true, null: false
|
||||
t.index ["hmac_token"], name: "index_channel_web_widgets_on_hmac_token", unique: true
|
||||
t.index ["website_token"], name: "index_channel_web_widgets_on_website_token", unique: true
|
||||
end
|
||||
create_table "channel_whatsapp" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "phone_number", null: false
|
||||
t.string "provider", default: "default"
|
||||
t.jsonb "provider_config", default: {}
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.jsonb "message_templates", default: {}
|
||||
t.datetime "message_templates_last_updated", precision: nil
|
||||
t.index ["phone_number"], name: "index_channel_whatsapp_on_phone_number", 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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "hmac_verified", default: false
|
||||
t.string "pubsub_token"
|
||||
t.index ["contact_id"], name: "index_contact_inboxes_on_contact_id"
|
||||
t.index ["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 ["pubsub_token"], name: "index_contact_inboxes_on_pubsub_token", unique: true
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.jsonb "additional_attributes", default: {}
|
||||
t.string "identifier"
|
||||
t.jsonb "custom_attributes", default: {}
|
||||
t.datetime "last_activity_at", precision: nil
|
||||
t.index "lower((email)::text), account_id", name: "index_contacts_on_lower_email_account_id"
|
||||
t.index ["account_id"], name: "index_contacts_on_account_id"
|
||||
t.index ["name", "email", "phone_number", "identifier"], using: 'gin', opclass: "gin_trgm_ops", name: "index_contacts_on_name_email_phone_number_identifier"
|
||||
t.index ["email", "account_id"], name: "uniq_email_per_account_contact", unique: true
|
||||
t.index ["identifier", "account_id"], name: "uniq_identifier_per_account_contact", unique: true
|
||||
t.index ["phone_number", "account_id"], name: "index_contacts_on_phone_number_and_account_id"
|
||||
end
|
||||
create_table "conversation_participants" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "user_id", null: false
|
||||
t.bigint "conversation_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_conversation_participants_on_account_id"
|
||||
t.index ["conversation_id"], name: "index_conversation_participants_on_conversation_id"
|
||||
t.index ["user_id", "conversation_id"], name: "index_conversation_participants_on_user_id_and_conversation_id", unique: true
|
||||
t.index ["user_id"], name: "index_conversation_participants_on_user_id"
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.bigint "contact_id"
|
||||
t.integer "display_id", null: false
|
||||
t.datetime "contact_last_seen_at", precision: nil
|
||||
t.datetime "agent_last_seen_at", precision: nil
|
||||
t.jsonb "additional_attributes", default: {}
|
||||
t.bigint "contact_inbox_id"
|
||||
t.uuid "uuid", default: -> { "gen_random_uuid()" }, null: false
|
||||
t.string "identifier"
|
||||
t.datetime "last_activity_at", precision: nil, default: -> { "CURRENT_TIMESTAMP" }, null: false
|
||||
t.bigint "team_id"
|
||||
t.bigint "campaign_id"
|
||||
t.datetime "snoozed_until", precision: nil
|
||||
t.jsonb "custom_attributes", default: {}
|
||||
t.datetime "assignee_last_seen_at", precision: nil
|
||||
t.datetime "first_reply_created_at", precision: nil
|
||||
t.integer "priority"
|
||||
t.index ["account_id", "display_id"], name: "index_conversations_on_account_id_and_display_id", unique: true
|
||||
t.index ["account_id", "id"], name: "index_conversations_on_id_and_account_id"
|
||||
t.index ["account_id", "inbox_id", "status", "assignee_id"], name: "conv_acid_inbid_stat_asgnid_idx"
|
||||
t.index ["account_id"], name: "index_conversations_on_account_id"
|
||||
t.index ["assignee_id", "account_id"], name: "index_conversations_on_assignee_id_and_account_id"
|
||||
t.index ["campaign_id"], name: "index_conversations_on_campaign_id"
|
||||
t.index ["contact_id"], name: "index_conversations_on_contact_id"
|
||||
t.index ["contact_inbox_id"], name: "index_conversations_on_contact_inbox_id"
|
||||
t.index ["first_reply_created_at"], name: "index_conversations_on_first_reply_created_at"
|
||||
t.index ["inbox_id"], name: "index_conversations_on_inbox_id"
|
||||
t.index ["last_activity_at"], name: "index_conversations_on_last_activity_at"
|
||||
t.index ["priority"], name: "index_conversations_on_priority"
|
||||
t.index ["status", "account_id"], name: "index_conversations_on_status_and_account_id"
|
||||
t.index ["status", "priority"], name: "index_conversations_on_status_and_priority"
|
||||
t.index ["team_id"], name: "index_conversations_on_team_id"
|
||||
t.index ["uuid"], name: "index_conversations_on_uuid", unique: true
|
||||
end
|
||||
create_table "csat_survey_responses" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "conversation_id", null: false
|
||||
t.bigint "message_id", null: false
|
||||
t.integer "rating", null: false
|
||||
t.text "feedback_message"
|
||||
t.bigint "contact_id", null: false
|
||||
t.bigint "assigned_agent_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_csat_survey_responses_on_account_id"
|
||||
t.index ["assigned_agent_id"], name: "index_csat_survey_responses_on_assigned_agent_id"
|
||||
t.index ["contact_id"], name: "index_csat_survey_responses_on_contact_id"
|
||||
t.index ["conversation_id"], name: "index_csat_survey_responses_on_conversation_id"
|
||||
t.index ["message_id"], name: "index_csat_survey_responses_on_message_id", unique: true
|
||||
end
|
||||
create_table "custom_attribute_definitions" do |t|
|
||||
t.string "attribute_display_name"
|
||||
t.string "attribute_key"
|
||||
t.integer "attribute_display_type", default: 0
|
||||
t.integer "default_value"
|
||||
t.integer "attribute_model", default: 0
|
||||
t.bigint "account_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.text "attribute_description"
|
||||
t.jsonb "attribute_values", default: []
|
||||
t.index ["account_id"], name: "index_custom_attribute_definitions_on_account_id"
|
||||
t.index ["attribute_key", "attribute_model", "account_id"], unique: true, name: 'attribute_key_model_index'
|
||||
end
|
||||
create_table "custom_filters" do |t|
|
||||
t.string "name", null: false
|
||||
t.integer "filter_type", default: 0, null: false
|
||||
t.jsonb "query", default: "{}", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_custom_filters_on_account_id"
|
||||
t.index ["user_id"], name: "index_custom_filters_on_user_id"
|
||||
end
|
||||
create_table "dashboard_apps" do |t|
|
||||
t.string "title", null: false
|
||||
t.jsonb "content", default: []
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_dashboard_apps_on_account_id"
|
||||
t.index ["user_id"], name: "index_dashboard_apps_on_user_id"
|
||||
end
|
||||
create_table "data_imports" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.string "data_type", null: false
|
||||
t.integer "status", default: 0, null: false
|
||||
t.text "processing_errors"
|
||||
t.integer "total_records"
|
||||
t.integer "processed_records"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_data_imports_on_account_id"
|
||||
end
|
||||
create_table "email_templates" do |t|
|
||||
t.string "name", null: false
|
||||
t.text "body", null: false
|
||||
t.integer "account_id"
|
||||
t.integer "template_type", default: 1
|
||||
t.integer "locale", default: 0, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["name", "account_id"], name: "index_email_templates_on_name_and_account_id", unique: true
|
||||
end
|
||||
create_table "folders" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.integer "category_id", null: false
|
||||
t.string "name"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.index ["inbox_id", "user_id"], name: "index_inbox_members_on_inbox_id_and_user_id", unique: true
|
||||
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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "channel_type"
|
||||
t.boolean "enable_auto_assignment", default: true
|
||||
t.boolean "greeting_enabled", default: false
|
||||
t.string "greeting_message"
|
||||
t.string "email_address"
|
||||
t.boolean "working_hours_enabled", default: false
|
||||
t.string "out_of_office_message"
|
||||
t.string "timezone", default: "UTC"
|
||||
t.boolean "enable_email_collect", default: true
|
||||
t.boolean "csat_survey_enabled", default: false
|
||||
t.boolean "allow_messages_after_resolved", default: true
|
||||
t.jsonb "auto_assignment_config", default: {}
|
||||
t.boolean "lock_to_single_conversation", default: false, null: false
|
||||
t.bigint "portal_id"
|
||||
t.index ["account_id"], name: "index_inboxes_on_account_id"
|
||||
t.index ["channel_id", "channel_type"], name: "index_inboxes_on_channel_id_and_channel_type"
|
||||
t.index ["portal_id"], name: "index_inboxes_on_portal_id"
|
||||
end
|
||||
create_table "installation_configs" do |t|
|
||||
t.string "name", null: false
|
||||
t.jsonb "serialized_value", default: {}, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "locked", default: true, null: false
|
||||
t.index ["name", "created_at"], name: "index_installation_configs_on_name_and_created_at", unique: true
|
||||
t.index ["name"], name: "index_installation_configs_on_name", unique: true
|
||||
end
|
||||
create_table "integrations_hooks" do |t|
|
||||
t.integer "status", default: 0
|
||||
t.integer "inbox_id"
|
||||
t.integer "account_id"
|
||||
t.string "app_id"
|
||||
t.integer "hook_type", default: 0
|
||||
t.string "reference_id"
|
||||
t.string "access_token"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.jsonb "settings", default: {}
|
||||
end
|
||||
create_table "labels" do |t|
|
||||
t.string "title"
|
||||
t.text "description"
|
||||
t.string "color", default: "#1f93ff", null: false
|
||||
t.boolean "show_on_sidebar"
|
||||
t.bigint "account_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_labels_on_account_id"
|
||||
t.index ["title", "account_id"], name: "index_labels_on_title_and_account_id", unique: true
|
||||
end
|
||||
create_table "macros" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.string "name", null: false
|
||||
t.integer "visibility", default: 0
|
||||
t.bigint "created_by_id"
|
||||
t.bigint "updated_by_id"
|
||||
t.jsonb "actions", default: {}, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_macros_on_account_id"
|
||||
end
|
||||
create_table "mentions" do |t|
|
||||
t.bigint "user_id", null: false
|
||||
t.bigint "conversation_id", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "mentioned_at", precision: nil, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_mentions_on_account_id"
|
||||
t.index ["conversation_id"], name: "index_mentions_on_conversation_id"
|
||||
t.index ["user_id", "conversation_id"], name: "index_mentions_on_user_id_and_conversation_id", unique: true
|
||||
t.index ["user_id"], name: "index_mentions_on_user_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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.boolean "private", default: false
|
||||
t.integer "status", default: 0
|
||||
t.string "source_id"
|
||||
t.integer "content_type", default: 0, null: false
|
||||
t.json "content_attributes", default: {}
|
||||
t.string "sender_type"
|
||||
t.bigint "sender_id"
|
||||
t.jsonb "external_source_ids", default: {}
|
||||
t.jsonb "additional_attributes", default: {}
|
||||
t.index "((additional_attributes -> 'campaign_id'::text))", name: "index_messages_on_additional_attributes_campaign_id", using: :gin
|
||||
t.index ["account_id"], name: "index_messages_on_account_id"
|
||||
t.index ["account_id", "inbox_id"]
|
||||
t.index ["conversation_id"], name: "index_messages_on_conversation_id"
|
||||
t.index "content", using: 'gin', opclass: "gin_trgm_ops"
|
||||
t.index ["inbox_id"], name: "index_messages_on_inbox_id"
|
||||
t.index ["sender_type", "sender_id"], name: "index_messages_on_sender_type_and_sender_id"
|
||||
t.index ["source_id"], name: "index_messages_on_source_id"
|
||||
end
|
||||
create_table "notes" do |t|
|
||||
t.text "content", null: false
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "contact_id", null: false
|
||||
t.bigint "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_notes_on_account_id"
|
||||
t.index ["contact_id"], name: "index_notes_on_contact_id"
|
||||
t.index ["user_id"], name: "index_notes_on_user_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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "push_flags", default: 0, null: false
|
||||
t.index ["account_id", "user_id"], name: "by_account_user", unique: true
|
||||
end
|
||||
create_table "notification_subscriptions" do |t|
|
||||
t.bigint "user_id", null: false
|
||||
t.integer "subscription_type", null: false
|
||||
t.jsonb "subscription_attributes", default: {}, null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.string "identifier"
|
||||
t.index ["identifier"], name: "index_notification_subscriptions_on_identifier", unique: true
|
||||
t.index ["user_id"], name: "index_notification_subscriptions_on_user_id"
|
||||
end
|
||||
create_table "notifications" do |t|
|
||||
t.bigint "account_id", null: false
|
||||
t.bigint "user_id", null: false
|
||||
t.integer "notification_type", null: false
|
||||
t.string "primary_actor_type", null: false
|
||||
t.bigint "primary_actor_id", null: false
|
||||
t.string "secondary_actor_type"
|
||||
t.bigint "secondary_actor_id"
|
||||
t.datetime "read_at", precision: nil
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_notifications_on_account_id"
|
||||
t.index ["primary_actor_type", "primary_actor_id"], name: "uniq_primary_actor_per_account_notifications"
|
||||
t.index ["secondary_actor_type", "secondary_actor_id"], name: "uniq_secondary_actor_per_account_notifications"
|
||||
t.index ["user_id"], name: "index_notifications_on_user_id"
|
||||
end
|
||||
create_table "platform_app_permissibles" do |t|
|
||||
t.bigint "platform_app_id", null: false
|
||||
t.string "permissible_type", null: false
|
||||
t.bigint "permissible_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["permissible_type", "permissible_id"], name: "index_platform_app_permissibles_on_permissibles"
|
||||
t.index ["platform_app_id", "permissible_id", "permissible_type"], name: "unique_permissibles_index", unique: true
|
||||
t.index ["platform_app_id"], name: "index_platform_app_permissibles_on_platform_app_id"
|
||||
end
|
||||
create_table "platform_apps" do |t|
|
||||
t.string "name", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
create_table "portal_members" do |t|
|
||||
t.bigint "portal_id"
|
||||
t.bigint "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["portal_id", "user_id"], name: "index_portal_members_on_portal_id_and_user_id", unique: true
|
||||
t.index ["user_id", "portal_id"], name: "index_portal_members_on_user_id_and_portal_id", unique: true
|
||||
end
|
||||
create_table "portals" do |t|
|
||||
t.integer "account_id", null: false
|
||||
t.string "name", null: false
|
||||
t.string "slug", null: false
|
||||
t.string "custom_domain"
|
||||
t.string "color"
|
||||
t.string "homepage_link"
|
||||
t.string "page_title"
|
||||
t.text "header_text"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.jsonb "config", default: {"allowed_locales"=>["en"]}
|
||||
t.boolean "archived", default: false
|
||||
t.index ["custom_domain"], name: "index_portals_on_custom_domain", unique: true
|
||||
t.index ["slug"], name: "index_portals_on_slug", unique: true
|
||||
end
|
||||
create_table "portals_members", id: false do |t|
|
||||
t.bigint "portal_id", null: false
|
||||
t.bigint "user_id", null: false
|
||||
t.index ["portal_id", "user_id"], name: "index_portals_members_on_portal_id_and_user_id", unique: true
|
||||
t.index ["portal_id"], name: "index_portals_members_on_portal_id"
|
||||
t.index ["user_id"], name: "index_portals_members_on_user_id"
|
||||
end
|
||||
create_table "related_categories" do |t|
|
||||
t.bigint "category_id"
|
||||
t.bigint "related_category_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["category_id", "related_category_id"], name: "index_related_categories_on_category_id_and_related_category_id", unique: true
|
||||
t.index ["related_category_id", "category_id"], name: "index_related_categories_on_related_category_id_and_category_id", unique: true
|
||||
end
|
||||
create_table "reporting_events" do |t|
|
||||
t.string "name"
|
||||
t.float "value"
|
||||
t.integer "account_id"
|
||||
t.integer "inbox_id"
|
||||
t.integer "user_id"
|
||||
t.integer "conversation_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.float "value_in_business_hours"
|
||||
t.datetime "event_start_time", precision: nil
|
||||
t.datetime "event_end_time", precision: nil
|
||||
t.index ["account_id"], name: "index_reporting_events_on_account_id"
|
||||
t.index ["conversation_id"], name: "index_reporting_events_on_conversation_id"
|
||||
t.index ["created_at"], name: "index_reporting_events_on_created_at"
|
||||
t.index ["inbox_id"], name: "index_reporting_events_on_inbox_id"
|
||||
t.index ["name"], name: "index_reporting_events_on_name"
|
||||
t.index ["user_id"], name: "index_reporting_events_on_user_id"
|
||||
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", precision: nil
|
||||
t.index ["context"], name: "index_taggings_on_context"
|
||||
t.index ["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 ["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"], 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"
|
||||
end
|
||||
create_table "tags", id: :serial do |t|
|
||||
t.string "name"
|
||||
t.integer "taggings_count", default: 0
|
||||
t.index "lower((name)::text) gin_trgm_ops", name: "tags_name_trgm_idx", using: :gin
|
||||
t.index ["name"], name: "index_tags_on_name", unique: true
|
||||
end
|
||||
create_table "team_members" do |t|
|
||||
t.bigint "team_id", null: false
|
||||
t.bigint "user_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["team_id", "user_id"], name: "index_team_members_on_team_id_and_user_id", unique: true
|
||||
t.index ["team_id"], name: "index_team_members_on_team_id"
|
||||
t.index ["user_id"], name: "index_team_members_on_user_id"
|
||||
end
|
||||
create_table "teams" do |t|
|
||||
t.string "name", null: false
|
||||
t.text "description"
|
||||
t.boolean "allow_auto_assign", default: true
|
||||
t.bigint "account_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["account_id"], name: "index_teams_on_account_id"
|
||||
t.index ["name", "account_id"], name: "index_teams_on_name_and_account_id", 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", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, 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", precision: nil
|
||||
t.datetime "remember_created_at", precision: nil
|
||||
t.integer "sign_in_count", default: 0, null: false
|
||||
t.datetime "current_sign_in_at", precision: nil
|
||||
t.datetime "last_sign_in_at", precision: nil
|
||||
t.string "current_sign_in_ip"
|
||||
t.string "last_sign_in_ip"
|
||||
t.string "confirmation_token"
|
||||
t.datetime "confirmed_at", precision: nil
|
||||
t.datetime "confirmation_sent_at", precision: nil
|
||||
t.string "unconfirmed_email"
|
||||
t.string "name", null: false
|
||||
t.string "display_name"
|
||||
t.string "email"
|
||||
t.json "tokens"
|
||||
t.datetime "created_at", precision: nil, null: false
|
||||
t.datetime "updated_at", precision: nil, null: false
|
||||
t.string "pubsub_token"
|
||||
t.integer "availability", default: 0
|
||||
t.jsonb "ui_settings", default: {}
|
||||
t.jsonb "custom_attributes", default: {}
|
||||
t.string "type"
|
||||
t.text "message_signature"
|
||||
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 ["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", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "webhook_type", default: 0
|
||||
t.jsonb "subscriptions", default: ["conversation_status_changed", "conversation_updated", "conversation_created", "contact_created", "contact_updated", "message_created", "message_updated", "webwidget_triggered"]
|
||||
t.index ["account_id", "url"], name: "index_webhooks_on_account_id_and_url", unique: true
|
||||
end
|
||||
create_table "working_hours" do |t|
|
||||
t.bigint "inbox_id"
|
||||
t.bigint "account_id"
|
||||
t.integer "day_of_week", null: false
|
||||
t.boolean "closed_all_day", default: false
|
||||
t.integer "open_hour"
|
||||
t.integer "open_minutes"
|
||||
t.integer "close_hour"
|
||||
t.integer "close_minutes"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.boolean "open_all_day", default: false
|
||||
t.index ["account_id"], name: "index_working_hours_on_account_id"
|
||||
t.index ["inbox_id"], name: "index_working_hours_on_inbox_id"
|
||||
end
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "inboxes", "portals"
|
||||
create_trigger("accounts_after_insert_row_tr", :generated => true, :compatibility => 1).
|
||||
on("accounts").
|
||||
after(:insert).
|
||||
for_each(:row) do
|
||||
"execute format('create sequence IF NOT EXISTS conv_dpid_seq_%s', NEW.id);"
|
||||
end
|
||||
create_trigger("conversations_before_insert_row_tr", :generated => true, :compatibility => 1).
|
||||
on("conversations").
|
||||
before(:insert).
|
||||
for_each(:row) do
|
||||
"NEW.display_id := nextval('conv_dpid_seq_' || NEW.account_id);"
|
||||
end
|
||||
create_trigger("camp_dpid_before_insert", :generated => true, :compatibility => 1).
|
||||
on("accounts").
|
||||
name("camp_dpid_before_insert").
|
||||
after(:insert).
|
||||
for_each(:row) do
|
||||
"execute format('create sequence IF NOT EXISTS camp_dpid_seq_%s', NEW.id);"
|
||||
end
|
||||
create_trigger("campaigns_before_insert_row_tr", :generated => true, :compatibility => 1).
|
||||
on("campaigns").
|
||||
before(:insert).
|
||||
for_each(:row) do
|
||||
"NEW.display_id := nextval('camp_dpid_seq_' || NEW.account_id);"
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
raise ActiveRecord::IrreversibleMigration, "The initial migration is not revertable"
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateSlaPolicies < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :sla_policies do |t|
|
||||
t.string :name, null: false
|
||||
t.float :frt_threshold, default: nil
|
||||
t.float :rt_threshold, default: nil
|
||||
t.boolean 'only_during_business_hours', default: false
|
||||
t.references :account, index: true, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddIndexToMessagesCreatedAt < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
def change
|
||||
add_index :messages, [:created_at], name: 'index_messages_on_created_at', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexToMessagesForReportings < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
def change
|
||||
add_index :messages, [:conversation_id, :account_id, :message_type, :created_at], name: 'index_messages_on_conversation_account_type_created',
|
||||
algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class SetDefaultEmptyStringForContactName < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_default :contacts, :name, from: nil, to: ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,57 @@
|
||||
class ArticleKeyConverter
|
||||
def initialize(article)
|
||||
@article = article
|
||||
end
|
||||
|
||||
def process
|
||||
new_content = replace(@article.content)
|
||||
@article.update(content: new_content)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def convert_key(id)
|
||||
verifier_name = 'ActiveStorage'
|
||||
key_generator = ActiveSupport::KeyGenerator.new(Rails.application.secrets.secret_key_base, iterations: 1000,
|
||||
hash_digest_class: OpenSSL::Digest::SHA1)
|
||||
key_generator = ActiveSupport::CachingKeyGenerator.new(key_generator)
|
||||
secret = key_generator.generate_key(verifier_name.to_s)
|
||||
verifier = ActiveSupport::MessageVerifier.new(secret)
|
||||
|
||||
begin
|
||||
ActiveStorage::Blob.find(verifier.verify(id, purpose: :blob_id))
|
||||
.try(:signed_id)
|
||||
rescue StandardError
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def replace(text)
|
||||
keys = get_keys(text)
|
||||
keys.each do |key|
|
||||
new_key = convert_key(key)
|
||||
text = text.gsub(key, new_key) if new_key
|
||||
end
|
||||
text
|
||||
end
|
||||
|
||||
def get_keys(text)
|
||||
uris = text.scan(URI::DEFAULT_PARSER.make_regexp).flatten.select do |x|
|
||||
x.to_s.include?('rails/active_storage')
|
||||
end
|
||||
|
||||
uris.map { |x| x.split('/')[-2] }
|
||||
end
|
||||
end
|
||||
|
||||
# rubocop:disable Style/OneClassPerFile
|
||||
class UpdateArticleImageKeys < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# Iterate through all articles
|
||||
Article.find_each do |article|
|
||||
# Run the ArticleKeyConverter for each one
|
||||
ArticleKeyConverter.new(article).process
|
||||
end
|
||||
end
|
||||
end
|
||||
# rubocop:enable Style/OneClassPerFile
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddPartialIndexForResolvedContacts < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :contacts, [:account_id, :email, :phone_number, :identifier], where: "(email <> '' OR phone_number <> '' OR identifier <> '')",
|
||||
name: 'index_contacts_on_nonempty_fields', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCustomSenderNameToggle < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :inboxes, :sender_name_type, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddProcessedMessageContentToMessages < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :messages, :processed_message_content, :text, null: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexToReportingEvents < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :reporting_events, [:account_id, :name, :created_at], name: 'reporting_events__account_id__name__created_at', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSenderNameToIn < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :inboxes, :business_name, :string, null: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSlaPolicyToConversations < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :conversations, :sla_policy_id, :bigint
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddWaitingSinceToConversations < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :conversations, :waiting_since, :datetime
|
||||
add_index :conversations, :waiting_since
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class SentimentColumnToMessages < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :messages, :sentiment, :jsonb, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddApiKeySidToTwilioSms < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :channel_twilio_sms, :api_key_sid, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddPartialIndexContactAccountId < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :contacts, [:account_id], where: "(email <> '' OR phone_number <> '' OR identifier <> '')",
|
||||
name: 'index_resolved_contact_account_id', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,17 @@
|
||||
class UpdateDefaultStatusInHooks < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_column_default :integrations_hooks, :status, 1
|
||||
|
||||
update_default_status
|
||||
end
|
||||
|
||||
def down
|
||||
change_column_default :integrations_hooks, :status, 0
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_default_status
|
||||
Integrations::Hook.all.update(status: 'enabled')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddRegexToCustomAttributeDefinition < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :custom_attribute_definitions, :regex_pattern, :string
|
||||
add_column :custom_attribute_definitions, :regex_cue, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class EnsureMessagePrivateNotNull < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :messages, :private, false, false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddIconToCategories < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :categories, :icon, :string, default: ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class ChangeFeatureFlagsToBigintInAccounts < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_column :accounts, :feature_flags, :bigint
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :accounts, :feature_flags, :integer
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSnoozedUntilToNotifications < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :notifications, :snoozed_until, :datetime
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveNotificationsWithMessagePrimaryActor < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
Migration::RemoveMessageNotifications.perform_later
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddCachedLabelsList < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :conversations, :cached_label_list, :string
|
||||
Conversation.reset_column_information
|
||||
ActsAsTaggableOn::Taggable::Cache.included(Conversation)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class ReRunCacheLabelJob < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
update_exisiting_conversations
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def update_exisiting_conversations
|
||||
# Run label migrations on the accounts that are not suspended
|
||||
::Account.active.find_in_batches do |account_batch|
|
||||
account_batch.each do |account|
|
||||
Migration::ConversationCacheLabelJob.perform_later(account)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddLastActivityAtToNotifications < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :notifications, :last_activity_at, :datetime, default: -> { 'CURRENT_TIMESTAMP' }
|
||||
add_index :notifications, :last_activity_at
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class RefactorSlaPolicyColumns < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
rename_column :sla_policies, :rt_threshold, :next_response_time_threshold
|
||||
rename_column :sla_policies, :frt_threshold, :first_response_time_threshold
|
||||
add_column :sla_policies, :description, :string
|
||||
add_column :sla_policies, :resolution_time_threshold, :float
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateAppliedSlas < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :applied_slas do |t|
|
||||
t.references :account, null: false
|
||||
t.references :sla_policy, null: false
|
||||
t.references :conversation, null: false
|
||||
|
||||
t.string :sla_status
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddContactTypeToContacts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :contacts, :contact_type, :integer, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddMiddleNameAndLastNameToContacts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :contacts, :middle_name, :string, default: ''
|
||||
add_column :contacts, :last_name, :string, default: ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddLocationAndCountryCodeToContacts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :contacts, :location, :string, default: ''
|
||||
add_column :contacts, :country_code, :string, default: ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveImapInboxSynedAtFromChannelEmail < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
remove_column :channel_email, :imap_inbox_synced_at, :datetime
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class ChangeAppliedSlaSlaStatusToEnum < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
remove_column :applied_slas, :sla_status, :string
|
||||
add_column :applied_slas, :sla_status, :integer, default: 0
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddBlockedToContacts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :contacts, :blocked, :boolean, default: false, null: false
|
||||
add_index :contacts, :blocked
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddMetaToNotifications < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :notifications, :meta, :jsonb, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddUniqueIndexToAppliedSlas < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_index :applied_slas,
|
||||
[:account_id, :sla_policy_id, :conversation_id],
|
||||
unique: true,
|
||||
name: 'index_applied_slas_on_account_sla_policy_conversation'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
class ChangeIdentifierTypeInNotificationsSubscriptions < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_column :notification_subscriptions, :identifier, :text
|
||||
end
|
||||
|
||||
def down
|
||||
change_column :notification_subscriptions, :identifier, :string
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class CreateSlaEvents < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :sla_events do |t|
|
||||
t.references :applied_sla, null: false
|
||||
t.references :conversation, null: false
|
||||
t.references :account, null: false
|
||||
t.references :sla_policy, null: false
|
||||
t.references :inbox, null: false
|
||||
|
||||
t.integer :event_type
|
||||
t.jsonb :meta, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,32 @@
|
||||
class ConvertCachedLabelListToText < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_column :conversations, :cached_label_list, :text
|
||||
end
|
||||
|
||||
def down
|
||||
# This might cause data loss if the text is longer than 255 characters
|
||||
# lets start by truncating the data to 255 characters
|
||||
Conversation.where('LENGTH(cached_label_list) > 255').find_in_batches do |conversation_batch|
|
||||
Conversation.transaction do
|
||||
conversation_batch.each do |conversation|
|
||||
conversation.update!(cached_label_list: truncate_list(conversation.cached_label_list))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
change_column :conversations, :cached_label_list, :string
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Truncate the list to 255 characters or less
|
||||
# by removing the last element until the length is less than 255
|
||||
def truncate_list(label_list)
|
||||
labels = label_list.split(',')
|
||||
|
||||
# we add the `labels.length - 1` to account for the commas
|
||||
labels.pop while (labels.join(',').length + labels.length - 1) > 255
|
||||
|
||||
labels.join(',')
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddChannelWebWidgetToPortals < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :portals, :channel_web_widget_id, :bigint
|
||||
add_index :portals, :channel_web_widget_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class IndexImprovementsConversationsContacts < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
remove_index :conversations, :last_activity_at
|
||||
add_index :contacts, [:account_id, :last_activity_at],
|
||||
order: { last_activity_at: 'DESC NULLS LAST' },
|
||||
algorithm: :concurrently,
|
||||
name: 'index_contacts_on_account_id_and_last_activity_at'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexForMessageTypeAccountDate < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :messages, [:account_id, :created_at, :message_type], name: 'index_messages_on_account_created_type', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class AddCustomRoles < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# Create the roles table
|
||||
create_table :custom_roles do |t|
|
||||
t.string :name
|
||||
t.string :description
|
||||
t.references :account, null: false
|
||||
t.text :permissions, array: true, default: []
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
# Associate the custom role with account user
|
||||
# Add the custom_role_id column to the account_users table
|
||||
add_reference :account_users, :custom_role, optional: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
class AddLocaleToArticle < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :articles, :locale, :string, default: 'en', null: false
|
||||
|
||||
set_locale_from_category
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_locale_from_category
|
||||
Article.find_in_batches do |article_batch|
|
||||
article_batch.each do |article|
|
||||
locale = if article.category.present?
|
||||
article.category.locale
|
||||
else
|
||||
article.portal.default_locale
|
||||
end
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
article.update_columns(locale: locale)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
class FixOldAudioAlertData < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
|
||||
# Update users with audio alerts enabled to 'mine'
|
||||
User.where(
|
||||
"users.ui_settings #>> '{enable_audio_alerts}' = ?", 'true'
|
||||
).update_all(
|
||||
"ui_settings = jsonb_set(ui_settings, '{enable_audio_alerts}', '\"mine\"')"
|
||||
)
|
||||
|
||||
# Update users with audio alerts enabled to 'none'
|
||||
User
|
||||
.where("users.ui_settings #>> '{enable_audio_alerts}' = ?", 'true')
|
||||
.update_all("ui_settings = jsonb_set(ui_settings, '{enable_audio_alerts}', '\"mine\"')")
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,90 @@
|
||||
class CreateCaptainTables < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
# Post this migration, the 'vector' extension is mandatory to run the application.
|
||||
# If the extension is not installed, the migration will raise an error.
|
||||
setup_vector_extension
|
||||
create_assistants
|
||||
create_documents
|
||||
create_assistant_responses
|
||||
create_old_tables
|
||||
end
|
||||
|
||||
def down
|
||||
drop_table :captain_assistant_responses if table_exists?(:captain_assistant_responses)
|
||||
drop_table :captain_documents if table_exists?(:captain_documents)
|
||||
drop_table :captain_assistants if table_exists?(:captain_assistants)
|
||||
drop_table :article_embeddings if table_exists?(:article_embeddings)
|
||||
|
||||
# We are not disabling the extension here because it might be
|
||||
# used by other tables which are not part of this migration.
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def setup_vector_extension
|
||||
return if extension_enabled?('vector')
|
||||
|
||||
begin
|
||||
enable_extension 'vector'
|
||||
rescue ActiveRecord::StatementInvalid
|
||||
raise StandardError, "Failed to enable 'vector' extension. Read more at https://chwt.app/v4/migration"
|
||||
end
|
||||
end
|
||||
|
||||
def create_assistants
|
||||
create_table :captain_assistants do |t|
|
||||
t.string :name, null: false
|
||||
t.bigint :account_id, null: false
|
||||
t.string :description
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_assistants, :account_id
|
||||
add_index :captain_assistants, [:account_id, :name], unique: true
|
||||
end
|
||||
|
||||
def create_documents
|
||||
create_table :captain_documents do |t|
|
||||
t.string :name, null: false
|
||||
t.string :external_link, null: false
|
||||
t.text :content
|
||||
t.bigint :assistant_id, null: false
|
||||
t.bigint :account_id, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_documents, :account_id
|
||||
add_index :captain_documents, :assistant_id
|
||||
add_index :captain_documents, [:assistant_id, :external_link], unique: true
|
||||
end
|
||||
|
||||
def create_assistant_responses
|
||||
create_table :captain_assistant_responses do |t|
|
||||
t.string :question, null: false
|
||||
t.text :answer, null: false
|
||||
t.vector :embedding, limit: 1536
|
||||
t.bigint :assistant_id, null: false
|
||||
t.bigint :document_id
|
||||
t.bigint :account_id, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_assistant_responses, :account_id
|
||||
add_index :captain_assistant_responses, :assistant_id
|
||||
add_index :captain_assistant_responses, :document_id
|
||||
add_index :captain_assistant_responses, :embedding, using: :ivfflat, name: 'vector_idx_knowledge_entries_embedding', opclass: :vector_l2_ops
|
||||
end
|
||||
|
||||
def create_old_tables
|
||||
create_table :article_embeddings, if_not_exists: true do |t|
|
||||
t.bigint :article_id, null: false
|
||||
t.text :term, null: false
|
||||
t.vector :embedding, limit: 1536
|
||||
t.timestamps
|
||||
end
|
||||
add_index :article_embeddings, :embedding, if_not_exists: true, using: :ivfflat, opclass: :vector_l2_ops
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class RemoveRobinTables < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
# rubocop:disable Rails/ReversibleMigration
|
||||
drop_table :responses if table_exists?(:responses)
|
||||
drop_table :response_sources if table_exists?(:response_sources)
|
||||
drop_table :response_documents if table_exists?(:response_documents)
|
||||
drop_table :inbox_response_sources if table_exists?(:inbox_response_sources)
|
||||
# rubocop:enable Rails/ReversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddStatusToCaptainDocuments < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :captain_documents, :status, :integer, null: false, default: 0
|
||||
add_index :captain_documents, :status
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveNotNullFromCaptainDocuments < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :captain_documents, :name, true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddConfigToCaptainAssistant < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :captain_assistants, :config, :jsonb, default: {}, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class CreateCaptainInbox < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :captain_inboxes do |t|
|
||||
t.references :captain_assistant, null: false
|
||||
t.references :inbox, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_inboxes, [:captain_assistant_id, :inbox_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveIndexFromCaptainAssistants < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
remove_index :captain_assistants, [:account_id, :name], if_exists: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddStatusToCaptainAssistantResponses < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :captain_assistant_responses, :status, :integer, default: 1, null: false
|
||||
add_index :captain_assistant_responses, :status
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,35 @@
|
||||
class ConvertDocumentToPolymorphicAssociation < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
add_column :captain_assistant_responses, :documentable_type, :string
|
||||
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
if ChatwootApp.enterprise?
|
||||
Captain::AssistantResponse
|
||||
.where
|
||||
.not(document_id: nil)
|
||||
.update_all(documentable_type: 'Captain::Document')
|
||||
end
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
remove_index :captain_assistant_responses, :document_id if index_exists?(
|
||||
:captain_assistant_responses, :document_id
|
||||
)
|
||||
|
||||
rename_column :captain_assistant_responses, :document_id, :documentable_id
|
||||
add_index :captain_assistant_responses, [:documentable_id, :documentable_type],
|
||||
name: 'idx_cap_asst_resp_on_documentable'
|
||||
end
|
||||
|
||||
def down
|
||||
if index_exists?(
|
||||
:captain_assistant_responses, [:documentable_id, :documentable_type], name: 'idx_cap_asst_resp_on_documentable'
|
||||
)
|
||||
remove_index :captain_assistant_responses, name: 'idx_cap_asst_resp_on_documentable'
|
||||
end
|
||||
|
||||
rename_column :captain_assistant_responses, :documentable_id, :document_id
|
||||
remove_column :captain_assistant_responses, :documentable_type
|
||||
add_index :captain_assistant_responses, :document_id unless index_exists?(
|
||||
:captain_assistant_responses, :document_id
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddMetaToAttachment < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :attachments, :meta, :jsonb, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddInternalAttributesToAccounts < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :accounts, :internal_attributes, :jsonb, null: false, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class AddIndexToArticles < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_index :articles, :status unless index_exists?(:articles, :status)
|
||||
add_index :articles, :views unless index_exists?(:articles, :views)
|
||||
add_index :articles, :portal_id unless index_exists?(:articles, :portal_id)
|
||||
add_index :articles, :account_id unless index_exists?(:articles, :account_id)
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class AddInstagramChannel < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :channel_instagram do |t|
|
||||
t.string :access_token, null: false
|
||||
t.datetime :expires_at, null: false
|
||||
t.integer :account_id, null: false
|
||||
t.string :instagram_id, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :channel_instagram, :instagram_id, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class RemovePortalMembers < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
drop_table :portal_members
|
||||
end
|
||||
|
||||
def down
|
||||
create_table :portal_members do |t|
|
||||
t.references :portal, index: false
|
||||
t.references :user, index: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :portal_members, [:portal_id, :user_id], unique: true
|
||||
add_index :portal_members, [:user_id, :portal_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class ConvertCsmlBotsToWebhookBots < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
# Find all CSML bots (bot_type = 1) and convert them to webhook (bot_type = 0)
|
||||
AgentBot.where(bot_type: 1).find_each do |bot|
|
||||
bot.update(bot_type: 0, bot_config: {})
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
# This migration is not reversible - we've removed CSML support
|
||||
raise ActiveRecord::IrreversibleMigration
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,24 @@
|
||||
class FlipChatwootV4DefaultFeatureFlagInstallationConfig < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
# Update the default feature flag config to enable chatwoot_v4
|
||||
config = InstallationConfig.find_by(name: 'ACCOUNT_LEVEL_FEATURE_DEFAULTS')
|
||||
if config && config.value.present?
|
||||
features = config.value.map do |f|
|
||||
if f['name'] == 'chatwoot_v4'
|
||||
f.merge('enabled' => true)
|
||||
else
|
||||
f
|
||||
end
|
||||
end
|
||||
config.value = features
|
||||
config.save!
|
||||
end
|
||||
|
||||
# Enable chatwoot_v4 for all accounts in batches of 100
|
||||
Account.find_in_batches(batch_size: 100) do |accounts|
|
||||
accounts.each { |account| account.enable_features!('chatwoot_v4') }
|
||||
end
|
||||
|
||||
GlobalConfig.clear_cache
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSettingsColumnToAccount < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :accounts, :settings, :jsonb, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class UpdateAutoResolveToMminutes < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
Account.where.not(auto_resolve_duration: nil).each do |account|
|
||||
account.auto_resolve_after = account.auto_resolve_duration * 60 * 24
|
||||
account.save!
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class CreateCopilotThreads < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :copilot_threads do |t|
|
||||
t.string :title, null: false
|
||||
t.references :user, null: false, index: true
|
||||
t.references :account, null: false, index: true
|
||||
t.uuid :uuid, null: false, default: 'gen_random_uuid()'
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :copilot_threads, :uuid, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
class CreateCopilotMessages < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :copilot_messages do |t|
|
||||
t.references :copilot_thread, null: false, index: true
|
||||
t.references :user, null: false, index: true
|
||||
t.references :account, null: false, index: true
|
||||
t.string :message_type, null: false
|
||||
t.jsonb :message, null: false, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCsatConfigToInboxes < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
add_column :inboxes, :csat_config, :jsonb, default: {}, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
class RemoveUuidFromCopilotThreads < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_column :copilot_threads, :uuid, :string
|
||||
|
||||
add_column :copilot_threads, :assistant_id, :integer
|
||||
add_index :copilot_threads, :assistant_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class RemoveUserIdFromCopilotMessages < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
remove_reference :copilot_messages, :user, index: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class ChangeMessageTypeToIntegerInCopilotMessages < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
remove_column :copilot_messages, :message_type
|
||||
add_column :copilot_messages, :message_type, :integer, default: 0
|
||||
end
|
||||
|
||||
def down
|
||||
remove_column :copilot_messages, :message_type
|
||||
add_column :copilot_messages, :message_type, :string, default: 'user'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class CreateChannelVoice < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
create_table :channel_voice do |t|
|
||||
t.string :phone_number, null: false
|
||||
t.string :provider, null: false, default: 'twilio'
|
||||
t.jsonb :provider_config, null: false
|
||||
t.integer :account_id, null: false
|
||||
t.jsonb :additional_attributes, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :channel_voice, :phone_number, unique: true
|
||||
add_index :channel_voice, :account_id
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
class AddIndexToMessages < ActiveRecord::Migration[7.0]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
# This index is added as a temporary fix for performance issues in the CSAT
|
||||
# responses controller where we query messages with account_id, content_type
|
||||
# and created_at. The current implementation (account.message.input_csat.count)
|
||||
# times out with millions of messages.
|
||||
#
|
||||
# TODO: Create a dedicated csat_survey table and add entries when surveys are
|
||||
# sent, then query this table instead of the entire messages table for better
|
||||
# performance.
|
||||
return if index_exists?(
|
||||
:messages,
|
||||
[:account_id, :content_type, :created_at],
|
||||
name: 'idx_messages_account_content_created'
|
||||
)
|
||||
|
||||
add_index :messages, [:account_id, :content_type, :created_at],
|
||||
name: 'idx_messages_account_content_created', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddTemplateParamsToCampaigns < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :campaigns, :template_params, :jsonb
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,18 @@
|
||||
class CreateCaptainScenarios < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :captain_scenarios do |t|
|
||||
t.string :title
|
||||
t.text :description
|
||||
t.text :instruction
|
||||
t.jsonb :tools, default: []
|
||||
t.boolean :enabled, default: true, null: false
|
||||
t.references :assistant, null: false
|
||||
t.references :account, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_scenarios, :enabled
|
||||
add_index :captain_scenarios, [:assistant_id, :enabled]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddResponseGuidelinesAndGuardrailsToCaptainAssistants < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :captain_assistants, :response_guidelines, :jsonb, default: []
|
||||
add_column :captain_assistants, :guardrails, :jsonb, default: []
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddSslSettingsToPortals < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :portals, :ssl_settings, :jsonb, default: {}, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
class AddIndexOnContactTypeAndAccountIdToContacts < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
add_index :contacts, [:account_id, :contact_type], name: 'index_contacts_on_account_id_and_contact_type', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddMetadataToCaptainDocuments < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :captain_documents, :metadata, :jsonb, default: {}
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class AddNotificationsPerformanceIndex < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
|
||||
def change
|
||||
# Add composite index to optimize notification count queries
|
||||
# This covers the common query pattern: WHERE user_id = ? AND account_id = ? AND snoozed_until IS NULL AND read_at IS NULL
|
||||
add_index :notifications, [:user_id, :account_id, :snoozed_until, :read_at],
|
||||
name: 'idx_notifications_performance',
|
||||
algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateAssignmentPolicies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :assignment_policies do |t|
|
||||
t.references :account, null: false, index: true
|
||||
t.string :name, null: false, limit: 255
|
||||
t.text :description
|
||||
t.integer :assignment_order, null: false, default: 0 # 0: round_robin, 1: balanced
|
||||
t.integer :conversation_priority, null: false, default: 0 # 0: earliest_created, 1: longest_waiting
|
||||
t.integer :fair_distribution_limit, null: false, default: 100
|
||||
t.integer :fair_distribution_window, null: false, default: 3600 # seconds
|
||||
t.boolean :enabled, null: false, default: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :assignment_policies, [:account_id, :name], unique: true
|
||||
add_index :assignment_policies, :enabled
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,12 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateInboxAssignmentPolicies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :inbox_assignment_policies do |t|
|
||||
t.references :inbox, null: false, index: { unique: true }
|
||||
t.references :assignment_policy, null: false, index: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateAgentCapacityPolicies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :agent_capacity_policies do |t|
|
||||
t.references :account, null: false, index: true
|
||||
t.string :name, null: false, limit: 255
|
||||
t.text :description
|
||||
t.jsonb :exclusion_rules, default: {}, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateInboxCapacityLimits < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :inbox_capacity_limits do |t|
|
||||
t.references :agent_capacity_policy, null: false, index: true
|
||||
t.references :inbox, null: false, index: true
|
||||
t.integer :conversation_limit, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :inbox_capacity_limits, [:agent_capacity_policy_id, :inbox_id], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class AddAgentCapacityPolicyToAccountUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :account_users, :agent_capacity_policy, null: true, index: true
|
||||
end
|
||||
end
|
||||
21
research/chatwoot/db/migrate/20250806140005_create_leaves.rb
Normal file
21
research/chatwoot/db/migrate/20250806140005_create_leaves.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateLeaves < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :leaves do |t|
|
||||
t.references :account, null: false
|
||||
t.references :user, null: false
|
||||
t.date :start_date, null: false
|
||||
t.date :end_date, null: false
|
||||
t.integer :leave_type, null: false, default: 0
|
||||
t.integer :status, null: false, default: 0
|
||||
t.text :reason
|
||||
t.references :approved_by
|
||||
t.datetime :approved_at
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :leaves, [:account_id, :status]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,21 @@
|
||||
class AddFeatureCitationToAssistantConfig < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
return unless ChatwootApp.enterprise?
|
||||
|
||||
Captain::Assistant.find_each do |assistant|
|
||||
assistant.update!(
|
||||
config: assistant.config.merge('feature_citation' => true)
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
def down
|
||||
return unless ChatwootApp.enterprise?
|
||||
|
||||
Captain::Assistant.find_each do |assistant|
|
||||
config = assistant.config.dup
|
||||
config.delete('feature_citation')
|
||||
assistant.update!(config: config)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,11 @@
|
||||
class AddTwoFactorToUsers < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :users, :otp_secret, :string
|
||||
add_column :users, :consumed_timestep, :integer
|
||||
add_column :users, :otp_required_for_login, :boolean, default: false, null: false
|
||||
add_column :users, :otp_backup_codes, :text
|
||||
|
||||
add_index :users, :otp_secret, unique: true
|
||||
add_index :users, :otp_required_for_login
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddContentTemplatesToTwilioSms < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :channel_twilio_sms, :content_templates, :jsonb, default: {}
|
||||
add_column :channel_twilio_sms, :content_templates_last_updated, :datetime
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class CreateAccountSamlSettings < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :account_saml_settings do |t|
|
||||
t.references :account, null: false
|
||||
t.string :sso_url
|
||||
t.text :certificate
|
||||
t.string :sp_entity_id
|
||||
t.string :idp_entity_id
|
||||
t.json :role_mappings, default: {}
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,10 @@
|
||||
class DropTelegramBots < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
drop_table :telegram_bots do |t|
|
||||
t.string :name
|
||||
t.string :auth_key
|
||||
t.integer :account_id
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddAllowedDomainsToChannelWidgets < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :channel_web_widgets, :allowed_domains, :text, default: ''
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddVerifiedToChannelEmail < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :channel_email, :verified_for_sending, :boolean, default: false, null: false
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,14 @@
|
||||
class CreateCompanies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :companies do |t|
|
||||
t.string :name, null: false
|
||||
t.string :domain
|
||||
t.text :description
|
||||
t.references :account, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
add_index :companies, [:name, :account_id]
|
||||
add_index :companies, [:domain, :account_id]
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddCompanyToContacts < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_reference :contacts, :company, null: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,22 @@
|
||||
class CreateCaptainCustomTools < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :captain_custom_tools do |t|
|
||||
t.references :account, null: false, index: true
|
||||
t.string :slug, null: false
|
||||
t.string :title, null: false
|
||||
t.text :description
|
||||
t.string :http_method, null: false, default: 'GET'
|
||||
t.text :endpoint_url, null: false
|
||||
t.text :request_template
|
||||
t.text :response_template
|
||||
t.string :auth_type, default: 'none'
|
||||
t.jsonb :auth_config, default: {}
|
||||
t.jsonb :param_schema, default: []
|
||||
t.boolean :enabled, default: true, null: false
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :captain_custom_tools, [:account_id, :slug], unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddNameToWebhooks < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :webhooks, :name, :string, null: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,16 @@
|
||||
class AddUniqueIndexToCompaniesDomain < ActiveRecord::Migration[7.1]
|
||||
def up
|
||||
remove_index :companies, name: 'index_companies_on_domain_and_account_id', if_exists: true
|
||||
|
||||
add_index :companies, [:account_id, :domain],
|
||||
unique: true,
|
||||
name: 'index_companies_on_account_and_domain',
|
||||
where: 'domain IS NOT NULL'
|
||||
end
|
||||
|
||||
def down
|
||||
remove_index :companies, name: 'index_companies_on_account_and_domain', if_exists: true
|
||||
add_index :companies, [:domain, :account_id],
|
||||
name: 'index_companies_on_domain_and_account_id'
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,6 @@
|
||||
class AddIndexToConversationsIdentifier < ActiveRecord::Migration[7.1]
|
||||
disable_ddl_transaction!
|
||||
def change
|
||||
add_index :conversations, [:identifier, :account_id], name: 'index_conversations_on_identifier_and_account_id', algorithm: :concurrently
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddAssigneeAgentBotIdToConversations < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :conversations, :assignee_agent_bot_id, :bigint
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,15 @@
|
||||
class AddTiktokChannel < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
create_table :channel_tiktok do |t|
|
||||
t.integer :account_id, null: false
|
||||
t.string :business_id, null: false
|
||||
t.string :access_token, null: false
|
||||
t.datetime :expires_at, null: false
|
||||
t.string :refresh_token, null: false
|
||||
t.datetime :refresh_token_expires_at, null: false
|
||||
t.timestamps
|
||||
end
|
||||
|
||||
add_index :channel_tiktok, :business_id, unique: true
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,5 @@
|
||||
class AddContactsCountToCompanies < ActiveRecord::Migration[7.1]
|
||||
def change
|
||||
add_column :companies, :contacts_count, :integer, default: 0, null: false
|
||||
end
|
||||
end
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user