Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup Prisma as our ORM (Object-Relational Mapper) #21

Merged
merged 30 commits into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
eb0455d
enh: install prisma
marco-souza May 18, 2023
f2e944a
fea: setup prisma
marco-souza May 18, 2023
14ee29e
fea: modeling prisma data
marco-souza May 18, 2023
f0a4bc9
fea: add diagram generator
marco-souza May 19, 2023
eb63ad9
fea: use custom .env.local file
marco-souza May 19, 2023
abb9b15
fea: migration init
marco-souza May 19, 2023
0e5dd29
fix: generate erd as markdown
marco-souza May 20, 2023
006fe18
enh: ignore .env files
marco-souza May 20, 2023
dc62936
fix: update db initial migration
marco-souza May 20, 2023
bb613c2
fea: setup docker to run app & db
marco-souza May 20, 2023
19e8f49
fix: ignore all .env files
marco-souza May 21, 2023
2c02f2b
fix: update env example
marco-souza May 21, 2023
3a32cba
fea: add vscode db connection
marco-souza May 30, 2023
5fcbcc0
enh: cleanup prisma configs
marco-souza May 30, 2023
96266b4
enh: improve docker setup
marco-souza May 30, 2023
0fa55f6
enh: share credentials between app and db
marco-souza May 30, 2023
3833175
enh: add utils commands
marco-souza May 30, 2023
1e66ace
enh: update dependencies
marco-souza May 30, 2023
64b7ece
fix: docker ignore node_modules
marco-souza May 30, 2023
7d933dc
fea: setup jest for testing
marco-souza May 30, 2023
d0537d7
fea: setup test container
marco-souza May 30, 2023
76cc5b1
fea: test get user by username
marco-souza May 30, 2023
72e6445
enh: improve npm scripts for docker
marco-souza May 30, 2023
4a6a27b
fix: docker networking issue
marco-souza May 30, 2023
8a7173d
fix: id creation for users
marco-souza May 30, 2023
685f9c1
fea: add test for getting users tasks
marco-souza May 30, 2023
0733f7e
fea: add test users doing a task
marco-souza May 30, 2023
f16cda9
fea: add test for getting dependent tasks
marco-souza May 30, 2023
6519e59
enh: make username unique
marco-souza May 30, 2023
d5adf93
fea: add test case for adding repeated username
marco-souza May 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# Next Auth
NEXTAUTH_SECRET=mypassword
NEXTAUTH_URL="http://localhost:3000" # dev only
NEXTAUTH_URL_INTERNAL="http://localhost:3000" # dev only

# Google credentials
GOOGLE_CLIENT_ID=*****
GOOGLE_CLIENT_SECRET=*****

# Github credentials
GITHUB_CLIENT_ID=*****
GITHUB_CLIENT_SECRET=*****
9 changes: 9 additions & 0 deletions .env.postgres
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# postgres
POSTGRES_USER="podcodar"
POSTGRES_PASSWORD="my-password"
POSTGRES_DB="podcodar-app-db"

# prisma
POSTGRES_HOST="db"
POSTGRES_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}"

9 changes: 9 additions & 0 deletions .env.postgres.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# postgres
POSTGRES_USER="podcodar"
POSTGRES_PASSWORD="my-password"
POSTGRES_DB="podcodar-app-test-db"

# prisma
POSTGRES_HOST="db"
POSTGRES_URL="postgres://${POSTGRES_USER}:${POSTGRES_PASSWORD}@${POSTGRES_HOST}:5432/${POSTGRES_DB}"

5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "@podcodar/eslint-config-next"
"extends": "@podcodar/eslint-config-next",
"env": {
"jest": true
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
.env*
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dist
.next
node_modules
prisma/*
24 changes: 23 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true
"typescript.enablePromptUseWorkspaceTsdk": true,
"sqltools.connections": [
{
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "podcodar-local-db",
"database": "podcodar-app-db",
"username": "podcodar",
"password": "my-password"
},
{
"previewLimit": 50,
"server": "localhost",
"port": 5432,
"driver": "PostgreSQL",
"name": "podcoadr-test-db",
"username": "podcodar",
"database": "podcodar-app-test-db",
"password": "my-password"
}
]
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## base stage
FROM node:lts-alpine as base
WORKDIR /app
RUN npm i -g npm pnpm concurrently

## dependencies stage
FROM base as dependencies
COPY package.json pnpm-lock* ./
COPY prisma ./prisma
RUN pnpm i && pnpm db:generate

# development stage
FROM base as development
COPY . .
COPY --from=dependencies /app/node_modules ./node_modules
# startup command
CMD pnpm db:migrate dev && pnpm dk:start
51 changes: 51 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
version: "3.8"

services:
app:
build:
context: .
target: development
env_file: .env.postgres
restart: always
ports:
- "3000:3000" # app
- "5555:5555" # studio
volumes:
- .:/app
- /app/node_modules
depends_on:
- db

integration-test:
build:
context: .
target: development
container_name: "e2e-test"
env_file: .env.postgres.test
command:
- /bin/sh
- -c
- |
pnpm db:migrate reset --force
pnpm db:migrate dev
pnpm test
volumes:
- .:/app
- /app/node_modules
depends_on:
- db

db:
image: postgres
env_file: .env.postgres
ports:
- "5432:5432"
volumes:
- db:/var/lib/postgresql/data

networks:
default:
name: podcodar-app

volumes:
db:
21 changes: 21 additions & 0 deletions jest.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import nextJest from "next/jest.js";

const createJestConfig = nextJest({
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment
dir: "./",
});

// Add any custom config to be passed to Jest
/** @type {import('jest').Config} */
const config = {
// Add more setup options before each test is run
// setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
testEnvironment: "jest-environment-jsdom",
moduleNameMapper: {
"^@/(.*)$": "<rootDir>/src/$1",
}

};

// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async
export default createJestConfig(config);
31 changes: 26 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,52 @@
"fmt": "prettier --write . && next lint --fix",
"lint-staged": "lint-staged",
"lint": "next lint",
"analyze": "ANALYZE=true yarn build",
"test": "jest --watchAll",
"analyze": "ANALYZE=true pnpm build",
"db:generate": "prisma generate",
"db:migrate": "prisma migrate",
"db:studio": "prisma studio",
"dk:start": "concurrently 'pnpm dev' 'pnpm db:studio --browser none'",
"app:up": "docker-compose up app",
"e2e:up": "docker-compose up integration-test",
"down": "docker-compose down",
"logs": "docker-compose logs",
"shell": "docker-compose exec app /bin/sh",
"prepare": "husky install"
},
"dependencies": {
"@headlessui/react": "^1.7.14",
"@heroicons/react": "^2.0.18",
"@next/bundle-analyzer": "^13.4.2",
"@next/bundle-analyzer": "^13.4.4",
"@types/node": "18.16.3",
"@types/react": "18.2.1",
"@types/react-dom": "18.2.3",
"eslint": "8.39.0",
"eslint-config-next": "13.4.1",
"next": "13.4.1",
"next": "13.4.4",
"next-auth": "^4.22.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "5.0.2"
},
"devDependencies": {
"@mermaid-js/mermaid-cli": "^10.1.0",
"@podcodar/eslint-config-next": "^1.6.0",
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^14.0.0",
"@types/jest": "^29.5.1",
"autoprefixer": "^10.4.14",
"concurrently": "^8.0.1",
"eslint-plugin-jest": "^27.2.1",
"husky": "^8.0.3",
"jest": "^29.5.0",
"jest-environment-jsdom": "^29.5.0",
"lint-staged": "^13.2.2",
"postcss": "^8.4.23",
"postcss": "^8.4.24",
"prettier": "^2.8.8",
"tailwindcss": "^3.3.2"
"prisma": "^4.15.0",
"prisma-erd-generator": "^1.7.0",
"tailwindcss": "^3.3.2",
"ts-node": "^10.9.1"
}
}
Loading