- Add PostgreSQL persistence for dashboards module (was returning empty vec![])
- Tables: dashboards, dashboard_widgets, dashboard_data_sources, dashboard_filters,
dashboard_widget_data_sources, conversational_queries
- Full CRUD operations with spawn_blocking pattern
- Add PostgreSQL persistence for legal module (was using in-memory HashMap)
- Tables: legal_documents, legal_document_versions, cookie_consents, consent_history,
legal_acceptances, data_deletion_requests, data_export_requests
- GDPR-compliant consent tracking and document management
- Add PostgreSQL persistence for compliance module (was returning empty results)
- Tables: compliance_checks, compliance_issues, compliance_audit_log, compliance_evidence,
compliance_risk_assessments, compliance_risks, compliance_training_records,
compliance_access_reviews
- Support for GDPR, SOC2, ISO27001, HIPAA, PCI-DSS frameworks
- Add migration files for all new tables
- Update schema.rs with new table definitions and joinables
- Register new routes in main.rs
- Add recursion_limit = 512 for macro expansion
113 lines
4.2 KiB
SQL
113 lines
4.2 KiB
SQL
CREATE TABLE support_tickets (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
org_id UUID NOT NULL,
|
|
bot_id UUID NOT NULL,
|
|
ticket_number VARCHAR(50) NOT NULL,
|
|
subject VARCHAR(500) NOT NULL,
|
|
description TEXT,
|
|
status VARCHAR(50) NOT NULL DEFAULT 'open',
|
|
priority VARCHAR(50) NOT NULL DEFAULT 'medium',
|
|
category VARCHAR(100),
|
|
source VARCHAR(50) NOT NULL DEFAULT 'web',
|
|
requester_id UUID,
|
|
requester_email VARCHAR(255),
|
|
requester_name VARCHAR(255),
|
|
assignee_id UUID,
|
|
team_id UUID,
|
|
due_date TIMESTAMPTZ,
|
|
first_response_at TIMESTAMPTZ,
|
|
resolved_at TIMESTAMPTZ,
|
|
closed_at TIMESTAMPTZ,
|
|
satisfaction_rating INTEGER,
|
|
tags TEXT[] NOT NULL DEFAULT '{}',
|
|
custom_fields JSONB NOT NULL DEFAULT '{}',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE ticket_comments (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
ticket_id UUID NOT NULL REFERENCES support_tickets(id) ON DELETE CASCADE,
|
|
author_id UUID,
|
|
author_name VARCHAR(255),
|
|
author_email VARCHAR(255),
|
|
content TEXT NOT NULL,
|
|
is_internal BOOLEAN NOT NULL DEFAULT FALSE,
|
|
attachments JSONB NOT NULL DEFAULT '[]',
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE ticket_sla_policies (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
org_id UUID NOT NULL,
|
|
bot_id UUID NOT NULL,
|
|
name VARCHAR(255) NOT NULL,
|
|
priority VARCHAR(50) NOT NULL,
|
|
first_response_hours INTEGER NOT NULL,
|
|
resolution_hours INTEGER NOT NULL,
|
|
business_hours_only BOOLEAN NOT NULL DEFAULT TRUE,
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE ticket_canned_responses (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
org_id UUID NOT NULL,
|
|
bot_id UUID NOT NULL,
|
|
title VARCHAR(255) NOT NULL,
|
|
content TEXT NOT NULL,
|
|
category VARCHAR(100),
|
|
shortcut VARCHAR(50),
|
|
created_by UUID,
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
|
|
updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE ticket_categories (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
org_id UUID NOT NULL,
|
|
bot_id UUID NOT NULL,
|
|
name VARCHAR(255) NOT NULL,
|
|
description TEXT,
|
|
parent_id UUID REFERENCES ticket_categories(id) ON DELETE SET NULL,
|
|
color VARCHAR(20),
|
|
icon VARCHAR(50),
|
|
sort_order INTEGER NOT NULL DEFAULT 0,
|
|
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE TABLE ticket_tags (
|
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
|
org_id UUID NOT NULL,
|
|
bot_id UUID NOT NULL,
|
|
name VARCHAR(100) NOT NULL,
|
|
color VARCHAR(20),
|
|
created_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
|
|
);
|
|
|
|
CREATE INDEX idx_support_tickets_org_bot ON support_tickets(org_id, bot_id);
|
|
CREATE INDEX idx_support_tickets_status ON support_tickets(status);
|
|
CREATE INDEX idx_support_tickets_priority ON support_tickets(priority);
|
|
CREATE INDEX idx_support_tickets_assignee ON support_tickets(assignee_id);
|
|
CREATE INDEX idx_support_tickets_requester ON support_tickets(requester_id);
|
|
CREATE INDEX idx_support_tickets_created ON support_tickets(created_at DESC);
|
|
CREATE INDEX idx_support_tickets_number ON support_tickets(ticket_number);
|
|
CREATE UNIQUE INDEX idx_support_tickets_org_number ON support_tickets(org_id, ticket_number);
|
|
|
|
CREATE INDEX idx_ticket_comments_ticket ON ticket_comments(ticket_id);
|
|
CREATE INDEX idx_ticket_comments_created ON ticket_comments(created_at);
|
|
|
|
CREATE INDEX idx_ticket_sla_org_bot ON ticket_sla_policies(org_id, bot_id);
|
|
CREATE INDEX idx_ticket_sla_priority ON ticket_sla_policies(priority);
|
|
|
|
CREATE INDEX idx_ticket_canned_org_bot ON ticket_canned_responses(org_id, bot_id);
|
|
CREATE INDEX idx_ticket_canned_shortcut ON ticket_canned_responses(shortcut);
|
|
|
|
CREATE INDEX idx_ticket_categories_org_bot ON ticket_categories(org_id, bot_id);
|
|
CREATE INDEX idx_ticket_categories_parent ON ticket_categories(parent_id);
|
|
|
|
CREATE INDEX idx_ticket_tags_org_bot ON ticket_tags(org_id, bot_id);
|
|
CREATE UNIQUE INDEX idx_ticket_tags_org_name ON ticket_tags(org_id, bot_id, name);
|