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

Installed Prisma ORM #5

Merged
merged 10 commits into from
Sep 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 1 addition & 2 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
POSTGRES_USER=user
POSTGRES_PASSWORD=password
# Nothing here yet
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ The repository is organized as follows:
bun install
```

3. Create env file
3. Create env files

```sh
cp .env.example .env
bun env:setup
```

4. Start the dev enviornment:
Expand Down Expand Up @@ -90,3 +90,4 @@ The following scripts are available in the root `package.json`:
- `typecheck`: Run TypeScript type checks.
- `shad-add`: Add a new UI component using Shadcn.
- `generate:package`: Generate a new package.
- `env:setup`: Setup the default env vars
18 changes: 18 additions & 0 deletions apps/db/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Preferred on Mac:
POSTGRES_USER="user"
POSTGRES_PASSWORD="password"
POSTGRES_DATABASE="good-dog"
POSTGRES_PORT=5432

DATABASE_URL="postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@localhost:${POSTGRES_PORT}/${POSTGRES_DATABASE}"


# Windows Version:
# Strings must be in double quotes on Windows, and template strings cannot be used

# POSTGRES_USER="user"
# POSTGRES_PASSWORD="password"
# POSTGRES_DATABASE="good-dog"
# POSTGRES_PORT=5432

# DATABASE_URL="postgresql://user:password@localhost:5432/good-dog"
8 changes: 4 additions & 4 deletions apps/db/compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ services:
image: postgres:15
restart: always
environment:
POSTGRES_DB: "good-dog"
POSTGRES_USER: "${POSTGRES_USER:-username}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD:-password}"
POSTGRES_DB: "${POSTGRES_DATABASE}"
POSTGRES_USER: "${POSTGRES_USER}"
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
volumes:
- ../../volumes/postgres:/var/lib/postgresql/data
ports:
- "${POSTGRES_PORT:-5432}:5432"
- "${POSTGRES_PORT}:5432"
23 changes: 22 additions & 1 deletion apps/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@
"version": "0.0.0",
"private": true,
"type": "module",
"exports": {
".": "./src/index.ts"
},
"scripts": {
"dev": "docker-compose -f compose.yml up",
"up": "docker-compose -f compose.yml up -d",
"down": "docker-compose -f compose.yml down",
"clean": "rm -rf .turbo node_modules",
"format": "prettier --check . --ignore-path ../../.gitignore"
"format": " prisma format && prettier --check . --ignore-path ../../.gitignore",
"push": "prisma db push",
"studio": "prisma studio",
"generate": "prisma generate",
"migrate": "prisma migrate dev",
"env": "cp .env.example .env"
},
"dependencies": {
"@prisma/client": "5.19.1"
},
"devDependencies": {
"@good-dog/eslint": "workspace:*",
"@good-dog/prettier": "workspace:*",
"@good-dog/typescript": "workspace:*",
"@types/bun": "^1.1.10",
"eslint": "9.10.0",
"prettier": "3.2.5",
"prisma": "^5.19.1",
"typescript": "5.4.5"
}
}
21 changes: 21 additions & 0 deletions apps/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions?
// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

// Temporary
model User {
id Int @id @default(autoincrement())
email String @unique
name String?
}
3 changes: 3 additions & 0 deletions apps/db/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { PrismaClient } from "@prisma/client";

export const prisma = new PrismaClient();
8 changes: 8 additions & 0 deletions apps/db/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "@good-dog/typescript/base.json",
"compilerOptions": {
"tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json"
},
"include": ["*.ts", "src"],
"exclude": ["node_modules"]
}
Binary file modified bun.lockb
Binary file not shown.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
"lint:fix": "turbo run lint --continue -- --fix --cache --cache-location node_modules/.cache/.eslintcache",
"lint:ws": "bunx sherif@latest",
"__MISC______________": "",
"postinstall": "bun run lint:ws",
"postinstall": "turbo run generate && bun run lint:ws",
"typecheck": "turbo run typecheck",
"shad-add": "turbo run ui-add",
"generate:package": "turbo generate package"
"generate:package": "turbo generate package",
"env:setup": "turbo run env"
},
"prettier": "@good-dog/prettier",
"devDependencies": {
Expand Down
7 changes: 7 additions & 0 deletions test/db/prisma.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { expect, test } from "bun:test";

import { prisma } from "@good-dog/db";

test("prisma is defined", () => {
expect(prisma).toBeDefined();
});
1 change: 1 addition & 0 deletions test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"typecheck": "tsc --noEmit --emitDeclarationOnly false"
},
"devDependencies": {
"@good-dog/db": "workspace:*",
"@good-dog/eslint": "workspace:*",
"@good-dog/prettier": "workspace:*",
"@good-dog/typescript": "workspace:*",
Expand Down
6 changes: 5 additions & 1 deletion turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
},
"generate": {
"cache": false,
"interactive": true
"interactive": false
},
"migrate": {
"cache": false,
Expand All @@ -68,6 +68,10 @@
"down": {
"cache": false,
"interactive": false
},
"env": {
"interactive": false,
"cache": false
}
},
"globalEnv": ["SKIP_ENV_VALIDATION"],
Expand Down