Skip to content

Commit

Permalink
Update Schema and Include Seeds (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
oroth8 authored Apr 10, 2023
1 parent e1cc530 commit 47931e7
Show file tree
Hide file tree
Showing 17 changed files with 535 additions and 186 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ addons:
- libgconf-2-4
before_script:
# ensure application config template is copied, as the server requires these env-var configs to be available
- cp -n fe/config/application.template.yml fe/config/application.yml
- cp -n fe/config/application.template.yml fe/config/application.yml
64 changes: 54 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,64 @@
# Veritext Replacement Template

## Repository Setup
## Structure

`cp fe/config/application.template.yml fe/config/application.yml`
`yarn`
`yarn dev`
- `fe` - Frontend
- `config` - Configuration files
- `application.yml` - Application enviromental variables for both `fe` and `be` configuration
- `be` - Backend
- `prisma` - Postgres ORM
## Getting Started

## Features
1. Clone the repo
2. `yarn setup`
3. Configure `fe/config/application.yml` with your own local postgres connection url like `postgresql://username@localhost:5432/veritext_box`
4. Due to the way prisma loads env variables in development, you will need to make sure your `pg` connection url is set to `DATABASE_URL` in your `.env` file located at `be/prisma/.env`
5. `yarn db:migrate:dev`
6. `yarn db:seed` (optional)
7. `yarn dev`

- Seperate frontend and backend into their own resptective directories
- leverages yarn workspaces
### Troubleshooting Prisma
- If you are having trouble getting your `DATABASE_URL` to work, try running `yarn db:generate` and then `yarn db:migrate:dev` again.

## TODO
## Setting Up Postgres Locally

If you don't have postgres installed locally, you can use the following commands to get it set up.
```bash
brew install postgresql
brew services start postgresql
```

There are several guides to creating a database using the homebrew cli tool, but the following is a quick guide to get you started with pgAdmin4.

1. Install pgAdmin4
```bash
https://www.pgadmin.org/download/pgadmin-4-macos/
```

2. Open pgAdmin4
3. After opening pgAdmin4, you will be prompted to create a "master password". This is the password you will use to login to pgAdmin4. You can just click enter to skip this password step or you can create a password.
4. Click `Add New Server`
5. Under the `General` tab, give your database a name in the input field labeled `Name`
6. Click the `Connection` tab
7. Under `Host name/address`, enter `localhost`
8. Under `Port`, enter `5432`
9. Keep username as `postgres`
10. Keep password empty
11. Click `Save`

- [ ] Fix husky
- [ ] Remove `Procfile` and `app.json` (not needed for AWS)
Now you should be taken to the dashboard of your database. If you followed the steps above, your connection string should be `postgresql://postgres@localhost:5432/database_name`. You can use this connection string to connect to your database using the `DATABASE_URL` variable in your `.env` file.

## Resources

- [Prisma](https://www.prisma.io/)
- [Prisma Migrations](prisma.io/docs/concepts/components/prisma-migrate/migrate-development-production)
- [Backend-Bolierplate](https://github.com/ljlm0402/typescript-express-starter/blob/master/lib/prisma)
- [Frontend-Bolierplate](https://github.com/LaunchPadLab/client-template)

### Notion
- https://www.notion.so/launchpadlab/Dev-Resources-0dddfd58e59148608336bd393aca6a21
## TODO
- https://app.asana.com/0/1203247162912464/1204350186317579/f

## Heroku Production Hosted Link

Expand Down
Binary file not shown.
Binary file not shown.
13 changes: 10 additions & 3 deletions be/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
{
"name": "@veritext-replacement-template/be",
"name": "be",
"version": "1.0.0",
"license": "UNLICENSED",
"scripts": {
"dev": "nodemon server.js",
"server": "node server.js"
"generate": "prisma generate",
"gui": "yarn prisma studio",
"migrate:dev": "prisma migrate dev",
"migrate:reset": "prisma migrate reset",
"migrate:deploy": "prisma migrate deploy",
"server": "node server.js",
"seed": "node prisma/seed.js"
},
"dependencies": {
"@prisma/client": "^4.12.0",
"@veritext-replacement-template/fe": "1.0.0",
"fe": "1.0.0",
"bcrypt": "^5.1.0",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
Expand Down
3 changes: 3 additions & 0 deletions be/prisma/env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A .env file is needed to run prisma commands at /be/prisma/.env

DATABASE_URL="postgresql://postgres@localhost:5433/travis_ci_test"
70 changes: 0 additions & 70 deletions be/prisma/migrations/20230331150640_init/migration.sql

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
-- CreateEnum
CREATE TYPE "Repository" AS ENUM ('VAULT', 'EXHIBIT_SHARE');

-- CreateTable
CREATE TABLE "Folder" (
"id" SERIAL NOT NULL,
"parentFolderId" INTEGER,
"repository" "Repository" NOT NULL,
"name" TEXT NOT NULL,
"path" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Folder_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "File" (
"id" SERIAL NOT NULL,
"folderId" INTEGER NOT NULL,
"repository" "Repository" NOT NULL,
"name" TEXT NOT NULL,
"path" TEXT NOT NULL,
"url" TEXT NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL,

CONSTRAINT "File_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Folder" ADD CONSTRAINT "Folder_parentFolderId_fkey" FOREIGN KEY ("parentFolderId") REFERENCES "Folder"("id") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "File" ADD CONSTRAINT "File_folderId_fkey" FOREIGN KEY ("folderId") REFERENCES "Folder"("id") ON DELETE CASCADE ON UPDATE CASCADE;
80 changes: 16 additions & 64 deletions be/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -12,83 +12,35 @@ datasource db {

// 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
id Int @id @default(autoincrement())
parentFolderId Int?
parentFolder Folder? @relation("folderTree", fields: [parentFolderId], references: [id], onDelete: Cascade)
subFolders Folder[] @relation("folderTree")
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
name String
path String
files File[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

// File

model File {
id String @id @default(uuid())
parentFolderId Int
id Int @id @default(autoincrement())
folder Folder @relation(fields: [folderId], references: [id], onDelete: Cascade)
folderId Int
repository Repository
name String
url String
sequence Int
name String
path String
url String
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

// ENUMS

// File, Folder
enum Repository {
VAULT
EXHIBIT_SHARE
}

// Activity
enum ActionableType {
FILE
FOLDER
}

// PermissionRule
enum ActivityType {
CREATED
VIEWED
DOWNLOADED
MOVED
DELETED
RENAMED
}
16 changes: 16 additions & 0 deletions be/prisma/seed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import prisma from './seeds/prismaClient.js'
import folderSeeder from './seeds/seeders/folderSeeder.js'
import fileSeeder from './seeds/seeders/fileSeeder.js'

const load = async () => {
try {
await folderSeeder()
await fileSeeder()
} catch (e) {
console.error(e)
process.exit(1)
} finally {
await prisma.$disconnect()
}
}
load()
Loading

0 comments on commit 47931e7

Please sign in to comment.