CREATE TABLE `access_requests` ( `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, `project_id` integer NOT NULL, `owner_id` integer NOT NULL, `task_id` integer, `session_id` integer, `agent_id` integer, `agent_name` text, `catalog_id` text, `host` text, `service_key` text NOT NULL, `purpose` text NOT NULL, `mode` text DEFAULT 'read' NOT NULL, `status` text DEFAULT 'open' NOT NULL, `reason` text, `connection_id` integer, `repeats` integer DEFAULT 0 NOT NULL, `decided_by` integer, `decided_at` integer, `created_at` integer DEFAULT (cast(unixepoch('subsec') * 1000 as integer)) NOT NULL, `updated_at` integer DEFAULT (cast(unixepoch('subsec') * 1000 as integer)) NOT NULL, FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade, FOREIGN KEY (`owner_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE cascade, FOREIGN KEY (`task_id`) REFERENCES `tasks`(`id`) ON UPDATE no action ON DELETE set null, FOREIGN KEY (`session_id`) REFERENCES `sessions`(`id`) ON UPDATE no action ON DELETE set null, FOREIGN KEY (`agent_id`) REFERENCES `agents`(`id`) ON UPDATE no action ON DELETE set null, FOREIGN KEY (`connection_id`) REFERENCES `connections`(`id`) ON UPDATE no action ON DELETE set null, FOREIGN KEY (`decided_by`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null ); --> statement-breakpoint CREATE INDEX `access_requests_project_service` ON `access_requests` (`project_id`,`service_key`,`status`);--> statement-breakpoint CREATE INDEX `access_requests_owner` ON `access_requests` (`owner_id`,`status`);