@cocrepo/prisma
v1.0.11
Published
Prisma schema and client for the core project
Readme
@cocrepo/db
Prisma 스키마 및 데이터베이스 클라이언트를 제공하는 패키지입니다.
중요: 이 패키지는 리팩토링되어 Prisma 전용 패키지가 되었습니다. DTO, Entity, Enum, Decorator는 별도 패키지로 분리되었습니다.
마이그레이션 가이드: docs/SCHEMA-REFACTORING.md
분리된 패키지
| 기능 | 새 패키지 |
| --------------------- | -------------------- |
| Data Transfer Objects | @cocrepo/dto |
| 엔티티 정의 | @cocrepo/entity |
| 열거형 | @cocrepo/enum |
| 데코레이터 | @cocrepo/decorator |
| 스키마 상수 | @cocrepo/constant |
현재 패키지 역할
- Prisma 스키마 관리
- 타입 안전 데이터베이스 클라이언트
- 마이그레이션 관리
- 시드 데이터
주요 기능
- Prisma 멀티 파일 스키마 지원
- 타입 안전 데이터베이스 클라이언트
- 공통 데이터베이스 유틸리티
- 백엔드 서비스 간 공유 타입
Installation
This package is part of the workspace and is automatically available to other packages.
Usage
Basic Usage
import { PrismaClient, prisma } from "@shared/prisma";
// Use the default instance
const users = await prisma.user.findMany();
// Or create your own instance
const customClient = new PrismaClient();Type Exports
import type { User, CreateInput, UpdateInput } from "@shared/prisma";
// Use generated Prisma types
type UserData = User;
// Use utility types
type CreateUserInput = CreateInput<User>;
type UpdateUserInput = UpdateInput<User>;Scripts
Development
pnpm generate- Generate Prisma client from multi-file schemapnpm build- Build the packagepnpm start:dev- Build in watch mode
Database Operations
pnpm db:push- Push schema to databasepnpm db:pull- Pull schema from databasepnpm db:studio- Open Prisma Studiopnpm db:migrate- Create and apply migrationspnpm db:migrate:deploy- Deploy migrations to productionpnpm db:reset- Reset database and re-run migrationspnpm db:seed- Seed the database
Multi-File Schema Architecture (Prisma Official)
This project uses Prisma's official multi-file schema support (GA since Prisma 6.7.0) to organize models into separate domain files:
prisma/
├── schema/ # Multi-file schema directory
│ ├── _base.prisma # Generator and datasource configuration
│ ├── core.prisma # Core business models (Tenant, Category, etc.)
│ ├── user.prisma # User and authentication models
│ ├── role.prisma # Role-based access control models
│ ├── space.prisma # Space management models
│ ├── file.prisma # File management models
│ └── task.prisma # Task and timeline models
├── migrations/ # Database migrations
└── seed.ts # Database seeding scriptHow It Works
Prisma automatically combines all .prisma files in the prisma/schema/ directory:
- Edit any schema file: Make changes to files in
prisma/schema/ - Generate client: Run
pnpm generate - Create migrations: Run
pnpm db:migrate
✅ No merge script needed - Prisma handles it natively!
Configuration
The multi-file schema is configured in prisma.config.ts:
export default defineConfig({
schema: "./prisma/schema", // Points to directory, not file
// ...
});Schema Statistics
Current schema contains:
- 30 models across 6 domain files
- 14 enums for type safety
- Automatic cross-file model referencing (no imports needed)
Environment Variables
Required environment variables:
DATABASE_URL- PostgreSQL connection stringDIRECT_URL- Direct PostgreSQL connection string (optional)
