-- Create Departments Table
CREATE TABLE departments (
department_id UUID DEFAULT gen_random_uuid(),
tenant_id UUID,
department_name VARCHAR(100) NOT NULL,
PRIMARY KEY (tenant_id, department_id),
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);
-- Create Revenue Table
CREATE TABLE revenue (
tenant_id UUID,
revenue_id UUID DEFAULT gen_random_uuid(),
department_id UUID,
amount NUMERIC(15, 2) NOT NULL,
date TIMESTAMP NOT NULL,
description TEXT,
PRIMARY KEY (tenant_id, revenue_id),
FOREIGN KEY (tenant_id, department_id) REFERENCES departments(tenant_id, department_id)
);
-- Create Expenses Table
CREATE TABLE expenses (
tenant_id UUID,
expense_id UUID DEFAULT gen_random_uuid(),
department_id UUID,
amount NUMERIC(15, 2) NOT NULL,
date TIMESTAMP NOT NULL,
description TEXT,
PRIMARY KEY (tenant_id, expense_id),
FOREIGN KEY (tenant_id, department_id) REFERENCES departments(tenant_id, department_id)
);
-- Create Invoices Table
CREATE TABLE invoices (
tenant_id UUID,
invoice_id UUID DEFAULT gen_random_uuid(),
department_id UUID,
file_path TEXT NOT NULL,
amount NUMERIC(15, 2) NOT NULL,
date TIMESTAMP NOT NULL,
description TEXT,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, invoice_id),
FOREIGN KEY (tenant_id, department_id) REFERENCES departments(tenant_id, department_id)
);
-- Create Receipts Table
CREATE TABLE receipts (
tenant_id UUID,
receipt_id UUID DEFAULT gen_random_uuid(),
department_id UUID,
file_path TEXT NOT NULL,
amount NUMERIC(15, 2) NOT NULL,
date TIMESTAMP NOT NULL,
description TEXT,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, receipt_id),
FOREIGN KEY (tenant_id, department_id) REFERENCES departments(tenant_id, department_id)
);
-- Create Financial Reports Table
CREATE TABLE financial_reports (
tenant_id UUID,
report_id UUID DEFAULT gen_random_uuid(),
report_type VARCHAR(50), -- e.g., "monthly", "quarterly", "annual"
generated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
data JSONB,
vector_embedding VECTOR(768), -- Adjust the dimensions as needed
PRIMARY KEY (tenant_id, report_id),
FOREIGN KEY (tenant_id) REFERENCES tenants(id)
);