From c08e7d45803a5f841f671c580ccf2d54779f490d Mon Sep 17 00:00:00 2001 From: daniel31x13 Date: Fri, 27 Oct 2023 16:06:42 -0400 Subject: [PATCH] updated prisma schema --- lib/api/migration/migrateToV2.js | 1 - .../migration.sql | 24 +++++ .../migration.sql | 18 ++++ prisma/schema.prisma | 89 ++++++++----------- 4 files changed, 79 insertions(+), 53 deletions(-) create mode 100644 prisma/migrations/20231027194841_add_updated_at_fields_to_tables/migration.sql create mode 100644 prisma/migrations/20231027195438_remove_unnecessary_tables/migration.sql diff --git a/lib/api/migration/migrateToV2.js b/lib/api/migration/migrateToV2.js index 29c7e17..ec2300a 100644 --- a/lib/api/migration/migrateToV2.js +++ b/lib/api/migration/migrateToV2.js @@ -31,7 +31,6 @@ async function checkFileExistence(path) { Key: path, }; - console.log(path); try { const headObjectAsync = util.promisify( s3Client.headObject.bind(s3Client) diff --git a/prisma/migrations/20231027194841_add_updated_at_fields_to_tables/migration.sql b/prisma/migrations/20231027194841_add_updated_at_fields_to_tables/migration.sql new file mode 100644 index 0000000..80cc4b5 --- /dev/null +++ b/prisma/migrations/20231027194841_add_updated_at_fields_to_tables/migration.sql @@ -0,0 +1,24 @@ +-- AlterTable +ALTER TABLE "Collection" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "Link" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "Tag" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "User" ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "UsersAndCollections" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "VerificationToken" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; + +-- AlterTable +ALTER TABLE "WhitelistedUser" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, +ADD COLUMN "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; diff --git a/prisma/migrations/20231027195438_remove_unnecessary_tables/migration.sql b/prisma/migrations/20231027195438_remove_unnecessary_tables/migration.sql new file mode 100644 index 0000000..e4c46ac --- /dev/null +++ b/prisma/migrations/20231027195438_remove_unnecessary_tables/migration.sql @@ -0,0 +1,18 @@ +/* + Warnings: + + - You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost. + - You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost. + +*/ +-- DropForeignKey +ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey"; + +-- DropForeignKey +ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey"; + +-- DropTable +DROP TABLE "Account"; + +-- DropTable +DROP TABLE "Session"; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index e417a4f..dda64fd 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -7,75 +7,52 @@ datasource db { url = env("DATABASE_URL") } -model Account { - id String @id @default(cuid()) - userId Int - type String - provider String - providerAccountId String - refresh_token String? - access_token String? - expires_at Int? - token_type String? - scope String? - id_token String? - session_state String? - - user User @relation(fields: [userId], references: [id], onDelete: Cascade) - - @@unique([provider, providerAccountId]) -} - -model Session { - id String @id @default(cuid()) - sessionToken String @unique - userId Int - expires DateTime - user User @relation(fields: [userId], references: [id], onDelete: Cascade) -} - model User { - id Int @id @default(autoincrement()) - name String + id Int @id @default(autoincrement()) + name String - username String? @unique + username String? @unique - email String? @unique - emailVerified DateTime? - imagePath String? + email String? @unique + emailVerified DateTime? + imagePath String? - accounts Account[] - sessions Session[] + password String + collections Collection[] - password String - collections Collection[] + tags Tag[] - tags Tag[] - - pinnedLinks Link[] + pinnedLinks Link[] archiveAsScreenshot Boolean @default(true) archiveAsPDF Boolean @default(true) archiveAsWaybackMachine Boolean @default(false) - collectionsJoined UsersAndCollections[] - isPrivate Boolean @default(false) - whitelistedUsers WhitelistedUser[] - createdAt DateTime @default(now()) + collectionsJoined UsersAndCollections[] + isPrivate Boolean @default(false) + whitelistedUsers WhitelistedUser[] + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) } model WhitelistedUser { - id Int @id @default(autoincrement()) + id Int @id @default(autoincrement()) - username String @default("") - User User? @relation(fields: [userId], references: [id]) - userId Int? + username String @default("") + User User? @relation(fields: [userId], references: [id]) + userId Int? + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) } model VerificationToken { - identifier String - token String @unique - expires DateTime + identifier String + token String @unique + expires DateTime + + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) @@unique([identifier, token]) } @@ -91,7 +68,8 @@ model Collection { ownerId Int members UsersAndCollections[] links Link[] - createdAt DateTime @default(now()) + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) @@unique([name, ownerId]) } @@ -107,6 +85,9 @@ model UsersAndCollections { canUpdate Boolean canDelete Boolean + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) + @@id([userId, collectionId]) } @@ -126,6 +107,7 @@ model Link { pdfPath String? createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) } model Tag { @@ -135,5 +117,8 @@ model Tag { owner User @relation(fields: [ownerId], references: [id]) ownerId Int + createdAt DateTime @default(now()) + updatedAt DateTime @updatedAt @default(now()) + @@unique([name, ownerId]) }