@trycompai/db 1.1.2 → 1.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/INTEGRATION_GUIDE.md +249 -0
- package/dist/{prisma/schema.prisma → schema.prisma} +2 -2
- package/package.json +17 -65
- package/dist/chunk-Y7OSPXHC.mjs +0 -7199
- package/dist/index.js +0 -7209
- package/dist/index.mjs +0 -13
- package/dist/prisma/functionDefinition.sql +0 -18
- package/dist/prisma/randomSecret.sql +0 -12
- package/dist/types.js +0 -7194
- package/dist/types.mjs +0 -9
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# Database Integration Guide
|
|
2
|
+
|
|
3
|
+
This package provides a combined Prisma schema file for your application.
|
|
4
|
+
|
|
5
|
+
## Schema-Only Distribution
|
|
6
|
+
|
|
7
|
+
The `@trycompai/db` package provides a single, combined schema file that includes all our database models. You generate your own Prisma client from this schema.
|
|
8
|
+
|
|
9
|
+
**What's included:**
|
|
10
|
+
- 📄 Combined Prisma schema file
|
|
11
|
+
- 🗂️ All database models and enums
|
|
12
|
+
- 🔗 Proper relationships and constraints
|
|
13
|
+
|
|
14
|
+
**Benefits:**
|
|
15
|
+
- ✅ Always up-to-date with your Prisma version
|
|
16
|
+
- ✅ No version conflicts
|
|
17
|
+
- ✅ You control the generator configuration
|
|
18
|
+
|
|
19
|
+
## Installation
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
# Using bun (recommended)
|
|
23
|
+
bun add @trycompai/db @prisma/client
|
|
24
|
+
bun add -D prisma
|
|
25
|
+
|
|
26
|
+
# Using npm
|
|
27
|
+
npm install @trycompai/db @prisma/client
|
|
28
|
+
npm install -D prisma
|
|
29
|
+
|
|
30
|
+
# Using yarn
|
|
31
|
+
yarn add @trycompai/db @prisma/client
|
|
32
|
+
yarn add -D prisma
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## Setup
|
|
36
|
+
|
|
37
|
+
After installation, copy the schema file to your project and generate the Prisma client:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
# Copy the schema file
|
|
41
|
+
cp node_modules/@trycompai/db/dist/schema.prisma prisma/schema.prisma
|
|
42
|
+
|
|
43
|
+
# Add the generator block to your schema
|
|
44
|
+
echo "
|
|
45
|
+
generator client {
|
|
46
|
+
provider = \"prisma-client-js\"
|
|
47
|
+
output = \"./generated\"
|
|
48
|
+
}" >> prisma/schema.prisma
|
|
49
|
+
|
|
50
|
+
# Generate the Prisma client
|
|
51
|
+
npx prisma generate
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
Or create a setup script in your `package.json`:
|
|
55
|
+
|
|
56
|
+
```json
|
|
57
|
+
{
|
|
58
|
+
"scripts": {
|
|
59
|
+
"db:setup": "cp node_modules/@trycompai/db/dist/schema.prisma prisma/schema.prisma && echo '\ngenerator client {\n provider = \"prisma-client-js\"\n output = \"./generated\"\n}' >> prisma/schema.prisma && prisma generate",
|
|
60
|
+
"db:generate": "prisma generate",
|
|
61
|
+
"db:migrate": "prisma migrate dev",
|
|
62
|
+
"db:studio": "prisma studio"
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Creating Your Database Client
|
|
68
|
+
|
|
69
|
+
Create a database client in your project:
|
|
70
|
+
|
|
71
|
+
```typescript
|
|
72
|
+
// lib/db.ts (or wherever you prefer)
|
|
73
|
+
import { PrismaClient } from '../prisma/generated';
|
|
74
|
+
|
|
75
|
+
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
|
76
|
+
|
|
77
|
+
export const db = globalForPrisma.prisma || new PrismaClient();
|
|
78
|
+
|
|
79
|
+
if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = db;
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Git Configuration
|
|
83
|
+
|
|
84
|
+
The Prisma client is generated to `src/db/generated/` and is automatically added to your `.gitignore`:
|
|
85
|
+
|
|
86
|
+
```
|
|
87
|
+
# Generated Prisma Client
|
|
88
|
+
src/db/generated/
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
> **💡 Note**: The file structure and setup is identical for both standalone and monorepo installations. The only difference is the schema source (combined schema from npm package vs. individual schema files from workspace) during the initial setup process.
|
|
92
|
+
|
|
93
|
+
⚠️ **Important**: Never commit the generated Prisma client - it's generated fresh on each install and build.
|
|
94
|
+
|
|
95
|
+
## Environment Setup
|
|
96
|
+
|
|
97
|
+
Create a `.env` file in your project root:
|
|
98
|
+
|
|
99
|
+
```env
|
|
100
|
+
DATABASE_URL="postgresql://username:password@localhost:5432/database"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## Usage
|
|
104
|
+
|
|
105
|
+
Import and use the database client in your application:
|
|
106
|
+
|
|
107
|
+
```typescript
|
|
108
|
+
// Import the database client
|
|
109
|
+
import { db } from '@trycompai/db';
|
|
110
|
+
|
|
111
|
+
// Import types
|
|
112
|
+
import type { User, Organization, Departments } from '@trycompai/db/types';
|
|
113
|
+
|
|
114
|
+
// Query examples
|
|
115
|
+
const users = await db.user.findMany();
|
|
116
|
+
const organizations = await db.organization.findMany();
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Available Models
|
|
120
|
+
|
|
121
|
+
This package includes schemas for:
|
|
122
|
+
|
|
123
|
+
- 👤 **Authentication**: Users, Sessions, Accounts, Members
|
|
124
|
+
- 🏢 **Organizations**: Organizations, Invitations, Onboarding
|
|
125
|
+
- 📋 **Policies**: Policies, Policy Templates, Departments
|
|
126
|
+
- 🎯 **Tasks**: Tasks, Task Templates, Task Status
|
|
127
|
+
- 🔒 **Controls**: Controls, Framework Requirements
|
|
128
|
+
- 📊 **Risks**: Risk Management, Risk Categories
|
|
129
|
+
- 🏭 **Vendors**: Vendor Management, Contacts
|
|
130
|
+
- 🔧 **Integrations**: Third-party Integrations, Results
|
|
131
|
+
- 💬 **Comments**: Comments, Attachments
|
|
132
|
+
- 🔑 **API Keys**: API Key Management
|
|
133
|
+
- 📝 **Audit Logs**: Activity Tracking
|
|
134
|
+
|
|
135
|
+
## Commands
|
|
136
|
+
|
|
137
|
+
```bash
|
|
138
|
+
# Generate Prisma client (if needed)
|
|
139
|
+
bunx prisma generate --schema=src/db/schema.prisma
|
|
140
|
+
|
|
141
|
+
# View database in Prisma Studio
|
|
142
|
+
bunx prisma studio --schema=src/db/schema.prisma
|
|
143
|
+
|
|
144
|
+
# Reset database (careful!)
|
|
145
|
+
bunx prisma migrate reset --schema=src/db/schema.prisma
|
|
146
|
+
|
|
147
|
+
# Push schema changes (development)
|
|
148
|
+
bunx prisma db push --schema=src/db/schema.prisma
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## TypeScript Integration
|
|
152
|
+
|
|
153
|
+
All types are automatically generated and available:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
import type {
|
|
157
|
+
User,
|
|
158
|
+
Organization,
|
|
159
|
+
Policy,
|
|
160
|
+
Risk,
|
|
161
|
+
Task,
|
|
162
|
+
Departments,
|
|
163
|
+
RiskStatus,
|
|
164
|
+
PolicyStatus,
|
|
165
|
+
} from '@/db/types';
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
## Troubleshooting
|
|
169
|
+
|
|
170
|
+
### Schema not found
|
|
171
|
+
|
|
172
|
+
If the schema wasn't copied automatically, run:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
bunx @trycompai/db postinstall
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Client generation fails
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
# Manually generate the client
|
|
182
|
+
bunx prisma generate --schema=src/db/schema.prisma
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Generated files appearing in git
|
|
186
|
+
|
|
187
|
+
If you see generated Prisma files in your git status, add this to your `.gitignore`:
|
|
188
|
+
|
|
189
|
+
```gitignore
|
|
190
|
+
# Generated Prisma Client
|
|
191
|
+
src/db/generated/
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Then clean up any tracked files:
|
|
195
|
+
|
|
196
|
+
```bash
|
|
197
|
+
git rm -r --cached src/db/generated/
|
|
198
|
+
git commit -m "Remove generated Prisma files from tracking"
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
### Database connection issues
|
|
202
|
+
|
|
203
|
+
1. Verify your `DATABASE_URL` in `.env`
|
|
204
|
+
2. Ensure your database is running
|
|
205
|
+
3. Check network connectivity
|
|
206
|
+
|
|
207
|
+
## Framework Compatibility
|
|
208
|
+
|
|
209
|
+
This package works with:
|
|
210
|
+
|
|
211
|
+
- ✅ Next.js (App Router & Pages Router)
|
|
212
|
+
- ✅ Remix
|
|
213
|
+
- ✅ Express.js
|
|
214
|
+
- ✅ Fastify
|
|
215
|
+
- ✅ Any Node.js framework
|
|
216
|
+
|
|
217
|
+
## Production Deployment
|
|
218
|
+
|
|
219
|
+
The postinstall script automatically runs during deployment on:
|
|
220
|
+
|
|
221
|
+
- ✅ Vercel (Node.js runtime)
|
|
222
|
+
- ✅ Railway (Docker containers)
|
|
223
|
+
- ✅ Render (Native Linux)
|
|
224
|
+
- ✅ AWS Lambda (Amazon Linux)
|
|
225
|
+
- ✅ Google Cloud Functions (Ubuntu-based)
|
|
226
|
+
- ✅ Docker (Debian/Alpine support)
|
|
227
|
+
|
|
228
|
+
**Cross-Platform Compatibility:**
|
|
229
|
+
The included binary targets ensure your app works across different deployment environments without additional configuration. The Prisma client will automatically select the correct binary for each platform.
|
|
230
|
+
|
|
231
|
+
For other platforms, ensure the postinstall script runs during your build process.
|
|
232
|
+
|
|
233
|
+
## Support
|
|
234
|
+
|
|
235
|
+
For issues or questions:
|
|
236
|
+
|
|
237
|
+
1. Check this integration guide
|
|
238
|
+
2. Verify your environment setup
|
|
239
|
+
3. Ensure all dependencies are installed
|
|
240
|
+
4. Check the Prisma documentation
|
|
241
|
+
|
|
242
|
+
## Schema Updates
|
|
243
|
+
|
|
244
|
+
When the `@trycompai/db` package is updated with new schema changes:
|
|
245
|
+
|
|
246
|
+
1. Update the package: `bun update @trycompai/db`
|
|
247
|
+
2. The postinstall script will automatically update your schema
|
|
248
|
+
3. Run `bunx prisma generate --schema=src/db/schema.prisma` to update your client
|
|
249
|
+
4. Update your application code if needed
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
generator client {
|
|
2
2
|
provider = "prisma-client-js"
|
|
3
|
-
previewFeatures = ["
|
|
3
|
+
previewFeatures = ["postgresqlExtensions"]
|
|
4
4
|
binaryTargets = ["native", "darwin-arm64", "debian-openssl-3.0.x", "linux-musl-openssl-3.0.x"]
|
|
5
|
-
output = "
|
|
5
|
+
output = "./generated/prisma"
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
datasource db {
|
package/package.json
CHANGED
|
@@ -1,92 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trycompai/db",
|
|
3
3
|
"description": "Database package with Prisma client and schema for Comp AI",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@prisma/client": "6.
|
|
6
|
+
"@prisma/client": "^6.13.0"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"prisma": "6.9.0",
|
|
10
9
|
"@trycompai/tsconfig": "workspace:*",
|
|
11
|
-
"
|
|
12
|
-
"tsup": "^8.5.0",
|
|
10
|
+
"prisma": "^6.13.0",
|
|
13
11
|
"typescript": "^5.8.3"
|
|
14
12
|
},
|
|
15
|
-
"peerDependencies": {
|
|
16
|
-
"@prisma/client": "6.9.0",
|
|
17
|
-
"prisma": "6.9.0"
|
|
18
|
-
},
|
|
19
13
|
"exports": {
|
|
20
|
-
".": "./
|
|
21
|
-
"./types": "./
|
|
22
|
-
"./schema": "./dist/prisma/schema.prisma",
|
|
23
|
-
"./dist": {
|
|
24
|
-
"import": "./dist/index.mjs",
|
|
25
|
-
"require": "./dist/index.js"
|
|
26
|
-
},
|
|
27
|
-
"./dist/types": {
|
|
28
|
-
"import": "./dist/types.mjs",
|
|
29
|
-
"require": "./dist/types.js"
|
|
30
|
-
},
|
|
31
|
-
"./dist/schema": "./dist/prisma/schema.prisma"
|
|
14
|
+
".": "./dist/index.ts",
|
|
15
|
+
"./types": "./dist/types.ts"
|
|
32
16
|
},
|
|
33
17
|
"files": [
|
|
34
|
-
"dist
|
|
35
|
-
"scripts/setup-consumer.sh",
|
|
18
|
+
"dist/schema.prisma",
|
|
36
19
|
"README.md",
|
|
37
20
|
"INTEGRATION_GUIDE.md"
|
|
38
21
|
],
|
|
39
|
-
"keywords": [
|
|
40
|
-
"comp-ai",
|
|
41
|
-
"database",
|
|
42
|
-
"postgresql",
|
|
43
|
-
"prisma"
|
|
44
|
-
],
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"main": "./dist/index.js",
|
|
47
|
-
"module": "./dist/index.mjs",
|
|
48
|
-
"prisma": {
|
|
49
|
-
"schema": "prisma",
|
|
50
|
-
"seed": "ts-node prisma/seed/seed.ts"
|
|
51
|
-
},
|
|
52
22
|
"publishConfig": {
|
|
53
23
|
"access": "public"
|
|
54
24
|
},
|
|
55
25
|
"repository": {
|
|
56
26
|
"type": "git",
|
|
57
|
-
"url": "git+https://github.com/
|
|
27
|
+
"url": "git+https://github.com/trycompai/comp.git",
|
|
58
28
|
"directory": "packages/db"
|
|
59
29
|
},
|
|
60
30
|
"scripts": {
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"db:generate": "
|
|
64
|
-
"db:migrate": "
|
|
65
|
-
"db:push": "
|
|
66
|
-
"db:seed": "
|
|
67
|
-
"db:studio": "
|
|
68
|
-
"dev": "tsup --watch",
|
|
31
|
+
"lint": "prettier --check 'src/**/*.{ts,tsx,js,jsx,json}' 'prisma/**/*.prisma' && tsc --noEmit",
|
|
32
|
+
"check-types": "tsc --noEmit",
|
|
33
|
+
"db:generate": "prisma generate",
|
|
34
|
+
"db:migrate": "prisma migrate dev",
|
|
35
|
+
"db:push": "prisma db push",
|
|
36
|
+
"db:seed": "prisma db seed",
|
|
37
|
+
"db:studio": "prisma studio",
|
|
69
38
|
"docker:clean": "docker-compose down -v",
|
|
70
39
|
"docker:down": "docker-compose down",
|
|
71
40
|
"docker:up": "docker-compose up -d",
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
|
|
75
|
-
},
|
|
76
|
-
"tsup": {
|
|
77
|
-
"entry": [
|
|
78
|
-
"src/index.ts",
|
|
79
|
-
"src/types.ts"
|
|
80
|
-
],
|
|
81
|
-
"format": [
|
|
82
|
-
"cjs",
|
|
83
|
-
"esm"
|
|
84
|
-
],
|
|
85
|
-
"dts": false,
|
|
86
|
-
"clean": true,
|
|
87
|
-
"external": [
|
|
88
|
-
"@prisma/client"
|
|
89
|
-
]
|
|
90
|
-
},
|
|
91
|
-
"types": "./dist/index.d.ts"
|
|
41
|
+
"build": "node scripts/combine-schemas.js",
|
|
42
|
+
"prepublishOnly": "bun run build"
|
|
43
|
+
}
|
|
92
44
|
}
|