This commit is contained in:
jane 2022-04-02 13:45:06 -04:00
parent 52a0ba1b3b
commit 83bc981152
23 changed files with 9034 additions and 927 deletions

View file

@ -0,0 +1,42 @@
/*
Warnings:
- You are about to drop the column `email` on the `User` table. All the data in the column will be lost.
- You are about to drop the `Note` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Password` table. If the table is not empty, all the data it contains will be lost.
- A unique constraint covering the columns `[discord_id]` on the table `User` will be added. If there are existing duplicate values, this will fail.
*/
-- DropForeignKey
ALTER TABLE "Note" DROP CONSTRAINT "Note_userId_fkey";
-- DropForeignKey
ALTER TABLE "Password" DROP CONSTRAINT "Password_userId_fkey";
-- DropIndex
DROP INDEX "User_email_key";
-- AlterTable
ALTER TABLE "User" DROP COLUMN "email",
ADD COLUMN "border_id" TEXT,
ADD COLUMN "discord_id" TEXT;
-- DropTable
DROP TABLE "Note";
-- DropTable
DROP TABLE "Password";
-- CreateTable
CREATE TABLE "Border" (
"id" TEXT NOT NULL,
"filename" TEXT NOT NULL,
CONSTRAINT "Border_pkey" PRIMARY KEY ("id")
);
-- CreateIndex
CREATE UNIQUE INDEX "Border_filename_key" ON "Border"("filename");
-- CreateIndex
CREATE UNIQUE INDEX "User_discord_id_key" ON "User"("discord_id");

View file

@ -9,30 +9,25 @@ generator client {
model User {
id String @id @default(cuid())
email String @unique
discord_id String? @unique
border_id String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
password Password?
notes Note[]
}
model Password {
hash String
model DiscordUser {
id String @id @default(cuid())
discord_id String @unique
access_token String?
refresh_token String?
expires DateTime?
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String @unique
username String?
discriminator String?
}
model Note {
id String @id @default(cuid())
title String
body String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: Cascade)
userId String
}
model Border {
id String @id @default(cuid())
filename String @unique
}

View file

@ -1,42 +1,20 @@
import { PrismaClient } from "@prisma/client";
import bcrypt from "@node-rs/bcrypt";
const prisma = new PrismaClient();
async function seed() {
const email = "rachel@remix.run";
const discord_id = "123601647258697730";
const border_id = 'test';
// cleanup the existing database
await prisma.user.delete({ where: { email } }).catch(() => {
await prisma.user.delete({ where: { discord_id } }).catch(() => {
// no worries if it doesn't exist yet
});
const hashedPassword = await bcrypt.hash("racheliscool", 10);
const user = await prisma.user.create({
data: {
email,
password: {
create: {
hash: hashedPassword,
},
},
},
});
await prisma.note.create({
data: {
title: "My first note",
body: "Hello, world!",
userId: user.id,
},
});
await prisma.note.create({
data: {
title: "My second note",
body: "Hello, world!",
userId: user.id,
discord_id,
border_id
},
});