Files
gochat/migrations/000042_add_csat_and_bot_rule_tables.up.sql
T

67 lines
2.8 KiB
SQL

CREATE TABLE IF NOT EXISTS csat_survey_responses (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ,
deleted_at TIMESTAMPTZ,
account_id BIGINT NOT NULL,
conversation_id BIGINT NOT NULL,
contact_id BIGINT,
message_id BIGINT,
assigned_agent_id BIGINT,
rating INTEGER NOT NULL,
feedback_message TEXT,
csat_review_notes TEXT,
review_notes_updated_by_id BIGINT,
review_notes_updated_at TIMESTAMPTZ
);
CREATE UNIQUE INDEX IF NOT EXISTS idx_csat_survey_responses_message_id
ON csat_survey_responses (message_id)
WHERE message_id IS NOT NULL AND deleted_at IS NULL;
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_account_id ON csat_survey_responses (account_id);
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_conversation_id ON csat_survey_responses (conversation_id);
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_contact_id ON csat_survey_responses (contact_id);
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_assigned_agent_id ON csat_survey_responses (assigned_agent_id);
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_review_notes_updated_by_id ON csat_survey_responses (review_notes_updated_by_id);
CREATE INDEX IF NOT EXISTS idx_csat_survey_responses_deleted_at ON csat_survey_responses (deleted_at);
CREATE TABLE IF NOT EXISTS bot_rules (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ,
deleted_at TIMESTAMPTZ,
agent_bot_id BIGINT NOT NULL,
account_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
event_name VARCHAR(100) NOT NULL,
conditions JSONB DEFAULT '[]'::jsonb,
actions JSONB DEFAULT '[]'::jsonb,
status VARCHAR(20) DEFAULT 'active'
);
CREATE INDEX IF NOT EXISTS idx_bot_rules_agent_bot_id ON bot_rules (agent_bot_id);
CREATE INDEX IF NOT EXISTS idx_bot_rules_account_id ON bot_rules (account_id);
CREATE INDEX IF NOT EXISTS idx_bot_rules_event_name ON bot_rules (event_name);
CREATE INDEX IF NOT EXISTS idx_bot_rules_deleted_at ON bot_rules (deleted_at);
CREATE TABLE IF NOT EXISTS bot_trigger_configs (
id BIGSERIAL PRIMARY KEY,
created_at TIMESTAMPTZ,
updated_at TIMESTAMPTZ,
deleted_at TIMESTAMPTZ,
agent_bot_id BIGINT NOT NULL,
account_id BIGINT NOT NULL,
name VARCHAR(255) NOT NULL,
description TEXT,
event_name VARCHAR(100) NOT NULL,
conditions JSONB DEFAULT '[]'::jsonb,
query_operator VARCHAR(10) DEFAULT 'and',
active BOOLEAN DEFAULT true
);
CREATE INDEX IF NOT EXISTS idx_bot_trigger_configs_agent_bot_id ON bot_trigger_configs (agent_bot_id);
CREATE INDEX IF NOT EXISTS idx_bot_trigger_configs_account_id ON bot_trigger_configs (account_id);
CREATE INDEX IF NOT EXISTS idx_bot_trigger_configs_event_name ON bot_trigger_configs (event_name);
CREATE INDEX IF NOT EXISTS idx_bot_trigger_configs_deleted_at ON bot_trigger_configs (deleted_at);