23 lines
1.2 KiB
SQL
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`); |