pkgs/db/drizzle/20260526232651_woozy_shinko_yamashiro/migration.sql (view raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
CREATE TABLE `tickets` ( `id` integer PRIMARY KEY AUTOINCREMENT, `anonymous_id` text NOT NULL, `status` text NOT NULL, `channel_id` text NOT NULL, `close_reason` text, `private_notes` text, `opened_at` integer NOT NULL, `closed_at` integer, `opened_by` integer NOT NULL, `open_reason` text, `subject` integer NOT NULL, `claimed_by` integer, `claimed_at` integer, `thanked_at` integer, `warned_at` integer, `last_message_at` integer, `has_moderator_message` integer, `has_author_message` integer, CONSTRAINT `fk_tickets_opened_by_actors_id_fk` FOREIGN KEY (`opened_by`) REFERENCES `actors`(`id`), CONSTRAINT `fk_tickets_subject_actors_id_fk` FOREIGN KEY (`subject`) REFERENCES `actors`(`id`), CONSTRAINT `fk_tickets_claimed_by_actors_id_fk` FOREIGN KEY (`claimed_by`) REFERENCES `actors`(`id`) ); --> statement-breakpoint CREATE TABLE `ticket_attachments` ( `id` integer PRIMARY KEY AUTOINCREMENT, `public_id` text NOT NULL, `message_id` integer, `ticket_id` integer NOT NULL, `actor_id` integer NOT NULL, `file_name` text NOT NULL, `file_type` text NOT NULL, `file_size` integer NOT NULL, CONSTRAINT `fk_ticket_attachments_message_id_ticket_messages_id_fk` FOREIGN KEY (`message_id`) REFERENCES `ticket_messages`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_ticket_attachments_ticket_id_tickets_id_fk` FOREIGN KEY (`ticket_id`) REFERENCES `tickets`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_ticket_attachments_actor_id_actors_id_fk` FOREIGN KEY (`actor_id`) REFERENCES `actors`(`id`) ON DELETE CASCADE ); --> statement-breakpoint CREATE TABLE `ticket_messages` ( `id` integer PRIMARY KEY AUTOINCREMENT, `public_id` text NOT NULL, `message_id` text, `ticket_id` integer NOT NULL, `actor_id` integer NOT NULL, `content` text NOT NULL, `actor_role` text NOT NULL, `created_at` integer NOT NULL, `edited_at` integer, `deleted_at` integer, CONSTRAINT `fk_ticket_messages_ticket_id_tickets_id_fk` FOREIGN KEY (`ticket_id`) REFERENCES `tickets`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_ticket_messages_actor_id_actors_id_fk` FOREIGN KEY (`actor_id`) REFERENCES `actors`(`id`) ON DELETE CASCADE ); --> statement-breakpoint CREATE TABLE `ticket_participants` ( `id` integer PRIMARY KEY AUTOINCREMENT, `ticket_id` integer NOT NULL, `actor_id` integer NOT NULL, `role` text NOT NULL, `reason` text, `created_at` integer NOT NULL, CONSTRAINT `fk_ticket_participants_ticket_id_tickets_id_fk` FOREIGN KEY (`ticket_id`) REFERENCES `tickets`(`id`) ON DELETE CASCADE, CONSTRAINT `fk_ticket_participants_actor_id_actors_id_fk` FOREIGN KEY (`actor_id`) REFERENCES `actors`(`id`) ON DELETE CASCADE ); |