From 27a8b0e33d4e4f08549f2ac8363841428cf49d12 Mon Sep 17 00:00:00 2001 From: Dejan Vasic Date: Sat, 30 Dec 2023 23:12:30 +1100 Subject: [PATCH] Database name changes for the note invites --- .../migration.sql | 49 +++++++++++++++++++ prisma/schema.prisma | 28 ++++++----- 2 files changed, 64 insertions(+), 13 deletions(-) create mode 100644 prisma/migrations/20231230121138_note_access_changes/migration.sql diff --git a/prisma/migrations/20231230121138_note_access_changes/migration.sql b/prisma/migrations/20231230121138_note_access_changes/migration.sql new file mode 100644 index 0000000..2ae4ef3 --- /dev/null +++ b/prisma/migrations/20231230121138_note_access_changes/migration.sql @@ -0,0 +1,49 @@ +/* + Warnings: + + - You are about to drop the `NoteAccess` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `NoteAccessInvite` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "NoteAccess" DROP CONSTRAINT "NoteAccess_noteId_fkey"; + +-- DropForeignKey +ALTER TABLE "NoteAccessInvite" DROP CONSTRAINT "NoteAccessInvite_noteId_fkey"; + +-- DropTable +DROP TABLE "NoteAccess"; + +-- DropTable +DROP TABLE "NoteAccessInvite"; + +-- CreateTable +CREATE TABLE "NoteCollaborator" ( + "id" TEXT NOT NULL, + "noteId" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMPTZ(6) NOT NULL, + + CONSTRAINT "NoteCollaborator_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "NoteInvite" ( + "id" TEXT NOT NULL, + "noteId" TEXT NOT NULL, + "email" TEXT NOT NULL, + "createdAt" TIMESTAMPTZ(6) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMPTZ(6) NOT NULL, + + CONSTRAINT "NoteInvite_pkey" PRIMARY KEY ("id") +); + +-- AddForeignKey +ALTER TABLE "NoteCollaborator" ADD CONSTRAINT "NoteCollaborator_noteId_fkey" FOREIGN KEY ("noteId") REFERENCES "Note"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "NoteCollaborator" ADD CONSTRAINT "NoteCollaborator_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "NoteInvite" ADD CONSTRAINT "NoteInvite_noteId_fkey" FOREIGN KEY ("noteId") REFERENCES "Note"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8e06806..b520265 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -12,15 +12,16 @@ datasource db { } model User { - id String @id - createdAt DateTime @default(now()) @db.Timestamptz(6) - updatedAt DateTime @updatedAt @db.Timestamptz(6) - authId String @unique - email String @unique - emailVerified Boolean - name String? - picture String? - boards Board[] + id String @id + createdAt DateTime @default(now()) @db.Timestamptz(6) + updatedAt DateTime @updatedAt @db.Timestamptz(6) + authId String @unique + email String @unique + emailVerified Boolean + name String? + picture String? + boards Board[] + noteCollaborators NoteCollaborator[] } model Board { @@ -43,20 +44,21 @@ model Note { colour String? boardId String board Board @relation(fields: [boardId], references: [id], onDelete: Cascade) - noteAccess NoteAccess[] - noteAccessInvites NoteAccessInvite[] + noteCollaborators NoteCollaborator[] + noteInvites NoteInvite[] } -model NoteAccess { +model NoteCollaborator { id String @id noteId String userId String createdAt DateTime @default(now()) @db.Timestamptz(6) updatedAt DateTime @updatedAt @db.Timestamptz(6) note Note @relation(fields: [noteId], references: [id], onDelete: Cascade) + user User @relation(fields: [userId], references: [id], onDelete: Cascade) } -model NoteAccessInvite { +model NoteInvite { id String @id noteId String email String