write-ups-challenges-2024-2025/photos/backend/drizzle/0000_fast_rawhide_kid.sql

23 lines
819 B
MySQL
Raw Normal View History

2024-11-25 21:32:02 +00:00
CREATE TABLE `photo_likes` (
`photo_id` integer NOT NULL,
`user_id` text NOT NULL,
PRIMARY KEY(`photo_id`, `user_id`),
FOREIGN KEY (`photo_id`) REFERENCES `photos`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `photos` (
`id` integer PRIMARY KEY NOT NULL,
`user_id` text(50) NOT NULL,
`caption` text(250),
`visible` integer DEFAULT false NOT NULL,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`username` text(50) NOT NULL,
`password` text(50) NOT NULL
);
--> statement-breakpoint
CREATE UNIQUE INDEX `users_username_unique` ON `users` (`username`);