Files
BRETT/server/db/migrations/0015_pink_kingpin.sql
2026-10-03 20:07:49 +02:00

16 lines
824 B
SQL

CREATE TABLE `tags` (
`id` bigint unsigned AUTO_INCREMENT NOT NULL,
`name` varchar(64) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT (now()),
CONSTRAINT `tags_id` PRIMARY KEY(`id`),
CONSTRAINT `tags_name_unique` UNIQUE(`name`)
);
--> statement-breakpoint
CREATE TABLE `upload_tags` (
`upload_id` varchar(8) NOT NULL,
`tag_id` bigint unsigned NOT NULL,
CONSTRAINT `upload_tags_upload_id_tag_id_pk` PRIMARY KEY(`upload_id`,`tag_id`)
);
--> statement-breakpoint
ALTER TABLE `upload_tags` ADD CONSTRAINT `upload_tags_upload_id_uploads_id_fk` FOREIGN KEY (`upload_id`) REFERENCES `uploads`(`id`) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE `upload_tags` ADD CONSTRAINT `upload_tags_tag_id_tags_id_fk` FOREIGN KEY (`tag_id`) REFERENCES `tags`(`id`) ON DELETE cascade ON UPDATE no action;