-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy path0000_milky_iron_man.sql
67 lines (67 loc) · 1.94 KB
/
0000_milky_iron_man.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
CREATE TABLE `categories` (
`id` text PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`body` text,
`createdOn` integer,
`updatedOn` integer
);
--> statement-breakpoint
CREATE TABLE `categoriesToPosts` (
`id` text NOT NULL,
`postId` text NOT NULL,
`categoryId` text NOT NULL,
`createdOn` integer,
`updatedOn` integer,
PRIMARY KEY(`postId`, `categoryId`),
FOREIGN KEY (`postId`) REFERENCES `posts`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`categoryId`) REFERENCES `categories`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `comments` (
`id` text PRIMARY KEY NOT NULL,
`body` text NOT NULL,
`userId` text NOT NULL,
`postId` integer NOT NULL,
`tags` text,
`createdOn` integer,
`updatedOn` integer
);
--> statement-breakpoint
CREATE TABLE `posts` (
`id` text PRIMARY KEY NOT NULL,
`title` text NOT NULL,
`body` text NOT NULL,
`userId` text NOT NULL,
`image` text,
`images` text,
`tags` text,
`createdOn` integer,
`updatedOn` integer
);
--> statement-breakpoint
CREATE TABLE `userSessions` (
`id` text PRIMARY KEY NOT NULL,
`userId` text NOT NULL,
`activeExpires` integer NOT NULL,
`idleExpires` integer NOT NULL,
`createdOn` integer,
`updatedOn` integer,
FOREIGN KEY (`userId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`firstName` text,
`lastName` text,
`email` text,
`password` text NOT NULL,
`role` text DEFAULT 'user',
`createdOn` integer,
`updatedOn` integer
);
--> statement-breakpoint
CREATE INDEX `commentsUserIdIndex` ON `comments` (`userId`);--> statement-breakpoint
CREATE INDEX `commentsPostIdIndex` ON `comments` (`postId`);--> statement-breakpoint
CREATE INDEX `postUserIdIndex` ON `posts` (`userId`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `email_idx` ON `users` (`email`);