PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_ticket_attachments` (
	`id` text PRIMARY KEY,
	`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
INSERT INTO `__new_ticket_attachments`(`id`, `message_id`, `ticket_id`, `actor_id`, `file_name`, `file_type`, `file_size`) SELECT `id`, `message_id`, `ticket_id`, `actor_id`, `file_name`, `file_type`, `file_size` FROM `ticket_attachments`;--> statement-breakpoint
DROP TABLE `ticket_attachments`;--> statement-breakpoint
ALTER TABLE `__new_ticket_attachments` RENAME TO `ticket_attachments`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> 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` (`id`);