feat: Add migration files for assignment v2 (#12147)

Co-authored-by: Pranav <pranav@chatwoot.com>
This commit is contained in:
Tanmay Deep Sharma
2025-08-12 10:14:38 +05:30
committed by GitHub
parent 693309202e
commit 4df58501e3
8 changed files with 173 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View 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