Skip to content

Commit

Permalink
add prisma
Browse files Browse the repository at this point in the history
  • Loading branch information
oroth8 committed Apr 3, 2023
1 parent 95cd582 commit 0747a54
Show file tree
Hide file tree
Showing 11 changed files with 232 additions and 0 deletions.
2 changes: 2 additions & 0 deletions be/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Keep environment variables out of version control
.env
1 change: 1 addition & 0 deletions be/node_modules/.bin/prisma

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions be/node_modules/.bin/prisma2

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions be/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
70 changes: 70 additions & 0 deletions be/prisma/migrations/20230331150640_init/migration.sql
Original file line number Diff line number Diff line change
@@ -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;
3 changes: 3 additions & 0 deletions be/prisma/migrations/migration_lock.toml
Original file line number Diff line number Diff line change
@@ -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"
94 changes: 94 additions & 0 deletions be/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -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
}
Empty file.
15 changes: 15 additions & 0 deletions be/src/lib/prisma.js
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions fe/config/application.template.yml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]":
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/[email protected]":
version "7.45.0"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.45.0.tgz#01f347d0d1b42451b340b32b12923dc22e042d27"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 0747a54

Please sign in to comment.