README.md 3.81 KB

Migration 20200419160117-init

This migration has been generated by sdy at 4/19/2020, 4:01:17 PM. You can check out the state of the schema after the migration.

Database Steps

CREATE TABLE `chat_schema`.`User` (
    `avatarUrl` varchar(191)   ,
    `bio` varchar(191)   ,
    `createdAt` datetime  DEFAULT CURRENT_TIMESTAMP ,
    `email` varchar(191) NOT NULL  ,
    `id` int NOT NULL  AUTO_INCREMENT,
    `loginSecret` varchar(191)   ,
    `name` varchar(191) NOT NULL  ,
    `password` varchar(191) NOT NULL  ,
    PRIMARY KEY (`id`)
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE TABLE `chat_schema`.`Room` (
    `id` int NOT NULL  AUTO_INCREMENT,
    PRIMARY KEY (`id`)
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE TABLE `chat_schema`.`Category` (
    `id` int NOT NULL  AUTO_INCREMENT,
    `name` varchar(191)  DEFAULT '' ,
    PRIMARY KEY (`id`)
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE TABLE `chat_schema`.`Message` (
    `id` int NOT NULL  AUTO_INCREMENT,
    `senderId` int NOT NULL ,
    `text` varchar(191)  DEFAULT '' ,
    PRIMARY KEY (`id`)
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE TABLE `chat_schema`.`_RoomToUser` (
    `A` int NOT NULL ,
    `B` int NOT NULL 
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE TABLE `chat_schema`.`_CategoryToRoom` (
    `A` int NOT NULL ,
    `B` int NOT NULL 
) 
DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci

CREATE UNIQUE INDEX `User.email` ON `chat_schema`.`User`(`email`)

CREATE UNIQUE INDEX `_RoomToUser_AB_unique` ON `chat_schema`.`_RoomToUser`(`A`,`B`)

CREATE  INDEX `_RoomToUser_B_index` ON `chat_schema`.`_RoomToUser`(`B`)

CREATE UNIQUE INDEX `_CategoryToRoom_AB_unique` ON `chat_schema`.`_CategoryToRoom`(`A`,`B`)

CREATE  INDEX `_CategoryToRoom_B_index` ON `chat_schema`.`_CategoryToRoom`(`B`)

ALTER TABLE `chat_schema`.`Message` ADD FOREIGN KEY (`senderId`) REFERENCES `chat_schema`.`User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE

ALTER TABLE `chat_schema`.`_RoomToUser` ADD FOREIGN KEY (`A`) REFERENCES `chat_schema`.`Room`(`id`) ON DELETE CASCADE ON UPDATE CASCADE

ALTER TABLE `chat_schema`.`_RoomToUser` ADD FOREIGN KEY (`B`) REFERENCES `chat_schema`.`User`(`id`) ON DELETE CASCADE ON UPDATE CASCADE

ALTER TABLE `chat_schema`.`_CategoryToRoom` ADD FOREIGN KEY (`A`) REFERENCES `chat_schema`.`Category`(`id`) ON DELETE CASCADE ON UPDATE CASCADE

ALTER TABLE `chat_schema`.`_CategoryToRoom` ADD FOREIGN KEY (`B`) REFERENCES `chat_schema`.`Room`(`id`) ON DELETE CASCADE ON UPDATE CASCADE

DROP TABLE `chat_schema`.`_migration`;

DROP TABLE `chat_schema`.`test`;

Changes

diff --git schema.prisma schema.prisma
migration ..20200419160117-init
--- datamodel.dml
+++ datamodel.dml
@@ -1,0 +1,41 @@
+generator client {
+  provider      = "prisma-client-js"
+  binaryTargets = ["native", "debian-openssl-1.1.x"]
+}
+
+datasource db {
+  provider = "mysql"
+  url      = env("DATABASE_URL")
+}
+
+model User {
+  id          Int       @default(autoincrement()) @id
+  avatarUrl   String?
+  email       String    @unique
+  password    String
+  name        String
+  loginSecret String?
+  bio         String?
+  rooms       Room[]    @relation(references: [id])
+  messages    Message[]
+  createdAt   DateTime? @default(now())
+}
+
+model Room {
+  id           Int        @default(autoincrement()) @id
+  participants User[]     @relation(references: [id])
+  categories   Category[] @relation(references: [id])
+}
+
+model Category {
+  id    Int     @default(autoincrement()) @id
+  name  String? @default("")
+  rooms Room[]  @relation(references: [id])
+}
+
+model Message {
+  id       Int     @default(autoincrement()) @id
+  text     String? @default("")
+  sender   User    @relation(fields: [senderId], references: [id])
+  senderId Int
+}