-- Create support_members table
CREATE TABLE support_members (
tenant_id UUID,
member_id UUID,
role VARCHAR(50) NOT NULL,
PRIMARY KEY (tenant_id, member_id),
FOREIGN KEY (tenant_id, member_id) REFERENCES users.tenant_users(tenant_id, user_id)
);
-- Create customers table
CREATE TABLE customers (
tenant_id UUID,
customer_id UUID DEFAULT gen_random_uuid(),
name VARCHAR(100) NOT NULL,
contact_email VARCHAR(100) NOT NULL,
contact_phone VARCHAR(20),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (tenant_id, customer_id),
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);
-- Create customer_employees table
CREATE TABLE customer_employees (
tenant_id UUID,
employee_id UUID,
customer_id UUID,
department VARCHAR(100),
PRIMARY KEY (tenant_id, employee_id),
FOREIGN KEY (tenant_id, customer_id) REFERENCES customers(tenant_id, customer_id),
FOREIGN KEY (tenant_id, employee_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create support_tickets table
CREATE TABLE support_tickets (
tenant_id UUID,
ticket_id UUID DEFAULT gen_random_uuid(),
customer_id UUID,
title VARCHAR(255) NOT NULL,
description TEXT NOT NULL,
status VARCHAR(50) DEFAULT 'open',
priority VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, ticket_id),
FOREIGN KEY (tenant_id, customer_id) REFERENCES customers(tenant_id, customer_id)
);
-- Create ticket_comments table
CREATE TABLE ticket_comments (
tenant_id UUID,
comment_id UUID DEFAULT gen_random_uuid(),
ticket_id UUID,
user_id UUID,
comment_text TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, comment_id),
FOREIGN KEY (tenant_id, ticket_id) REFERENCES support_tickets(tenant_id, ticket_id),
FOREIGN KEY (tenant_id, user_id) REFERENCES tenant_users(tenant_id, user_id)
);
-- Create knowledge_base table
CREATE TABLE knowledge_base (
article_id UUID DEFAULT gen_random_uuid(),
tenant_id UUID,
support_member_id UUID,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, article_id),
FOREIGN KEY (tenant_id, support_member_id) REFERENCES support_members(tenant_id, member_id)
);