Merge remote-tracking branch 'origin/captain/pdf_support_fe' into captain/pdf_support

This commit is contained in:
Tanmay Sharma
2025-08-27 14:47:28 +07:00
993 changed files with 28669 additions and 8431 deletions
@@ -1,5 +1,5 @@
class AddTemplateParamsToCampaigns < ActiveRecord::Migration[7.1]
def change
add_column :campaigns, :template_params, :jsonb, default: {}, null: false
add_column :campaigns, :template_params, :jsonb
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
@@ -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,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
+70 -1
View File
@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
ActiveRecord::Schema[7.1].define(version: 2025_08_22_061042) do
# These extensions should be enabled to support this database
enable_extension "pg_stat_statements"
enable_extension "pg_trgm"
@@ -39,8 +39,10 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.integer "availability", default: 0, null: false
t.boolean "auto_offline", default: true, null: false
t.bigint "custom_role_id"
t.bigint "agent_capacity_policy_id"
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 ["agent_capacity_policy_id"], name: "index_account_users_on_agent_capacity_policy_id"
t.index ["custom_role_id"], name: "index_account_users_on_custom_role_id"
t.index ["user_id"], name: "index_account_users_on_user_id"
end
@@ -120,6 +122,16 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.index ["account_id"], name: "index_agent_bots_on_account_id"
end
create_table "agent_capacity_policies", force: :cascade do |t|
t.bigint "account_id", null: false
t.string "name", limit: 255, null: false
t.text "description"
t.jsonb "exclusion_rules", default: {}, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id"], name: "index_agent_capacity_policies_on_account_id"
end
create_table "applied_slas", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "sla_policy_id", null: false
@@ -169,6 +181,22 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.index ["views"], name: "index_articles_on_views"
end
create_table "assignment_policies", force: :cascade do |t|
t.bigint "account_id", null: false
t.string "name", limit: 255, null: false
t.text "description"
t.integer "assignment_order", default: 0, null: false
t.integer "conversation_priority", default: 0, null: false
t.integer "fair_distribution_limit", default: 100, null: false
t.integer "fair_distribution_window", default: 3600, null: false
t.boolean "enabled", default: true, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "name"], name: "index_assignment_policies_on_account_id_and_name", unique: true
t.index ["account_id"], name: "index_assignment_policies_on_account_id"
t.index ["enabled"], name: "index_assignment_policies_on_enabled"
end
create_table "attachments", id: :serial, force: :cascade do |t|
t.integer "file_type", default: 0
t.string "external_url"
@@ -446,6 +474,8 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.integer "medium", default: 0
t.string "messaging_service_sid"
t.string "api_key_sid"
t.jsonb "content_templates", default: {}
t.datetime "content_templates_last_updated"
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
@@ -728,6 +758,26 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.datetime "updated_at", null: false
end
create_table "inbox_assignment_policies", force: :cascade do |t|
t.bigint "inbox_id", null: false
t.bigint "assignment_policy_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["assignment_policy_id"], name: "index_inbox_assignment_policies_on_assignment_policy_id"
t.index ["inbox_id"], name: "index_inbox_assignment_policies_on_inbox_id", unique: true
end
create_table "inbox_capacity_limits", force: :cascade do |t|
t.bigint "agent_capacity_policy_id", null: false
t.bigint "inbox_id", null: false
t.integer "conversation_limit", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["agent_capacity_policy_id", "inbox_id"], name: "idx_on_agent_capacity_policy_id_inbox_id_71c7ec4caf", unique: true
t.index ["agent_capacity_policy_id"], name: "index_inbox_capacity_limits_on_agent_capacity_policy_id"
t.index ["inbox_id"], name: "index_inbox_capacity_limits_on_inbox_id"
end
create_table "inbox_members", id: :serial, force: :cascade do |t|
t.integer "user_id", null: false
t.integer "inbox_id", null: false
@@ -800,6 +850,24 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.index ["title", "account_id"], name: "index_labels_on_title_and_account_id", unique: true
end
create_table "leaves", force: :cascade do |t|
t.bigint "account_id", null: false
t.bigint "user_id", null: false
t.date "start_date", null: false
t.date "end_date", null: false
t.integer "leave_type", default: 0, null: false
t.integer "status", default: 0, null: false
t.text "reason"
t.bigint "approved_by_id"
t.datetime "approved_at"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["account_id", "status"], name: "index_leaves_on_account_id_and_status"
t.index ["account_id"], name: "index_leaves_on_account_id"
t.index ["approved_by_id"], name: "index_leaves_on_approved_by_id"
t.index ["user_id"], name: "index_leaves_on_user_id"
end
create_table "macros", force: :cascade do |t|
t.bigint "account_id", null: false
t.string "name", null: false
@@ -909,6 +977,7 @@ ActiveRecord::Schema[7.1].define(version: 2025_07_22_152516) do
t.index ["last_activity_at"], name: "index_notifications_on_last_activity_at"
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", "account_id", "snoozed_until", "read_at"], name: "idx_notifications_performance"
t.index ["user_id"], name: "index_notifications_on_user_id"
end