diff --git a/app/models/account_user.rb b/app/models/account_user.rb index d559ab5b4..bbcb0e010 100644 --- a/app/models/account_user.rb +++ b/app/models/account_user.rb @@ -2,24 +2,26 @@ # # Table name: account_users # -# id :bigint not null, primary key -# active_at :datetime -# auto_offline :boolean default(TRUE), not null -# availability :integer default("online"), not null -# role :integer default("agent") -# created_at :datetime not null -# updated_at :datetime not null -# account_id :bigint -# custom_role_id :bigint -# inviter_id :bigint -# user_id :bigint +# id :bigint not null, primary key +# active_at :datetime +# auto_offline :boolean default(TRUE), not null +# availability :integer default("online"), not null +# role :integer default("agent") +# created_at :datetime not null +# updated_at :datetime not null +# account_id :bigint +# agent_capacity_policy_id :bigint +# custom_role_id :bigint +# inviter_id :bigint +# user_id :bigint # # Indexes # -# index_account_users_on_account_id (account_id) -# index_account_users_on_custom_role_id (custom_role_id) -# index_account_users_on_user_id (user_id) -# uniq_user_id_per_account_id (account_id,user_id) UNIQUE +# index_account_users_on_account_id (account_id) +# index_account_users_on_agent_capacity_policy_id (agent_capacity_policy_id) +# index_account_users_on_custom_role_id (custom_role_id) +# index_account_users_on_user_id (user_id) +# uniq_user_id_per_account_id (account_id,user_id) UNIQUE # class AccountUser < ApplicationRecord diff --git a/db/migrate/20250806140000_create_assignment_policies.rb b/db/migrate/20250806140000_create_assignment_policies.rb new file mode 100644 index 000000000..c02e3d6de --- /dev/null +++ b/db/migrate/20250806140000_create_assignment_policies.rb @@ -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 diff --git a/db/migrate/20250806140001_create_inbox_assignment_policies.rb b/db/migrate/20250806140001_create_inbox_assignment_policies.rb new file mode 100644 index 000000000..37fd6e37e --- /dev/null +++ b/db/migrate/20250806140001_create_inbox_assignment_policies.rb @@ -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 diff --git a/db/migrate/20250806140002_create_agent_capacity_policies.rb b/db/migrate/20250806140002_create_agent_capacity_policies.rb new file mode 100644 index 000000000..4fdeabc92 --- /dev/null +++ b/db/migrate/20250806140002_create_agent_capacity_policies.rb @@ -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 diff --git a/db/migrate/20250806140003_create_inbox_capacity_limits.rb b/db/migrate/20250806140003_create_inbox_capacity_limits.rb new file mode 100644 index 000000000..c107ce182 --- /dev/null +++ b/db/migrate/20250806140003_create_inbox_capacity_limits.rb @@ -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 diff --git a/db/migrate/20250806140004_add_agent_capacity_policy_to_account_users.rb b/db/migrate/20250806140004_add_agent_capacity_policy_to_account_users.rb new file mode 100644 index 000000000..53bc8e8f9 --- /dev/null +++ b/db/migrate/20250806140004_add_agent_capacity_policy_to_account_users.rb @@ -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 diff --git a/db/migrate/20250806140005_create_leaves.rb b/db/migrate/20250806140005_create_leaves.rb new file mode 100644 index 000000000..982ec1181 --- /dev/null +++ b/db/migrate/20250806140005_create_leaves.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 6391e3fcf..7f44c373c 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -39,8 +39,10 @@ ActiveRecord::Schema[7.1].define(version: 2025_08_08_123008) 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_08_08_123008) 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_08_08_123008) 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" @@ -728,6 +756,26 @@ ActiveRecord::Schema[7.1].define(version: 2025_08_08_123008) 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 +848,24 @@ ActiveRecord::Schema[7.1].define(version: 2025_08_08_123008) 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