db: add utils & generate migration
@@ -1,5 +1,11 @@
import { defineConfig } from "drizzle-kit"; -import config from "@stealth-developers/config"; + +const config = { + db: { + url: process.env.DATABASE_URL!, + auth: process.env.DATABASE_AUTH!, + }, +}; export default defineConfig({ out: "./drizzle",
@@ -1,22 +0,0 @@
-CREATE TABLE `actors` ( - `id` integer PRIMARY KEY AUTOINCREMENT, - `discord_id` text UNIQUE, - `display_name` text, - `username` text, - `avatar` text, - `created_at` integer NOT NULL, - `updated_at` integer NOT NULL, - `deleted_at` integer -); ---> statement-breakpoint -CREATE TABLE `sessions` ( - `id` text PRIMARY KEY, - `user_id` integer NOT NULL, - `access_token` text NOT NULL, - `refresh_token` text NOT NULL, - `expires_at` integer NOT NULL, - `created_at` integer NOT NULL, - `scope` text, - `token_type` text, - CONSTRAINT `fk_sessions_user_id_actors_id_fk` FOREIGN KEY (`user_id`) REFERENCES `actors`(`id`) -);
@@ -1,209 +0,0 @@
-{ - "version": "7", - "dialect": "sqlite", - "id": "0771a4dc-9b9f-4342-b6cc-7368e6e6ac93", - "prevIds": ["00000000-0000-0000-0000-000000000000"], - "ddl": [ - { - "name": "actors", - "entityType": "tables" - }, - { - "name": "sessions", - "entityType": "tables" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "discord_id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "display_name", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "username", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "avatar", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "updated_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "user_id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "access_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "refresh_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "expires_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "scope", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "token_type", - "entityType": "columns", - "table": "sessions" - }, - { - "columns": ["user_id"], - "tableTo": "actors", - "columnsTo": ["id"], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_sessions_user_id_actors_id_fk", - "entityType": "fks", - "table": "sessions" - }, - { - "columns": ["id"], - "nameExplicit": false, - "name": "actors_pk", - "table": "actors", - "entityType": "pks" - }, - { - "columns": ["id"], - "nameExplicit": false, - "name": "sessions_pk", - "table": "sessions", - "entityType": "pks" - }, - { - "columns": ["discord_id"], - "nameExplicit": false, - "name": "actors_discord_id_unique", - "entityType": "uniques", - "table": "actors" - } - ], - "renames": [] -}
@@ -1,1 +0,0 @@
-ALTER TABLE `actors` ADD `moderator` integer;
@@ -1,231 +0,0 @@
-{ - "version": "7", - "dialect": "sqlite", - "id": "aefd1f03-d714-480c-9628-6877616b4425", - "prevIds": [ - "0771a4dc-9b9f-4342-b6cc-7368e6e6ac93" - ], - "ddl": [ - { - "name": "actors", - "entityType": "tables" - }, - { - "name": "sessions", - "entityType": "tables" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "discord_id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "display_name", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "username", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "avatar", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "moderator", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "updated_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "user_id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "access_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "refresh_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "scope", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "token_type", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "expires_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "sessions" - }, - { - "columns": [ - "user_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_sessions_user_id_actors_id_fk", - "entityType": "fks", - "table": "sessions" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "actors_pk", - "table": "actors", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "sessions_pk", - "table": "sessions", - "entityType": "pks" - }, - { - "columns": [ - "discord_id" - ], - "nameExplicit": false, - "name": "actors_discord_id_unique", - "entityType": "uniques", - "table": "actors" - } - ], - "renames": [] -}
@@ -1,63 +0,0 @@
-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 -);
@@ -1,853 +0,0 @@
-{ - "version": "7", - "dialect": "sqlite", - "id": "627c7c0b-ac0a-4373-aee3-02e637e05ee6", - "prevIds": [ - "aefd1f03-d714-480c-9628-6877616b4425" - ], - "ddl": [ - { - "name": "actors", - "entityType": "tables" - }, - { - "name": "sessions", - "entityType": "tables" - }, - { - "name": "tickets", - "entityType": "tables" - }, - { - "name": "ticket_attachments", - "entityType": "tables" - }, - { - "name": "ticket_messages", - "entityType": "tables" - }, - { - "name": "ticket_participants", - "entityType": "tables" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "discord_id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "display_name", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "username", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "avatar", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "moderator", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "updated_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "user_id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "access_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "refresh_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "scope", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "token_type", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "expires_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "anonymous_id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "status", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "channel_id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "close_reason", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "private_notes", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "opened_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "closed_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "opened_by", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "open_reason", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "subject", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "claimed_by", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "claimed_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "thanked_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "warned_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "last_message_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "has_moderator_message", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "has_author_message", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "public_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "message_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_name", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_type", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_size", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "public_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "message_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "content", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_role", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "edited_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "role", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "reason", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "columns": [ - "user_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_sessions_user_id_actors_id_fk", - "entityType": "fks", - "table": "sessions" - }, - { - "columns": [ - "opened_by" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_opened_by_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "subject" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_subject_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "claimed_by" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_claimed_by_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "message_id" - ], - "tableTo": "ticket_messages", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_message_id_ticket_messages_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_messages_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_messages" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_messages_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_messages" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_participants_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_participants" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_participants_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_participants" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "actors_pk", - "table": "actors", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "sessions_pk", - "table": "sessions", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "tickets_pk", - "table": "tickets", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_attachments_pk", - "table": "ticket_attachments", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_messages_pk", - "table": "ticket_messages", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_participants_pk", - "table": "ticket_participants", - "entityType": "pks" - }, - { - "columns": [ - "discord_id" - ], - "nameExplicit": false, - "name": "actors_discord_id_unique", - "entityType": "uniques", - "table": "actors" - } - ], - "renames": [] -}
@@ -1,9 +0,0 @@
-CREATE INDEX `ticket_attachments_ticket_idx` ON `ticket_attachments` (`ticket_id`);--> statement-breakpoint -CREATE INDEX `ticket_attachments_actor_idx` ON `ticket_attachments` (`actor_id`);--> statement-breakpoint -CREATE INDEX `ticket_attachments_public_id_idx` ON `ticket_attachments` (`public_id`);--> statement-breakpoint -CREATE INDEX `ticket_messages_ticket_idx` ON `ticket_messages` (`ticket_id`);--> statement-breakpoint -CREATE INDEX `ticket_messages_actor_idx` ON `ticket_messages` (`actor_id`);--> statement-breakpoint -CREATE INDEX `ticket_messages_public_id_idx` ON `ticket_messages` (`public_id`);--> statement-breakpoint -CREATE INDEX `ticket_participants_ticket_idx` ON `ticket_participants` (`ticket_id`);--> statement-breakpoint -CREATE INDEX `ticket_participants_actor_idx` ON `ticket_participants` (`actor_id`);--> statement-breakpoint -CREATE INDEX `ticket_participants_role_idx` ON `ticket_participants` (`role`);
@@ -1,979 +0,0 @@
-{ - "version": "7", - "dialect": "sqlite", - "id": "f1bd9a2e-f82a-4938-9bf2-2bf4ef3c7c61", - "prevIds": [ - "627c7c0b-ac0a-4373-aee3-02e637e05ee6" - ], - "ddl": [ - { - "name": "actors", - "entityType": "tables" - }, - { - "name": "sessions", - "entityType": "tables" - }, - { - "name": "tickets", - "entityType": "tables" - }, - { - "name": "ticket_attachments", - "entityType": "tables" - }, - { - "name": "ticket_messages", - "entityType": "tables" - }, - { - "name": "ticket_participants", - "entityType": "tables" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "discord_id", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "display_name", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "username", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "avatar", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "moderator", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "updated_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "actors" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "user_id", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "access_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "refresh_token", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "scope", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "token_type", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "expires_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "sessions" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "anonymous_id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "status", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "channel_id", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "close_reason", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "private_notes", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "opened_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "closed_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "opened_by", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "open_reason", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "subject", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "claimed_by", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "claimed_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "thanked_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "warned_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "last_message_at", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "has_moderator_message", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "has_author_message", - "entityType": "columns", - "table": "tickets" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "public_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "message_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_name", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_type", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "file_size", - "entityType": "columns", - "table": "ticket_attachments" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "public_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "message_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "content", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_role", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "edited_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "deleted_at", - "entityType": "columns", - "table": "ticket_messages" - }, - { - "type": "integer", - "notNull": false, - "autoincrement": true, - "default": null, - "generated": null, - "name": "id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "ticket_id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "actor_id", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "text", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "role", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "text", - "notNull": false, - "autoincrement": false, - "default": null, - "generated": null, - "name": "reason", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "type": "integer", - "notNull": true, - "autoincrement": false, - "default": null, - "generated": null, - "name": "created_at", - "entityType": "columns", - "table": "ticket_participants" - }, - { - "columns": [ - "user_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_sessions_user_id_actors_id_fk", - "entityType": "fks", - "table": "sessions" - }, - { - "columns": [ - "opened_by" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_opened_by_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "subject" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_subject_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "claimed_by" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", - "nameExplicit": false, - "name": "fk_tickets_claimed_by_actors_id_fk", - "entityType": "fks", - "table": "tickets" - }, - { - "columns": [ - "message_id" - ], - "tableTo": "ticket_messages", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_message_id_ticket_messages_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_attachments_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_attachments" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_messages_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_messages" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_messages_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_messages" - }, - { - "columns": [ - "ticket_id" - ], - "tableTo": "tickets", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_participants_ticket_id_tickets_id_fk", - "entityType": "fks", - "table": "ticket_participants" - }, - { - "columns": [ - "actor_id" - ], - "tableTo": "actors", - "columnsTo": [ - "id" - ], - "onUpdate": "NO ACTION", - "onDelete": "CASCADE", - "nameExplicit": false, - "name": "fk_ticket_participants_actor_id_actors_id_fk", - "entityType": "fks", - "table": "ticket_participants" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "actors_pk", - "table": "actors", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "sessions_pk", - "table": "sessions", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "tickets_pk", - "table": "tickets", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_attachments_pk", - "table": "ticket_attachments", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_messages_pk", - "table": "ticket_messages", - "entityType": "pks" - }, - { - "columns": [ - "id" - ], - "nameExplicit": false, - "name": "ticket_participants_pk", - "table": "ticket_participants", - "entityType": "pks" - }, - { - "columns": [ - { - "value": "ticket_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_attachments_ticket_idx", - "entityType": "indexes", - "table": "ticket_attachments" - }, - { - "columns": [ - { - "value": "actor_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_attachments_actor_idx", - "entityType": "indexes", - "table": "ticket_attachments" - }, - { - "columns": [ - { - "value": "public_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_attachments_public_id_idx", - "entityType": "indexes", - "table": "ticket_attachments" - }, - { - "columns": [ - { - "value": "ticket_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_messages_ticket_idx", - "entityType": "indexes", - "table": "ticket_messages" - }, - { - "columns": [ - { - "value": "actor_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_messages_actor_idx", - "entityType": "indexes", - "table": "ticket_messages" - }, - { - "columns": [ - { - "value": "public_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_messages_public_id_idx", - "entityType": "indexes", - "table": "ticket_messages" - }, - { - "columns": [ - { - "value": "ticket_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_participants_ticket_idx", - "entityType": "indexes", - "table": "ticket_participants" - }, - { - "columns": [ - { - "value": "actor_id", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_participants_actor_idx", - "entityType": "indexes", - "table": "ticket_participants" - }, - { - "columns": [ - { - "value": "role", - "isExpression": false - } - ], - "isUnique": false, - "where": null, - "origin": "manual", - "name": "ticket_participants_role_idx", - "entityType": "indexes", - "table": "ticket_participants" - }, - { - "columns": [ - "discord_id" - ], - "nameExplicit": false, - "name": "actors_discord_id_unique", - "entityType": "uniques", - "table": "actors" - } - ], - "renames": [] -}
@@ -1,30 +0,0 @@
-ALTER TABLE `tickets` RENAME COLUMN `private_notes` TO `private_reason`;--> statement-breakpoint -PRAGMA foreign_keys=OFF;--> statement-breakpoint -CREATE TABLE `__new_tickets` ( - `id` integer PRIMARY KEY AUTOINCREMENT, - `anonymous_id` text NOT NULL, - `status` text NOT NULL, - `channel_id` text, - `close_reason` text, - `private_reason` 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 -INSERT INTO `__new_tickets`(`id`, `anonymous_id`, `status`, `channel_id`, `close_reason`, `private_reason`, `opened_at`, `closed_at`, `opened_by`, `open_reason`, `subject`, `claimed_by`, `claimed_at`, `thanked_at`, `warned_at`, `last_message_at`, `has_moderator_message`, `has_author_message`) SELECT `id`, `anonymous_id`, `status`, `channel_id`, `close_reason`, `private_reason`, `opened_at`, `closed_at`, `opened_by`, `open_reason`, `subject`, `claimed_by`, `claimed_at`, `thanked_at`, `warned_at`, `last_message_at`, `has_moderator_message`, `has_author_message` FROM `tickets`;--> statement-breakpoint -DROP TABLE `tickets`;--> statement-breakpoint -ALTER TABLE `__new_tickets` RENAME TO `tickets`;--> statement-breakpoint -PRAGMA foreign_keys=ON;
@@ -1,17 +1,25 @@
{ "version": "7", "dialect": "sqlite", - "id": "c6ffe18f-3c96-4471-9485-54c1e2bd17c0", + "id": "424749f7-d545-4b2c-a64f-fd2b7548a703", "prevIds": [ - "f1bd9a2e-f82a-4938-9bf2-2bf4ef3c7c61" + "00000000-0000-0000-0000-000000000000" ], "ddl": [ { + "name": "sessions", + "entityType": "tables" + }, + { + "name": "users", + "entityType": "tables" + }, + { "name": "actors", "entityType": "tables" }, { - "name": "sessions", + "name": "guilds", "entityType": "tables" }, {@@ -31,6 +39,86 @@ "name": "tickets",
"entityType": "tables" }, { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "id", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "user_id", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "text", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "access_token", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "text", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "refresh_token", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "scope", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "token_type", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "expires_at", + "entityType": "columns", + "table": "sessions" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "created_at", + "entityType": "columns", + "table": "sessions" + }, + { "type": "integer", "notNull": false, "autoincrement": true,@@ -38,6 +126,96 @@ "default": null,
"generated": null, "name": "id", "entityType": "columns", + "table": "users" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "discord_id", + "entityType": "columns", + "table": "users" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "display_name", + "entityType": "columns", + "table": "users" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "username", + "entityType": "columns", + "table": "users" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "avatar", + "entityType": "columns", + "table": "users" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "created_at", + "entityType": "columns", + "table": "users" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "updated_at", + "entityType": "columns", + "table": "users" + }, + { + "type": "integer", + "notNull": false, + "autoincrement": true, + "default": null, + "generated": null, + "name": "id", + "entityType": "columns", + "table": "actors" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "guild_id", + "entityType": "columns", + "table": "actors" + }, + { + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "user_id", + "entityType": "columns", "table": "actors" }, {@@ -121,24 +299,24 @@ "entityType": "columns",
"table": "actors" }, { - "type": "text", + "type": "integer", "notNull": false, - "autoincrement": false, + "autoincrement": true, "default": null, "generated": null, "name": "id", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { - "type": "integer", + "type": "text", "notNull": true, "autoincrement": false, "default": null, "generated": null, - "name": "user_id", + "name": "discord_id", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "text",@@ -146,19 +324,49 @@ "notNull": true,
"autoincrement": false, "default": null, "generated": null, - "name": "access_token", + "name": "name", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "text", - "notNull": true, + "notNull": false, "autoincrement": false, "default": null, "generated": null, - "name": "refresh_token", + "name": "icon", + "entityType": "columns", + "table": "guilds" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "ticket_category", + "entityType": "columns", + "table": "guilds" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "ticket_log_channel", + "entityType": "columns", + "table": "guilds" + }, + { + "type": "text", + "notNull": false, + "autoincrement": false, + "default": null, + "generated": null, + "name": "ticket_greeting", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "text",@@ -166,9 +374,9 @@ "notNull": false,
"autoincrement": false, "default": null, "generated": null, - "name": "scope", + "name": "ticket_prompt_channel", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "text",@@ -176,9 +384,9 @@ "notNull": false,
"autoincrement": false, "default": null, "generated": null, - "name": "token_type", + "name": "ticket_prompt", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "integer",@@ -186,9 +394,9 @@ "notNull": true,
"autoincrement": false, "default": null, "generated": null, - "name": "expires_at", + "name": "created_at", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "integer",@@ -196,9 +404,9 @@ "notNull": true,
"autoincrement": false, "default": null, "generated": null, - "name": "created_at", + "name": "updated_at", "entityType": "columns", - "table": "sessions" + "table": "guilds" }, { "type": "integer",@@ -231,7 +439,7 @@ "entityType": "columns",
"table": "ticket_attachments" }, { - "type": "integer", + "type": "text", "notNull": true, "autoincrement": false, "default": null,@@ -311,7 +519,7 @@ "entityType": "columns",
"table": "ticket_messages" }, { - "type": "integer", + "type": "text", "notNull": true, "autoincrement": false, "default": null,@@ -391,7 +599,7 @@ "entityType": "columns",
"table": "ticket_participants" }, { - "type": "integer", + "type": "text", "notNull": true, "autoincrement": false, "default": null,@@ -441,9 +649,9 @@ "entityType": "columns",
"table": "ticket_participants" }, { - "type": "integer", + "type": "text", "notNull": false, - "autoincrement": true, + "autoincrement": false, "default": null, "generated": null, "name": "id",@@ -451,12 +659,22 @@ "entityType": "columns",
"table": "tickets" }, { - "type": "text", + "type": "integer", + "notNull": true, + "autoincrement": false, + "default": null, + "generated": null, + "name": "guild_id", + "entityType": "columns", + "table": "tickets" + }, + { + "type": "integer", "notNull": true, "autoincrement": false, "default": null, "generated": null, - "name": "anonymous_id", + "name": "local_id", "entityType": "columns", "table": "tickets" },@@ -624,19 +842,49 @@ {
"columns": [ "user_id" ], - "tableTo": "actors", + "tableTo": "users", "columnsTo": [ "id" ], "onUpdate": "NO ACTION", - "onDelete": "NO ACTION", + "onDelete": "CASCADE", "nameExplicit": false, - "name": "fk_sessions_user_id_actors_id_fk", + "name": "fk_sessions_user_id_users_id_fk", "entityType": "fks", "table": "sessions" }, { "columns": [ + "guild_id" + ], + "tableTo": "guilds", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "CASCADE", + "nameExplicit": false, + "name": "fk_actors_guild_id_guilds_id_fk", + "entityType": "fks", + "table": "actors" + }, + { + "columns": [ + "user_id" + ], + "tableTo": "users", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "CASCADE", + "nameExplicit": false, + "name": "fk_actors_user_id_users_id_fk", + "entityType": "fks", + "table": "actors" + }, + { + "columns": [ "message_id" ], "tableTo": "ticket_messages",@@ -739,6 +987,21 @@ "nameExplicit": false,
"name": "fk_ticket_participants_actor_id_actors_id_fk", "entityType": "fks", "table": "ticket_participants" + }, + { + "columns": [ + "guild_id" + ], + "tableTo": "guilds", + "columnsTo": [ + "id" + ], + "onUpdate": "NO ACTION", + "onDelete": "CASCADE", + "nameExplicit": false, + "name": "fk_tickets_guild_id_guilds_id_fk", + "entityType": "fks", + "table": "tickets" }, { "columns": [@@ -790,6 +1053,24 @@ "columns": [
"id" ], "nameExplicit": false, + "name": "sessions_pk", + "table": "sessions", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, + "name": "users_pk", + "table": "users", + "entityType": "pks" + }, + { + "columns": [ + "id" + ], + "nameExplicit": false, "name": "actors_pk", "table": "actors", "entityType": "pks"@@ -799,8 +1080,8 @@ "columns": [
"id" ], "nameExplicit": false, - "name": "sessions_pk", - "table": "sessions", + "name": "guilds_pk", + "table": "guilds", "entityType": "pks" }, {@@ -842,6 +1123,24 @@ },
{ "columns": [ { + "value": "guild_id", + "isExpression": false + }, + { + "value": "user_id", + "isExpression": false + } + ], + "isUnique": true, + "where": null, + "origin": "manual", + "name": "actors_guild_user_idx", + "entityType": "indexes", + "table": "actors" + }, + { + "columns": [ + { "value": "ticket_id", "isExpression": false }@@ -967,15 +1266,40 @@ "table": "ticket_participants"
}, { "columns": [ + { + "value": "guild_id", + "isExpression": false + }, + { + "value": "local_id", + "isExpression": false + } + ], + "isUnique": true, + "where": null, + "origin": "manual", + "name": "tickets_guild_local_idx", + "entityType": "indexes", + "table": "tickets" + }, + { + "columns": [ "discord_id" ], "nameExplicit": false, - "name": "actors_discord_id_unique", + "name": "users_discord_id_unique", + "entityType": "uniques", + "table": "users" + }, + { + "columns": [ + "discord_id" + ], + "nameExplicit": false, + "name": "guilds_discord_id_unique", "entityType": "uniques", - "table": "actors" + "table": "guilds" } ], - "renames": [ - "tickets.private_notes->tickets.private_reason" - ] + "renames": [] }
@@ -0,0 +1,129 @@
+CREATE TABLE `sessions` ( + `id` text PRIMARY KEY, + `user_id` integer NOT NULL, + `access_token` text NOT NULL, + `refresh_token` text NOT NULL, + `scope` text, + `token_type` text, + `expires_at` integer NOT NULL, + `created_at` integer NOT NULL, + CONSTRAINT `fk_sessions_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE +); +--> statement-breakpoint +CREATE TABLE `users` ( + `id` integer PRIMARY KEY AUTOINCREMENT, + `discord_id` text UNIQUE, + `display_name` text, + `username` text, + `avatar` text, + `created_at` integer NOT NULL, + `updated_at` integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE `actors` ( + `id` integer PRIMARY KEY AUTOINCREMENT, + `guild_id` integer NOT NULL, + `user_id` integer NOT NULL, + `discord_id` text, + `display_name` text, + `username` text, + `avatar` text, + `moderator` integer, + `created_at` integer NOT NULL, + `updated_at` integer NOT NULL, + `deleted_at` integer, + CONSTRAINT `fk_actors_guild_id_guilds_id_fk` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE CASCADE, + CONSTRAINT `fk_actors_user_id_users_id_fk` FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE +); +--> statement-breakpoint +CREATE TABLE `guilds` ( + `id` integer PRIMARY KEY AUTOINCREMENT, + `discord_id` text NOT NULL UNIQUE, + `name` text NOT NULL, + `icon` text, + `ticket_category` text, + `ticket_log_channel` text, + `ticket_greeting` text, + `ticket_prompt_channel` text, + `ticket_prompt` text, + `created_at` integer NOT NULL, + `updated_at` integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE `ticket_attachments` ( + `id` integer PRIMARY KEY AUTOINCREMENT, + `public_id` text NOT NULL, + `message_id` integer, + `ticket_id` text 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` text 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` text 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 +); +--> statement-breakpoint +CREATE TABLE `tickets` ( + `id` text PRIMARY KEY, + `guild_id` integer NOT NULL, + `local_id` integer NOT NULL, + `status` text NOT NULL, + `channel_id` text, + `close_reason` text, + `private_reason` 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_guild_id_guilds_id_fk` FOREIGN KEY (`guild_id`) REFERENCES `guilds`(`id`) ON DELETE CASCADE, + 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 UNIQUE INDEX `actors_guild_user_idx` ON `actors` (`guild_id`,`user_id`);--> statement-breakpoint +CREATE INDEX `ticket_attachments_ticket_idx` ON `ticket_attachments` (`ticket_id`);--> statement-breakpoint +CREATE INDEX `ticket_attachments_actor_idx` ON `ticket_attachments` (`actor_id`);--> statement-breakpoint +CREATE INDEX `ticket_attachments_public_id_idx` ON `ticket_attachments` (`public_id`);--> statement-breakpoint +CREATE INDEX `ticket_messages_ticket_idx` ON `ticket_messages` (`ticket_id`);--> statement-breakpoint +CREATE INDEX `ticket_messages_actor_idx` ON `ticket_messages` (`actor_id`);--> statement-breakpoint +CREATE INDEX `ticket_messages_public_id_idx` ON `ticket_messages` (`public_id`);--> statement-breakpoint +CREATE INDEX `ticket_participants_ticket_idx` ON `ticket_participants` (`ticket_id`);--> statement-breakpoint +CREATE INDEX `ticket_participants_actor_idx` ON `ticket_participants` (`actor_id`);--> statement-breakpoint +CREATE INDEX `ticket_participants_role_idx` ON `ticket_participants` (`role`);--> statement-breakpoint +CREATE UNIQUE INDEX `tickets_guild_local_idx` ON `tickets` (`guild_id`,`local_id`);
@@ -3,6 +3,9 @@ "name": "@stealth-developers/db",
"type": "module", "main": "./src/index.ts", "types": "./src/index.ts", + "scripts": { + "db": "bun ./scripts/db.ts" + }, "dependencies": { "@libsql/client": "^0.17.3", "drizzle-orm": "v1.0.0-rc.3"@@ -13,6 +16,6 @@ "drizzle-kit": "v1.0.0-rc.3"
}, "peerDependencies": { "@stealth-developers/config": "workspace:*", - "typescript": "^5" + "typescript": "^5.9.3" } }
@@ -0,0 +1,13 @@
+import config from "@stealth-developers/config"; + +const proc = Bun.spawn([process.execPath, "x", "drizzle-kit", ...Bun.argv.slice(2)], { + env: { + PATH: process.env.PATH, + DATABASE_URL: config.db.url, + DATABASE_AUTH: config.db.auth, + }, + stdout: "inherit", + stderr: "inherit", +}); + +await proc.exited;
@@ -16,7 +16,7 @@ .integer("user_id")
.notNull() .references(() => users.id, { onDelete: "cascade" }), - discordId: s.text("discord_id").unique(), + discordId: s.text("discord_id"), displayName: s.text("display_name"), username: s.text("username"), avatar: s.text("avatar"),
@@ -1,24 +1,71 @@
-import { eq } from "drizzle-orm"; -import db, { actors, sessions } from ".."; +import { eq, and } from "drizzle-orm"; +import db, { actors, sessions, users, guilds } from ".."; export async function getUser(id: number) { + const [result] = await db.select().from(users).where(eq(users.id, id)); + return result; +} + +export async function getUserByDiscordId(discordId: string) { + const [result] = await db.select().from(users).where(eq(users.discordId, discordId)); + return result; +} + +export async function getActor(id: number) { const [result] = await db.select().from(actors).where(eq(actors.id, id)); return result; } -export async function getUserByDiscordId(discordId: string) { - const [result] = await db.select().from(actors).where(eq(actors.discordId, discordId)); + +export async function getActorByDiscordId(discordId: string, guildId: number) { + const [result] = await db + .select() + .from(actors) + .where(and(eq(actors.discordId, discordId), eq(actors.guildId, guildId))); return result; } +export async function getActorByDiscordIdAndGuildDiscordId( + discordId: string, + guildDiscordId: string, +) { + const [guild] = await db.select().from(guilds).where(eq(guilds.discordId, guildDiscordId)); + if (!guild) return null; + return getActorByDiscordId(discordId, guild.id); +} + export async function getUserSessions(id: number) { const result = await db.select().from(sessions).where(eq(sessions.userId, id)); return result; } + export async function getSession(id: string) { const [result] = await db.select().from(sessions).where(eq(sessions.id, id)); return result; } +export async function upsertGuild(guild: { discordId: string; name: string; icon: string | null }) { + const [upsertedGuild] = await db + .insert(guilds) + .values({ + discordId: guild.discordId, + name: guild.name, + icon: guild.icon, + createdAt: new Date(), + updatedAt: new Date(), + }) + .onConflictDoUpdate({ + target: guilds.discordId, + set: { + name: guild.name, + icon: guild.icon, + updatedAt: new Date(), + }, + }) + .returning(); + + return upsertedGuild; +} + export async function upsertUser(user: { username: string; displayName: string | null;@@ -26,18 +73,17 @@ id: string;
avatar: string | null; }) { const [upsertedUser] = await db - .insert(actors) + .insert(users) .values({ discordId: user.id, username: user.username, displayName: user.displayName, avatar: user.avatar, - createdAt: new Date(), updatedAt: new Date(), }) .onConflictDoUpdate({ - target: actors.discordId, + target: users.discordId, set: { username: user.username, displayName: user.displayName,@@ -48,6 +94,60 @@ })
.returning(); return upsertedUser; +} + +export async function upsertActor(data: { + guild: { + discordId: string; + name: string; + icon: string | null; + }; + user: { + discordId: string; + username: string; + displayName: string | null; + avatar: string | null; + }; + moderator: boolean; +}) { + const dbGuild = await upsertGuild(data.guild); + const dbUser = await upsertUser({ + id: data.user.discordId, + username: data.user.username, + displayName: data.user.displayName, + avatar: data.user.avatar, + }); + + if (!dbGuild || !dbUser) { + throw new Error("Failed to upsert guild or user"); + } + + const [actor] = await db + .insert(actors) + .values({ + guildId: dbGuild.id, + userId: dbUser.id, + discordId: data.user.discordId, + username: data.user.username, + displayName: data.user.displayName, + avatar: data.user.avatar, + moderator: data.moderator, + createdAt: new Date(), + updatedAt: new Date(), + }) + .onConflictDoUpdate({ + target: [actors.guildId, actors.userId], + set: { + username: data.user.username, + displayName: data.user.displayName, + avatar: data.user.avatar, + moderator: data.moderator, + updatedAt: new Date(), + }, + }) + .returning(); + + return actor; } export async function anonymiseUser(id: number) {