1+ CREATE TABLE `custom_redaction_templates ` (
2+ ` id` text PRIMARY KEY NOT NULL ,
3+ ` user_id` text NOT NULL ,
4+ ` name` text NOT NULL ,
5+ ` description` text ,
6+ ` category` text DEFAULT ' Custom' NOT NULL ,
7+ ` patterns` text ,
8+ ` is_shared` integer DEFAULT false NOT NULL ,
9+ ` usage_count` integer DEFAULT 0 NOT NULL ,
10+ ` created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
11+ ` updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
12+ FOREIGN KEY (` user_id` ) REFERENCES ` users` (` id` ) ON UPDATE no action ON DELETE cascade
13+ );
14+ -- > statement-breakpoint
15+ CREATE INDEX `idx_custom_redaction_templates_user_id ` ON ` custom_redaction_templates` (` user_id` );-- > statement-breakpoint
16+ CREATE INDEX `idx_custom_redaction_templates_is_shared ` ON ` custom_redaction_templates` (` is_shared` );-- > statement-breakpoint
17+ CREATE TABLE `document_access_log ` (
18+ ` id` text PRIMARY KEY NOT NULL ,
19+ ` document_id` text NOT NULL ,
20+ ` user_id` text NOT NULL ,
21+ ` access_type` text NOT NULL ,
22+ ` mfa_verified` integer DEFAULT false NOT NULL ,
23+ ` ip_address` text ,
24+ ` user_agent` text ,
25+ ` metadata` text ,
26+ ` created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
27+ FOREIGN KEY (` document_id` ) REFERENCES ` secure_documents` (` id` ) ON UPDATE no action ON DELETE cascade ,
28+ FOREIGN KEY (` user_id` ) REFERENCES ` users` (` id` ) ON UPDATE no action ON DELETE cascade
29+ );
30+ -- > statement-breakpoint
31+ CREATE INDEX `idx_document_access_log_document_id ` ON ` document_access_log` (` document_id` );-- > statement-breakpoint
32+ CREATE INDEX `idx_document_access_log_user_id ` ON ` document_access_log` (` user_id` );-- > statement-breakpoint
33+ CREATE INDEX `idx_document_access_log_access_type ` ON ` document_access_log` (` access_type` );-- > statement-breakpoint
34+ CREATE INDEX `idx_document_access_log_created_at ` ON ` document_access_log` (` created_at` );-- > statement-breakpoint
35+ CREATE TABLE `redaction_history ` (
36+ ` id` text PRIMARY KEY NOT NULL ,
37+ ` source_document_id` text NOT NULL ,
38+ ` result_document_id` text ,
39+ ` user_id` text NOT NULL ,
40+ ` template_id` text ,
41+ ` redaction_count` integer DEFAULT 0 NOT NULL ,
42+ ` redaction_areas` text ,
43+ ` patterns_matched` text ,
44+ ` is_permanent` integer DEFAULT false NOT NULL ,
45+ ` created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
46+ FOREIGN KEY (` source_document_id` ) REFERENCES ` secure_documents` (` id` ) ON UPDATE no action ON DELETE cascade ,
47+ FOREIGN KEY (` result_document_id` ) REFERENCES ` secure_documents` (` id` ) ON UPDATE no action ON DELETE no action,
48+ FOREIGN KEY (` user_id` ) REFERENCES ` users` (` id` ) ON UPDATE no action ON DELETE cascade
49+ );
50+ -- > statement-breakpoint
51+ CREATE INDEX `idx_redaction_history_source_document_id ` ON ` redaction_history` (` source_document_id` );-- > statement-breakpoint
52+ CREATE INDEX `idx_redaction_history_user_id ` ON ` redaction_history` (` user_id` );-- > statement-breakpoint
53+ CREATE INDEX `idx_redaction_history_template_id ` ON ` redaction_history` (` template_id` );-- > statement-breakpoint
54+ CREATE INDEX `idx_redaction_history_created_at ` ON ` redaction_history` (` created_at` );-- > statement-breakpoint
55+ CREATE TABLE `secure_documents ` (
56+ ` id` text PRIMARY KEY NOT NULL ,
57+ ` uploaded_by` text NOT NULL ,
58+ ` original_file_name` text NOT NULL ,
59+ ` file_path` text NOT NULL ,
60+ ` file_size` integer NOT NULL ,
61+ ` mime_type` text NOT NULL ,
62+ ` sha256_hash` text NOT NULL ,
63+ ` status` text DEFAULT ' pending_scan' NOT NULL ,
64+ ` virus_scan_result` text ,
65+ ` requires_mfa` integer DEFAULT false NOT NULL ,
66+ ` access_password_hash` text ,
67+ ` is_encrypted` integer DEFAULT true NOT NULL ,
68+ ` encryption_key_id` text ,
69+ ` expires_at` text ,
70+ ` access_count` integer DEFAULT 0 NOT NULL ,
71+ ` last_accessed_at` text ,
72+ ` created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
73+ ` updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL ,
74+ FOREIGN KEY (` uploaded_by` ) REFERENCES ` users` (` id` ) ON UPDATE no action ON DELETE cascade
75+ );
76+ -- > statement-breakpoint
77+ CREATE INDEX `idx_secure_documents_uploaded_by ` ON ` secure_documents` (` uploaded_by` );-- > statement-breakpoint
78+ CREATE INDEX `idx_secure_documents_status ` ON ` secure_documents` (` status` );-- > statement-breakpoint
79+ CREATE INDEX `idx_secure_documents_sha256 ` ON ` secure_documents` (` sha256_hash` );-- > statement-breakpoint
80+ CREATE INDEX `idx_secure_documents_created_at ` ON ` secure_documents` (` created_at` );-- > statement-breakpoint
81+ CREATE INDEX `idx_secure_documents_expires_at ` ON ` secure_documents` (` expires_at` );-- > statement-breakpoint
82+ CREATE INDEX `idx_agencies_jurisdiction ` ON ` agencies` (` jurisdiction_level` );-- > statement-breakpoint
83+ CREATE INDEX `idx_agencies_state ` ON ` agencies` (` state` );-- > statement-breakpoint
84+ CREATE INDEX `idx_api_keys_user_id ` ON ` api_keys` (` user_id` );-- > statement-breakpoint
85+ CREATE UNIQUE INDEX `idx_api_keys_key_hash ` ON ` api_keys` (` key_hash` );-- > statement-breakpoint
86+ CREATE INDEX `idx_appeals_request_id ` ON ` appeals` (` request_id` );-- > statement-breakpoint
87+ CREATE INDEX `idx_appeals_user_id ` ON ` appeals` (` user_id` );-- > statement-breakpoint
88+ CREATE INDEX `idx_appeals_status ` ON ` appeals` (` status` );-- > statement-breakpoint
89+ CREATE INDEX `idx_audit_logs_user_id ` ON ` audit_logs` (` user_id` );-- > statement-breakpoint
90+ CREATE INDEX `idx_audit_logs_action ` ON ` audit_logs` (` action` );-- > statement-breakpoint
91+ CREATE INDEX `idx_audit_logs_resource_type ` ON ` audit_logs` (` resource_type` );-- > statement-breakpoint
92+ CREATE INDEX `idx_audit_logs_resource_id ` ON ` audit_logs` (` resource_id` );-- > statement-breakpoint
93+ CREATE INDEX `idx_audit_logs_created_at ` ON ` audit_logs` (` created_at` );-- > statement-breakpoint
94+ CREATE INDEX `idx_audit_logs_user_action ` ON ` audit_logs` (` user_id` ,` action` );-- > statement-breakpoint
95+ CREATE INDEX `idx_audit_logs_action_created ` ON ` audit_logs` (` action` ,` created_at` );-- > statement-breakpoint
96+ CREATE INDEX `idx_audit_logs_resource_type_id ` ON ` audit_logs` (` resource_type` ,` resource_id` );-- > statement-breakpoint
97+ CREATE INDEX `idx_comment_votes_comment_id ` ON ` comment_votes` (` comment_id` );-- > statement-breakpoint
98+ CREATE INDEX `idx_comment_votes_user_id ` ON ` comment_votes` (` user_id` );-- > statement-breakpoint
99+ CREATE UNIQUE INDEX `idx_comment_votes_user_comment ` ON ` comment_votes` (` user_id` ,` comment_id` );-- > statement-breakpoint
100+ CREATE INDEX `idx_comments_document_id ` ON ` comments` (` document_id` );-- > statement-breakpoint
101+ CREATE INDEX `idx_comments_user_id ` ON ` comments` (` user_id` );-- > statement-breakpoint
102+ CREATE INDEX `idx_comments_type ` ON ` comments` (` type` );-- > statement-breakpoint
103+ CREATE INDEX `idx_comments_created_at ` ON ` comments` (` created_at` );-- > statement-breakpoint
104+ CREATE INDEX `idx_documents_request_id ` ON ` documents` (` request_id` );-- > statement-breakpoint
105+ CREATE INDEX `idx_documents_agency_id ` ON ` documents` (` agency_id` );-- > statement-breakpoint
106+ CREATE INDEX `idx_documents_uploaded_by ` ON ` documents` (` uploaded_by` );-- > statement-breakpoint
107+ CREATE INDEX `idx_documents_type ` ON ` documents` (` type` );-- > statement-breakpoint
108+ CREATE INDEX `idx_documents_is_public ` ON ` documents` (` is_public` );-- > statement-breakpoint
109+ CREATE INDEX `idx_documents_created_at ` ON ` documents` (` created_at` );-- > statement-breakpoint
110+ CREATE INDEX `idx_foia_requests_user_id ` ON ` foia_requests` (` user_id` );-- > statement-breakpoint
111+ CREATE INDEX `idx_foia_requests_agency_id ` ON ` foia_requests` (` agency_id` );-- > statement-breakpoint
112+ CREATE INDEX `idx_foia_requests_status ` ON ` foia_requests` (` status` );-- > statement-breakpoint
113+ CREATE INDEX `idx_foia_requests_category ` ON ` foia_requests` (` category` );-- > statement-breakpoint
114+ CREATE INDEX `idx_foia_requests_created_at ` ON ` foia_requests` (` created_at` );-- > statement-breakpoint
115+ CREATE INDEX `idx_foia_requests_due_date ` ON ` foia_requests` (` due_date` );-- > statement-breakpoint
116+ CREATE INDEX `idx_foia_requests_is_public ` ON ` foia_requests` (` is_public` );-- > statement-breakpoint
117+ CREATE INDEX `idx_foia_requests_user_status ` ON ` foia_requests` (` user_id` ,` status` );-- > statement-breakpoint
118+ CREATE INDEX `idx_foia_requests_agency_status ` ON ` foia_requests` (` agency_id` ,` status` );-- > statement-breakpoint
119+ CREATE INDEX `idx_foia_requests_status_created ` ON ` foia_requests` (` status` ,` created_at` );-- > statement-breakpoint
120+ CREATE INDEX `idx_knowledge_articles_category ` ON ` knowledge_articles` (` category` );-- > statement-breakpoint
121+ CREATE INDEX `idx_knowledge_articles_state ` ON ` knowledge_articles` (` state` );-- > statement-breakpoint
122+ CREATE INDEX `idx_knowledge_articles_is_published ` ON ` knowledge_articles` (` is_published` );-- > statement-breakpoint
123+ CREATE INDEX `idx_sessions_user_id ` ON ` sessions` (` user_id` );-- > statement-breakpoint
124+ CREATE INDEX `idx_sessions_expires_at ` ON ` sessions` (` expires_at` );-- > statement-breakpoint
125+ CREATE INDEX `idx_sessions_user_expires ` ON ` sessions` (` user_id` ,` expires_at` );-- > statement-breakpoint
126+ CREATE INDEX `idx_use_of_force_stats_agency_id ` ON ` use_of_force_stats` (` agency_id` );-- > statement-breakpoint
127+ CREATE INDEX `idx_use_of_force_stats_year ` ON ` use_of_force_stats` (` year` );-- > statement-breakpoint
128+ CREATE INDEX `idx_use_of_force_stats_agency_year ` ON ` use_of_force_stats` (` agency_id` ,` year` );
0 commit comments