diff --git a/.env.example b/.env.example index 19e2636..7e5c397 100644 --- a/.env.example +++ b/.env.example @@ -1,2 +1 @@ -POSTGRES_USER=user -POSTGRES_PASSWORD=password \ No newline at end of file +# Nothing here yet \ No newline at end of file diff --git a/README.md b/README.md index 1d0feae..06a045b 100644 --- a/README.md +++ b/README.md @@ -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: @@ -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 diff --git a/apps/db/.env.example b/apps/db/.env.example new file mode 100644 index 0000000..7af0140 --- /dev/null +++ b/apps/db/.env.example @@ -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" \ No newline at end of file diff --git a/apps/db/compose.yml b/apps/db/compose.yml index dfff637..1294b6a 100644 --- a/apps/db/compose.yml +++ b/apps/db/compose.yml @@ -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" diff --git a/apps/db/package.json b/apps/db/package.json index 3dd626b..fc7b18f 100644 --- a/apps/db/package.json +++ b/apps/db/package.json @@ -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" } } diff --git a/apps/db/prisma/schema.prisma b/apps/db/prisma/schema.prisma new file mode 100644 index 0000000..7f7a603 --- /dev/null +++ b/apps/db/prisma/schema.prisma @@ -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? +} diff --git a/apps/db/src/index.ts b/apps/db/src/index.ts new file mode 100644 index 0000000..901f3a0 --- /dev/null +++ b/apps/db/src/index.ts @@ -0,0 +1,3 @@ +import { PrismaClient } from "@prisma/client"; + +export const prisma = new PrismaClient(); diff --git a/apps/db/tsconfig.json b/apps/db/tsconfig.json new file mode 100644 index 0000000..3db9f98 --- /dev/null +++ b/apps/db/tsconfig.json @@ -0,0 +1,8 @@ +{ + "extends": "@good-dog/typescript/base.json", + "compilerOptions": { + "tsBuildInfoFile": "node_modules/.cache/tsbuildinfo.json" + }, + "include": ["*.ts", "src"], + "exclude": ["node_modules"] +} diff --git a/bun.lockb b/bun.lockb index 455a674..37d6e06 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index ca40ac5..cc4ab2f 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/test/db/prisma.test.ts b/test/db/prisma.test.ts new file mode 100644 index 0000000..d6a754d --- /dev/null +++ b/test/db/prisma.test.ts @@ -0,0 +1,7 @@ +import { expect, test } from "bun:test"; + +import { prisma } from "@good-dog/db"; + +test("prisma is defined", () => { + expect(prisma).toBeDefined(); +}); diff --git a/test/package.json b/test/package.json index 44f3622..67adc42 100644 --- a/test/package.json +++ b/test/package.json @@ -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:*", diff --git a/turbo.json b/turbo.json index 29160a5..c5a89d9 100644 --- a/turbo.json +++ b/turbo.json @@ -47,7 +47,7 @@ }, "generate": { "cache": false, - "interactive": true + "interactive": false }, "migrate": { "cache": false, @@ -68,6 +68,10 @@ "down": { "cache": false, "interactive": false + }, + "env": { + "interactive": false, + "cache": false } }, "globalEnv": ["SKIP_ENV_VALIDATION"],