Skip to content

Commit e3bcd01

Browse files
committed
✨ Add board and category schemas
1 parent 7ad7e05 commit e3bcd01

File tree

9 files changed

+670
-1
lines changed

9 files changed

+670
-1
lines changed

src/db/field.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { int, timestamp } from 'drizzle-orm/mysql-core'
1+
import { int, timestamp, varchar } from 'drizzle-orm/mysql-core'
22

33
export const id = int('id').primaryKey().autoincrement()
44

@@ -9,3 +9,5 @@ export const updatedAt = timestamp('updated_at')
99
.notNull()
1010
.defaultNow()
1111
.onUpdateNow()
12+
13+
export const slug = varchar('slug', { length: 64 }).notNull().unique()

src/db/migration/0003_red_wallop.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
CREATE TABLE `ara_board` (
2+
`id` int AUTO_INCREMENT NOT NULL,
3+
`created_at` timestamp NOT NULL DEFAULT (now()),
4+
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
5+
`slug` varchar(64) NOT NULL,
6+
`name_ko` varchar(64) NOT NULL,
7+
`name_en` varchar(64) NOT NULL,
8+
`group_id` int NOT NULL,
9+
CONSTRAINT `ara_board_id` PRIMARY KEY(`id`),
10+
CONSTRAINT `ara_board_slug_unique` UNIQUE(`slug`)
11+
);
12+
--> statement-breakpoint
13+
CREATE TABLE `ara_board_group` (
14+
`id` int AUTO_INCREMENT NOT NULL,
15+
`created_at` timestamp NOT NULL DEFAULT (now()),
16+
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
17+
`name_ko` varchar(64) NOT NULL,
18+
`name_en` varchar(64) NOT NULL,
19+
CONSTRAINT `ara_board_group_id` PRIMARY KEY(`id`)
20+
);
21+
--> statement-breakpoint
22+
CREATE TABLE `ara_category` (
23+
`id` int AUTO_INCREMENT NOT NULL,
24+
`created_at` timestamp NOT NULL DEFAULT (now()),
25+
`updated_at` timestamp NOT NULL DEFAULT (now()) ON UPDATE CURRENT_TIMESTAMP,
26+
`slug` varchar(64) NOT NULL,
27+
`name_ko` varchar(64) NOT NULL,
28+
`name_en` varchar(64) NOT NULL,
29+
`board_id` int NOT NULL,
30+
CONSTRAINT `ara_category_id` PRIMARY KEY(`id`),
31+
CONSTRAINT `ara_board_slug_unique` UNIQUE(`slug`),
32+
CONSTRAINT `ara_category_slug_board_id_unique` UNIQUE(`slug`,`board_id`)
33+
);
34+
--> statement-breakpoint
35+
ALTER TABLE `ara_board` ADD CONSTRAINT `ara_board_group_id_ara_board_group_id_fk` FOREIGN KEY (`group_id`) REFERENCES `ara_board_group`(`id`) ON DELETE no action ON UPDATE no action;--> statement-breakpoint
36+
ALTER TABLE `ara_category` ADD CONSTRAINT `ara_category_board_id_ara_board_id_fk` FOREIGN KEY (`board_id`) REFERENCES `ara_board`(`id`) ON DELETE no action ON UPDATE no action;

0 commit comments

Comments
 (0)