CREATE TABLE IF NOT EXISTS `support_tickets` (
  `id` text PRIMARY KEY NOT NULL,
  `customer_id` text NOT NULL,
  `assignee_id` text,
  `subject` text NOT NULL,
  `category` text NOT NULL,
  `priority` text NOT NULL,
  `status` text NOT NULL,
  `created_at` integer NOT NULL,
  `updated_at` integer NOT NULL,
  `deleted_at` integer,
  FOREIGN KEY (`customer_id`) REFERENCES `users`(`id`),
  FOREIGN KEY (`assignee_id`) REFERENCES `users`(`id`)
);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS `idx_tickets_status_priority` ON `support_tickets` (`status`,`priority`);
--> statement-breakpoint
CREATE INDEX IF NOT EXISTS `idx_tickets_customer_status` ON `support_tickets` (`customer_id`,`status`) WHERE `deleted_at` IS NULL;
--> statement-breakpoint
PRAGMA optimize;
