-
Notifications
You must be signed in to change notification settings - Fork 7
DataBase 명세서
Taegyung Gong edited this page Nov 26, 2020
·
8 revisions
CREATE TABLE `User` (
`id` INT NOT NULL AUTO_INCREMENT,
`nickname` VARCHAR(191) NOT NULL,
`avatar` VARCHAR(191) NOT NULL,
`password` VARCHAR(191),
`lang` VARCHAR(191) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
CREATE TABLE `Room` (
`id` INT NOT NULL AUTO_INCREMENT,
`avatar` VARCHAR(191) NOT NULL,
`code` VARCHAR(191) NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
UNIQUE INDEX `Room.code_unique`(`code`),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
CREATE TABLE `Message` (
`id` INT NOT NULL AUTO_INCREMENT,
`text` VARCHAR(191) NOT NULL,
`source` VARCHAR(191) NOT NULL,
`roomId` INT NOT NULL,
`userId` INT NOT NULL,
`createdAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
`updatedAt` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
PRIMARY KEY (`id`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
CREATE TABLE `_RoomToUser` (
`A` INT NOT NULL,
`B` INT NOT NULL,
UNIQUE INDEX `_RoomToUser_AB_unique`(`A`,
`B`),
INDEX `_RoomToUser_B_index`(`B`)
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci
ALTER TABLE `Message` ADD FOREIGN KEY (`roomId`) REFERENCES `Room`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE `Message` ADD FOREIGN KEY (`userId`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE `_RoomToUser` ADD FOREIGN KEY (`A`) REFERENCES `Room`(`id`) ON DELETE CASCADE ON UPDATE CASCADE
ALTER TABLE `_RoomToUser` ADD FOREIGN KEY (`B`) REFERENCES `User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE