From 0747a5417704abbd3bfd4bc1593bd2e1d5de1a79 Mon Sep 17 00:00:00 2001 From: Owen Roth Date: Mon, 3 Apr 2023 08:12:03 -0600 Subject: [PATCH] add prisma --- be/.gitignore | 2 + be/node_modules/.bin/prisma | 1 + be/node_modules/.bin/prisma2 | 1 + be/package.json | 2 + .../20230331150640_init/migration.sql | 70 ++++++++++++++ be/prisma/migrations/migration_lock.toml | 3 + be/prisma/schema.prisma | 94 +++++++++++++++++++ be/src/controllers/users.controller.js | 0 be/src/lib/prisma.js | 15 +++ fe/config/application.template.yml | 20 ++++ yarn.lock | 24 +++++ 11 files changed, 232 insertions(+) create mode 100644 be/.gitignore create mode 120000 be/node_modules/.bin/prisma create mode 120000 be/node_modules/.bin/prisma2 create mode 100644 be/prisma/migrations/20230331150640_init/migration.sql create mode 100644 be/prisma/migrations/migration_lock.toml create mode 100644 be/prisma/schema.prisma create mode 100644 be/src/controllers/users.controller.js create mode 100644 be/src/lib/prisma.js create mode 100644 fe/config/application.template.yml diff --git a/be/.gitignore b/be/.gitignore new file mode 100644 index 0000000..653851a --- /dev/null +++ b/be/.gitignore @@ -0,0 +1,2 @@ +# Keep environment variables out of version control +.env diff --git a/be/node_modules/.bin/prisma b/be/node_modules/.bin/prisma new file mode 120000 index 0000000..52af877 --- /dev/null +++ b/be/node_modules/.bin/prisma @@ -0,0 +1 @@ +../../../node_modules/prisma/build/index.js \ No newline at end of file diff --git a/be/node_modules/.bin/prisma2 b/be/node_modules/.bin/prisma2 new file mode 120000 index 0000000..52af877 --- /dev/null +++ b/be/node_modules/.bin/prisma2 @@ -0,0 +1 @@ +../../../node_modules/prisma/build/index.js \ No newline at end of file diff --git a/be/package.json b/be/package.json index 89abf20..627dda5 100644 --- a/be/package.json +++ b/be/package.json @@ -5,9 +5,11 @@ "server": "node server.js" }, "dependencies": { + "@prisma/client": "^4.12.0", "@veritext-replacement-template/fe": "1.0.0", "cookie-parser": "^1.4.6", "cors": "^2.8.5", + "prisma": "^4.12.0", "winston": "^3.8.2", "winston-daily-rotate-file": "^4.7.1" }, diff --git a/be/prisma/migrations/20230331150640_init/migration.sql b/be/prisma/migrations/20230331150640_init/migration.sql new file mode 100644 index 0000000..9fbbeb4 --- /dev/null +++ b/be/prisma/migrations/20230331150640_init/migration.sql @@ -0,0 +1,70 @@ +-- CreateEnum +CREATE TYPE "ActionType" AS ENUM ('CREATE', 'VIEW', 'DELETE'); + +-- CreateEnum +CREATE TYPE "Repository" AS ENUM ('VAULT', 'EXHIBIT_SHARE'); + +-- CreateEnum +CREATE TYPE "ActionableType" AS ENUM ('FILE', 'FOLDER'); + +-- CreateEnum +CREATE TYPE "ActivityType" AS ENUM ('CREATED', 'VIEWED', 'DOWNLOADED', 'MOVED', 'DELETED', 'RENAMED'); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "admin" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Activity" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "activityType" "ActivityType" NOT NULL, + "actionableType" "ActionableType" NOT NULL, + + CONSTRAINT "Activity_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Folder" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "path" TEXT NOT NULL, + "repository" "Repository" NOT NULL, + + CONSTRAINT "Folder_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "PermissionRule" ( + "id" TEXT NOT NULL, + "folderId" TEXT NOT NULL, + "actionType" "ActionType" NOT NULL, + + CONSTRAINT "PermissionRule_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "File" ( + "id" TEXT NOT NULL, + "parentFolderId" INTEGER NOT NULL, + "repository" "Repository" NOT NULL, + "name" TEXT NOT NULL, + "url" TEXT NOT NULL, + "sequence" INTEGER NOT NULL, + "path" TEXT NOT NULL, + + CONSTRAINT "File_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Activity_userId_key" ON "Activity"("userId"); + +-- AddForeignKey +ALTER TABLE "Activity" ADD CONSTRAINT "Activity_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "PermissionRule" ADD CONSTRAINT "PermissionRule_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE RESTRICT ON UPDATE CASCADE; \ No newline at end of file diff --git a/be/prisma/migrations/migration_lock.toml b/be/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/be/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/be/prisma/schema.prisma b/be/prisma/schema.prisma new file mode 100644 index 0000000..44e6eb4 --- /dev/null +++ b/be/prisma/schema.prisma @@ -0,0 +1,94 @@ +// This is your Prisma schema file, +// learn more about it in the docs: https://pris.ly/d/prisma-schema + +generator client { + provider = "prisma-client-js" +} + +datasource db { + provider = "postgresql" + url = env("DATABASE_URL") +} + +// MODELS +// Refrence https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#default + +// User + +model User { + id String @id @default(uuid()) + admin Boolean @default(false) + activities Activity[] +} + +// Activity + +model Activity { + id String @id @default(uuid()) + user User @relation(fields: [userId], references: [id]) + userId String @unique + activityType ActivityType + actionableType ActionableType +} + + +// Folder + +model Folder { + id String @id @default(uuid()) + name String + path String + repository Repository + permissions PermissionRule[] +} + +// Permissions + +model PermissionRule { + id String @id @default(uuid()) + folder Folder @relation(fields: [folderId], references: [id]) + folderId String + actionType ActionType +} + +enum ActionType { + CREATE + VIEW + DELETE +} + +// File + +model File { + id String @id @default(uuid()) + parentFolderId Int + repository Repository + name String + url String + sequence Int + path String +} + +// ENUMS + +// File, Folder +enum Repository { + VAULT + EXHIBIT_SHARE +} + +// Activity +enum ActionableType { + FILE + FOLDER +} + +// PermissionRule +enum ActivityType { + CREATED + VIEWED + DOWNLOADED + MOVED + DELETED + RENAMED +} \ No newline at end of file diff --git a/be/src/controllers/users.controller.js b/be/src/controllers/users.controller.js new file mode 100644 index 0000000..e69de29 diff --git a/be/src/lib/prisma.js b/be/src/lib/prisma.js new file mode 100644 index 0000000..413e5e8 --- /dev/null +++ b/be/src/lib/prisma.js @@ -0,0 +1,15 @@ +// lib/prisma.js +import { PrismaClient } from '@prisma/client' + +let prisma + +if (process.env.NODE_ENV === 'production') { + prisma = new PrismaClient() +} else { + if (!global.prisma) { + global.prisma = new PrismaClient() + } + prisma = global.prisma +} + +export default prisma diff --git a/fe/config/application.template.yml b/fe/config/application.template.yml new file mode 100644 index 0000000..495d749 --- /dev/null +++ b/fe/config/application.template.yml @@ -0,0 +1,20 @@ +# BE +# PORT +PORT: 8080 + +# DATABASE +# DATABASE_URL: mysql://root:password@localhost:3306/dev + +# TOKEN +# SECRET_KEY: secretKey + +# LOG +LOG_FORMAT: dev +LOG_DIR: ../logs + +# CORS +ORIGIN: "*" +CREDENTIALS: true + +# DATABASE +DATABASE_URL: your-database-url \ No newline at end of file diff --git a/yarn.lock b/yarn.lock index 53e4802..50f13db 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1733,6 +1733,23 @@ resolved "https://registry.yarnpkg.com/@popperjs/core/-/core-2.11.7.tgz#ccab5c8f7dc557a52ca3288c10075c9ccd37fff7" integrity sha512-Cr4OjIkipTtcXKjAsm8agyleBuDHvxzeBoa1v543lbv1YaIwQjESsVcmjiWiPEbC1FIeHOG/Op9kdCmAmiS3Kw== +"@prisma/client@^4.12.0": + version "4.12.0" + resolved "https://registry.yarnpkg.com/@prisma/client/-/client-4.12.0.tgz#119b692888b1fe0fd3305c7d0e0ac48520aa6839" + integrity sha512-j9/ighfWwux97J2dS15nqhl60tYoH8V0IuSsgZDb6bCFcQD3fXbXmxjYC8GHhIgOk3lB7Pq+8CwElz2MiDpsSg== + dependencies: + "@prisma/engines-version" "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7" + +"@prisma/engines-version@4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7": + version "4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7" + resolved "https://registry.yarnpkg.com/@prisma/engines-version/-/engines-version-4.12.0-67.659ef412370fa3b41cd7bf6e94587c1dfb7f67e7.tgz#51a1cc5c886564b542acde64a873645d0dee2566" + integrity sha512-JIHNj5jlXb9mcaJwakM0vpgRYJIAurxTUqM0iX0tfEQA5XLZ9ONkIckkhuAKdAzocZ+80GYg7QSsfpjg7OxbOA== + +"@prisma/engines@4.12.0": + version "4.12.0" + resolved "https://registry.yarnpkg.com/@prisma/engines/-/engines-4.12.0.tgz#68d99078b70b2d9c339d0e8cbf2e99f00b72aa8c" + integrity sha512-0alKtnxhNB5hYU+ymESBlGI4b9XrGGSdv7Ud+8TE/fBNOEhIud0XQsAR+TrvUZgS4na5czubiMsODw0TUrgkIA== + "@sentry-internal/tracing@7.45.0": version "7.45.0" resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.45.0.tgz#01f347d0d1b42451b340b32b12923dc22e042d27" @@ -7432,6 +7449,13 @@ pretty-format@^29.5.0: ansi-styles "^5.0.0" react-is "^18.0.0" +prisma@^4.12.0: + version "4.12.0" + resolved "https://registry.yarnpkg.com/prisma/-/prisma-4.12.0.tgz#1080eda951928cb3b0274ad29da9ae4f93143d68" + integrity sha512-xqVper4mbwl32BWzLpdznHAYvYDWQQWK2tBfXjdUD397XaveRyAP7SkBZ6kFlIg8kKayF4hvuaVtYwXd9BodAg== + dependencies: + "@prisma/engines" "4.12.0" + process-nextick-args@~2.0.0: version "2.0.1" resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-2.0.1.tgz#7820d9b16120cc55ca9ae7792680ae7dba6d7fe2"