peppa/packages/db/migrations/0021_deep_vivisector.sql
Асель 87502479a9 PEP-159: миграция вложений — 0021 после 0020 из main
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 16:03:45 +05:00

23 lines
1.2 KiB
SQL

CREATE TABLE `attachments` (
`id` integer PRIMARY KEY AUTOINCREMENT NOT NULL,
`project_id` integer NOT NULL,
`user_id` integer,
`task_id` integer,
`chat_message_id` integer,
`event_id` integer,
`name` text NOT NULL,
`file` text NOT NULL,
`mime` text NOT NULL,
`size` integer NOT NULL,
`created_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 (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE set null,
FOREIGN KEY (`task_id`) REFERENCES `tasks`(`id`) ON UPDATE no action ON DELETE set null,
FOREIGN KEY (`chat_message_id`) REFERENCES `chat_messages`(`id`) ON UPDATE no action ON DELETE set null,
FOREIGN KEY (`event_id`) REFERENCES `events`(`id`) ON UPDATE no action ON DELETE set null
);
--> statement-breakpoint
CREATE INDEX `attachments_task` ON `attachments` (`task_id`);--> statement-breakpoint
CREATE INDEX `attachments_message` ON `attachments` (`chat_message_id`);--> statement-breakpoint
CREATE INDEX `attachments_event` ON `attachments` (`event_id`);--> statement-breakpoint
CREATE INDEX `attachments_project` ON `attachments` (`project_id`);