@1aboveio/app-dev-skills 0.0.0-stage → 0.1.0
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/README.md +29 -2
- package/package.json +33 -4
- package/skills/airflow/LICENSE +3 -0
- package/skills/airflow/SKILL.md +199 -0
- package/skills/airflow/release-check.mjs +93 -0
- package/skills/android-foundation/LICENSE +3 -0
- package/skills/android-foundation/SKILL.md +192 -0
- package/skills/android-foundation/assets/android-ci-job.yml +217 -0
- package/skills/android-foundation/references/ci.md +87 -0
- package/skills/android-foundation/references/gotchas.md +221 -0
- package/skills/android-foundation/references/setup.md +164 -0
- package/skills/android-foundation/release-check.mjs +93 -0
- package/skills/android-foundation/scripts/device-run.sh +176 -0
- package/skills/android-foundation/scripts/device-run.test.mjs +172 -0
- package/skills/app-debug/LICENSE +3 -0
- package/skills/app-debug/SKILL.md +110 -0
- package/skills/app-debug/references/common-errors.md +128 -0
- package/skills/app-debug/release-check.mjs +93 -0
- package/skills/better-auth/LICENSE +3 -0
- package/skills/better-auth/SKILL.md +598 -0
- package/skills/better-auth/references/feishu-api.md +270 -0
- package/skills/better-auth/release-check.mjs +93 -0
- package/skills/ios-foundation/LICENSE +3 -0
- package/skills/ios-foundation/SKILL.md +184 -0
- package/skills/ios-foundation/references/setup.md +243 -0
- package/skills/ios-foundation/release-check.mjs +93 -0
- package/skills/monorepo/LICENSE +3 -0
- package/skills/monorepo/SKILL.md +462 -0
- package/skills/monorepo/release-check.mjs +93 -0
- package/skills/nextjs-fullstack/LICENSE +3 -0
- package/skills/nextjs-fullstack/SKILL.md +211 -0
- package/skills/nextjs-fullstack/conventions.md +318 -0
- package/skills/nextjs-fullstack/frontend-conventions.md +61 -0
- package/skills/nextjs-fullstack/nextjs16.md +287 -0
- package/skills/nextjs-fullstack/release-check.mjs +93 -0
- package/skills/nextjs-fullstack/server-actions.md +409 -0
- package/skills/prisma-setup/LICENSE +3 -0
- package/skills/prisma-setup/SKILL.md +181 -0
- package/skills/prisma-setup/nextjs.md +258 -0
- package/skills/prisma-setup/release-check.mjs +93 -0
- package/skills/prisma-setup/turborepo.md +301 -0
- package/skills/pyspark/LICENSE +3 -0
- package/skills/pyspark/SKILL.md +127 -0
- package/skills/pyspark/assets/templates/etl.py +748 -0
- package/skills/pyspark/assets/templates/utils/__init__.py +1 -0
- package/skills/pyspark/assets/templates/utils/hudi_metadata.py +14 -0
- package/skills/pyspark/references/diagnosis-and-profiling.md +169 -0
- package/skills/pyspark/references/etl-contract.md +129 -0
- package/skills/pyspark/references/production-validation.md +131 -0
- package/skills/pyspark/references/reconciliation.md +38 -0
- package/skills/pyspark/references/transformation-design.md +190 -0
- package/skills/pyspark/references/velocity-feature-calculation.md +193 -0
- package/skills/pyspark/release-check.mjs +93 -0
- package/skills/pyspark/scripts/spark_eventlog_summary.py +223 -0
- package/skills/python-backend/LICENSE +3 -0
- package/skills/python-backend/SKILL.md +325 -0
- package/skills/python-backend/assets/uv-install.sh +48 -0
- package/skills/python-backend/references/uv-installs.md +83 -0
- package/skills/python-backend/release-check.mjs +93 -0
- package/skills/shadcn/LICENSE +3 -0
- package/skills/shadcn/SKILL.md +120 -0
- package/skills/shadcn/assets/shadcn-small.png +0 -0
- package/skills/shadcn/assets/shadcn.png +0 -0
- package/skills/shadcn/cli.md +411 -0
- package/skills/shadcn/customization.md +224 -0
- package/skills/shadcn/mcp.md +101 -0
- package/skills/shadcn/release-check.mjs +93 -0
- package/skills/shadcn/rules/base-vs-radix.md +323 -0
- package/skills/shadcn/rules/component-selection.md +67 -0
- package/skills/shadcn/rules/composition.md +195 -0
- package/skills/shadcn/rules/data-table.md +201 -0
- package/skills/shadcn/rules/forms.md +255 -0
- package/skills/shadcn/rules/icons.md +103 -0
- package/skills/shadcn/rules/styling.md +167 -0
- package/skills/zod-v4/LICENSE +3 -0
- package/skills/zod-v4/SKILL.md +286 -0
- package/skills/zod-v4/release-check.mjs +93 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# Next.js + Prisma v7 Bootstrap
|
|
2
|
+
|
|
3
|
+
Complete setup guide for Prisma v7 in a standalone Next.js App Router project.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Setup Workflow
|
|
8
|
+
|
|
9
|
+
### 1. Install Dependencies
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install prisma tsx --save-dev
|
|
13
|
+
npm install @prisma/adapter-pg @prisma/client dotenv
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
### 2. Initialize Prisma
|
|
17
|
+
|
|
18
|
+
**Interactive command - run manually:**
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npx prisma init --db --output ../app/generated/prisma
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
This creates:
|
|
25
|
+
- `prisma/schema.prisma`
|
|
26
|
+
- `prisma.config.ts`
|
|
27
|
+
- `.env` with DATABASE_URL
|
|
28
|
+
|
|
29
|
+
Ensure `.env` uses `postgres://` URL scheme.
|
|
30
|
+
|
|
31
|
+
### 3. Update Schema
|
|
32
|
+
|
|
33
|
+
```prisma
|
|
34
|
+
generator client {
|
|
35
|
+
provider = "prisma-client"
|
|
36
|
+
output = "../app/generated/prisma"
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
datasource db {
|
|
40
|
+
provider = "postgresql"
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
model User {
|
|
44
|
+
id Int @id @default(autoincrement())
|
|
45
|
+
email String @unique
|
|
46
|
+
name String?
|
|
47
|
+
createdAt DateTime @default(now())
|
|
48
|
+
updatedAt DateTime @updatedAt
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
### 4. Create Prisma Client
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
// lib/prisma.ts
|
|
56
|
+
import { PrismaClient } from "../app/generated/prisma/client"
|
|
57
|
+
import { PrismaPg } from "@prisma/adapter-pg"
|
|
58
|
+
|
|
59
|
+
const adapter = new PrismaPg({
|
|
60
|
+
connectionString: process.env.DATABASE_URL!,
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
const globalForPrisma = global as unknown as { prisma: PrismaClient }
|
|
64
|
+
|
|
65
|
+
const prisma = globalForPrisma.prisma || new PrismaClient({ adapter })
|
|
66
|
+
|
|
67
|
+
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma
|
|
68
|
+
|
|
69
|
+
export default prisma
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 5. Add NPM Scripts
|
|
73
|
+
|
|
74
|
+
```json
|
|
75
|
+
{
|
|
76
|
+
"scripts": {
|
|
77
|
+
"dev": "next dev",
|
|
78
|
+
"build": "next build",
|
|
79
|
+
"db:test": "tsx scripts/test-database.ts",
|
|
80
|
+
"db:studio": "prisma studio"
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 6. Create Test Script
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
// scripts/test-database.ts
|
|
89
|
+
import "dotenv/config"
|
|
90
|
+
import prisma from "../lib/prisma"
|
|
91
|
+
|
|
92
|
+
async function testDatabase() {
|
|
93
|
+
console.log("Testing Prisma connection...\n")
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
console.log("Connected!")
|
|
97
|
+
|
|
98
|
+
const user = await prisma.user.create({
|
|
99
|
+
data: { email: "test@example.com", name: "Test" },
|
|
100
|
+
})
|
|
101
|
+
console.log("Created:", user)
|
|
102
|
+
|
|
103
|
+
const users = await prisma.user.findMany()
|
|
104
|
+
console.log(`Found ${users.length} users`)
|
|
105
|
+
|
|
106
|
+
console.log("\nAll tests passed!")
|
|
107
|
+
} catch (error) {
|
|
108
|
+
console.error("Error:", error)
|
|
109
|
+
process.exit(1)
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
testDatabase()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
### 7. Push Schema & Test
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
npx prisma db push
|
|
120
|
+
npx prisma generate
|
|
121
|
+
npm run db:test
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## API Route Example
|
|
127
|
+
|
|
128
|
+
```typescript
|
|
129
|
+
// app/api/users/route.ts
|
|
130
|
+
import { NextRequest, NextResponse } from "next/server"
|
|
131
|
+
import prisma from "../../../lib/prisma"
|
|
132
|
+
|
|
133
|
+
export async function GET(request: NextRequest) {
|
|
134
|
+
try {
|
|
135
|
+
const users = await prisma.user.findMany()
|
|
136
|
+
return NextResponse.json(users)
|
|
137
|
+
} catch (error) {
|
|
138
|
+
console.error("Error fetching users:", error)
|
|
139
|
+
return NextResponse.json(
|
|
140
|
+
{ error: "Failed to fetch users" },
|
|
141
|
+
{ status: 500 }
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export async function POST(request: NextRequest) {
|
|
147
|
+
try {
|
|
148
|
+
const body = await request.json()
|
|
149
|
+
const user = await prisma.user.create({
|
|
150
|
+
data: { email: body.email, name: body.name },
|
|
151
|
+
})
|
|
152
|
+
return NextResponse.json(user, { status: 201 })
|
|
153
|
+
} catch (error) {
|
|
154
|
+
console.error("Error creating user:", error)
|
|
155
|
+
return NextResponse.json(
|
|
156
|
+
{ error: "Failed to create user" },
|
|
157
|
+
{ status: 500 }
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Server Component Example
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
// app/page.tsx
|
|
169
|
+
import prisma from "../lib/prisma"
|
|
170
|
+
|
|
171
|
+
export default async function Home() {
|
|
172
|
+
let users = []
|
|
173
|
+
let error = null
|
|
174
|
+
|
|
175
|
+
try {
|
|
176
|
+
users = await prisma.user.findMany({
|
|
177
|
+
orderBy: { createdAt: "desc" },
|
|
178
|
+
})
|
|
179
|
+
} catch (e) {
|
|
180
|
+
console.error("Error:", e)
|
|
181
|
+
error = "Failed to load users"
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
return (
|
|
185
|
+
<main className="p-8">
|
|
186
|
+
<h1>Users</h1>
|
|
187
|
+
{error ? (
|
|
188
|
+
<p className="text-red-500">{error}</p>
|
|
189
|
+
) : users.length === 0 ? (
|
|
190
|
+
<p>No users yet</p>
|
|
191
|
+
) : (
|
|
192
|
+
<ul>
|
|
193
|
+
{users.map((user) => (
|
|
194
|
+
<li key={user.id}>{user.name} ({user.email})</li>
|
|
195
|
+
))}
|
|
196
|
+
</ul>
|
|
197
|
+
)}
|
|
198
|
+
</main>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## File Structure
|
|
206
|
+
|
|
207
|
+
```
|
|
208
|
+
project/
|
|
209
|
+
├── app/
|
|
210
|
+
│ ├── generated/
|
|
211
|
+
│ │ └── prisma/ # Generated client
|
|
212
|
+
│ ├── api/
|
|
213
|
+
│ │ └── users/
|
|
214
|
+
│ │ └── route.ts
|
|
215
|
+
│ └── page.tsx
|
|
216
|
+
├── lib/
|
|
217
|
+
│ └── prisma.ts # Singleton client
|
|
218
|
+
├── prisma/
|
|
219
|
+
│ ├── schema.prisma
|
|
220
|
+
│ └── migrations/
|
|
221
|
+
├── scripts/
|
|
222
|
+
│ └── test-database.ts
|
|
223
|
+
├── prisma.config.ts
|
|
224
|
+
├── .env
|
|
225
|
+
└── package.json
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
---
|
|
229
|
+
|
|
230
|
+
## Troubleshooting
|
|
231
|
+
|
|
232
|
+
### "Cannot find module"
|
|
233
|
+
|
|
234
|
+
Check import path includes `/client`:
|
|
235
|
+
```typescript
|
|
236
|
+
// Correct
|
|
237
|
+
import { PrismaClient } from "../app/generated/prisma/client"
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### "DATABASE_URL not found"
|
|
241
|
+
|
|
242
|
+
Ensure `import "dotenv/config"` is at top of:
|
|
243
|
+
- `prisma.config.ts`
|
|
244
|
+
- `scripts/test-database.ts`
|
|
245
|
+
|
|
246
|
+
### "Connection refused"
|
|
247
|
+
|
|
248
|
+
Verify DATABASE_URL uses TCP URL (`postgres://...`), not HTTP URL.
|
|
249
|
+
|
|
250
|
+
### "prisma-client-js deprecated"
|
|
251
|
+
|
|
252
|
+
Update generator:
|
|
253
|
+
```prisma
|
|
254
|
+
generator client {
|
|
255
|
+
provider = "prisma-client" # Not "prisma-client-js"
|
|
256
|
+
output = "../app/generated/prisma"
|
|
257
|
+
}
|
|
258
|
+
```
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { spawnSync } from 'node:child_process';
|
|
3
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
4
|
+
import { homedir } from 'node:os';
|
|
5
|
+
import { dirname, join } from 'node:path';
|
|
6
|
+
import { fileURLToPath } from 'node:url';
|
|
7
|
+
|
|
8
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
9
|
+
const WEEK_MS = 7 * DAY_MS;
|
|
10
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
function readJson(path, fallback = {}) {
|
|
13
|
+
try { return JSON.parse(readFileSync(path, 'utf8')); } catch { return fallback; }
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function frontmatterValue(text, key) {
|
|
17
|
+
const frontmatter = /^---\n([\s\S]*?)\n---/.exec(text)?.[1] ?? '';
|
|
18
|
+
const match = new RegExp('^' + key + ':\\s*([^\\n]+)$', 'm').exec(frontmatter);
|
|
19
|
+
return match?.[1].trim().replace(/^['"]|['"]$/g, '') ?? null;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function repositoryOf(source) {
|
|
23
|
+
const value = String(source ?? '').trim();
|
|
24
|
+
const match = /^(?:git@github\.com:|https:\/\/github\.com\/)?([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+?)(?:\.git)?$/.exec(value);
|
|
25
|
+
return match?.[1] ?? null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function stableVersion(value) {
|
|
29
|
+
const match = /^v?(\d+)\.(\d+)\.(\d+)$/.exec(String(value ?? '').trim());
|
|
30
|
+
return match ? match.slice(1).map(Number) : null;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function newer(left, right) {
|
|
34
|
+
for (let index = 0; index < 3; index += 1) {
|
|
35
|
+
if (left[index] !== right[index]) return left[index] > right[index];
|
|
36
|
+
}
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function writeCache(path, value) {
|
|
41
|
+
try {
|
|
42
|
+
mkdirSync(dirname(path), { recursive: true });
|
|
43
|
+
writeFileSync(path, JSON.stringify(value));
|
|
44
|
+
} catch { /* A read-only cache must not block skill use. */ }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function main(now = Date.now()) {
|
|
48
|
+
if (process.env.ONEABOVEIO_NO_UPDATE_CHECK) return;
|
|
49
|
+
const skill = readFileSync(join(here, 'SKILL.md'), 'utf8');
|
|
50
|
+
const name = frontmatterValue(skill, 'name');
|
|
51
|
+
const localVersion = stableVersion(frontmatterValue(skill, 'release-version'));
|
|
52
|
+
if (!name || !localVersion) return;
|
|
53
|
+
|
|
54
|
+
const lock = readJson(join(process.env.HOME || homedir(), '.agents', '.skill-lock.json'));
|
|
55
|
+
const entry = lock.skills?.[name];
|
|
56
|
+
const repository = repositoryOf(entry?.sourceUrl || entry?.source);
|
|
57
|
+
if (!repository) return;
|
|
58
|
+
|
|
59
|
+
const cacheRoot = process.env.XDG_CACHE_HOME || join(process.env.HOME || homedir(), '.cache');
|
|
60
|
+
const cachePath = join(cacheRoot, '1aboveio-skills', 'release-check.json');
|
|
61
|
+
const all = readJson(cachePath);
|
|
62
|
+
const cache = all[repository] && typeof all[repository] === 'object' ? all[repository] : {};
|
|
63
|
+
|
|
64
|
+
if (!cache.lastCheck || now - cache.lastCheck >= DAY_MS) {
|
|
65
|
+
const result = spawnSync('gh', ['api', 'repos/' + repository + '/releases/latest', '--jq', '.tag_name'], {
|
|
66
|
+
encoding: 'utf8',
|
|
67
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
68
|
+
timeout: 1500,
|
|
69
|
+
});
|
|
70
|
+
cache.lastCheck = now;
|
|
71
|
+
if (result.status === 0 && stableVersion(result.stdout)) cache.latestTag = result.stdout.trim();
|
|
72
|
+
else delete cache.latestTag;
|
|
73
|
+
all[repository] = cache;
|
|
74
|
+
writeCache(cachePath, all);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const latestVersion = stableVersion(cache.latestTag);
|
|
78
|
+
if (!latestVersion || !newer(latestVersion, localVersion)) return;
|
|
79
|
+
if (cache.notifiedTag === cache.latestTag && cache.notifiedAt && now - cache.notifiedAt < WEEK_MS) return;
|
|
80
|
+
|
|
81
|
+
cache.notifiedTag = cache.latestTag;
|
|
82
|
+
cache.notifiedAt = now;
|
|
83
|
+
all[repository] = cache;
|
|
84
|
+
writeCache(cachePath, all);
|
|
85
|
+
const command = `npx skills@1.5.23 add '${repository}#${cache.latestTag}' --global --agent universal claude-code --skill ${name} --yes`;
|
|
86
|
+
process.stdout.write(
|
|
87
|
+
`UPDATE_AVAILABLE: A newer 1AboveIO skills release (${cache.latestTag}) is available; this skill is `
|
|
88
|
+
+ `v${localVersion.join('.')}. Ask once whether to refresh ${name}. On approval run \`${command}\`. `
|
|
89
|
+
+ 'The refreshed instructions apply next session. Either way, continue the current task and do not ask again this session.\n',
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
try { main(); } catch { /* Update checks are advisory and always fail silent. */ }
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
# Turborepo + Prisma v7 Setup
|
|
2
|
+
|
|
3
|
+
Monorepo setup with shared Prisma package across multiple apps.
|
|
4
|
+
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
## Monorepo Layout
|
|
8
|
+
|
|
9
|
+
```
|
|
10
|
+
repo/
|
|
11
|
+
├── apps/
|
|
12
|
+
│ ├── web/ # Next.js app
|
|
13
|
+
│ └── admin/ # Another Next app
|
|
14
|
+
├── packages/
|
|
15
|
+
│ ├── db/ # Prisma package
|
|
16
|
+
│ └── ui/ # Shared UI
|
|
17
|
+
├── turbo.json
|
|
18
|
+
├── package.json
|
|
19
|
+
└── .env
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**Key rule:** Prisma lives in `packages/db`, not inside an app.
|
|
23
|
+
|
|
24
|
+
---
|
|
25
|
+
|
|
26
|
+
## Package Structure: packages/db
|
|
27
|
+
|
|
28
|
+
```
|
|
29
|
+
packages/db/
|
|
30
|
+
├── prisma/
|
|
31
|
+
│ ├── schema.prisma
|
|
32
|
+
│ └── migrations/
|
|
33
|
+
├── src/
|
|
34
|
+
│ ├── generated/
|
|
35
|
+
│ │ └── prisma/ # Generated client
|
|
36
|
+
│ ├── client.ts # Singleton
|
|
37
|
+
│ └── index.ts # Exports
|
|
38
|
+
├── scripts/
|
|
39
|
+
│ └── test-database.ts
|
|
40
|
+
├── prisma.config.ts
|
|
41
|
+
└── package.json
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Schema Configuration
|
|
47
|
+
|
|
48
|
+
```prisma
|
|
49
|
+
// packages/db/prisma/schema.prisma
|
|
50
|
+
generator client {
|
|
51
|
+
provider = "prisma-client"
|
|
52
|
+
output = "../src/generated/prisma"
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
datasource db {
|
|
56
|
+
provider = "postgresql"
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
model User {
|
|
60
|
+
id Int @id @default(autoincrement())
|
|
61
|
+
email String @unique
|
|
62
|
+
name String?
|
|
63
|
+
createdAt DateTime @default(now())
|
|
64
|
+
updatedAt DateTime @updatedAt
|
|
65
|
+
}
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## Prisma Config
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
// packages/db/prisma.config.ts
|
|
74
|
+
import "dotenv/config"
|
|
75
|
+
import { defineConfig, env } from "prisma/config"
|
|
76
|
+
|
|
77
|
+
export default defineConfig({
|
|
78
|
+
schema: "prisma/schema.prisma",
|
|
79
|
+
migrations: {
|
|
80
|
+
path: "prisma/migrations",
|
|
81
|
+
},
|
|
82
|
+
datasource: {
|
|
83
|
+
url: env("DATABASE_URL"),
|
|
84
|
+
},
|
|
85
|
+
})
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
---
|
|
89
|
+
|
|
90
|
+
## Client Singleton
|
|
91
|
+
|
|
92
|
+
```typescript
|
|
93
|
+
// packages/db/src/client.ts
|
|
94
|
+
import { PrismaClient } from "./generated/prisma/client"
|
|
95
|
+
import { PrismaPg } from "@prisma/adapter-pg"
|
|
96
|
+
|
|
97
|
+
const adapter = new PrismaPg({
|
|
98
|
+
connectionString: process.env.DATABASE_URL!,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const globalForPrisma = globalThis as unknown as {
|
|
102
|
+
prisma?: PrismaClient
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export const prisma =
|
|
106
|
+
globalForPrisma.prisma ?? new PrismaClient({ adapter })
|
|
107
|
+
|
|
108
|
+
if (process.env.NODE_ENV !== "production") {
|
|
109
|
+
globalForPrisma.prisma = prisma
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default prisma
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Package Exports
|
|
118
|
+
|
|
119
|
+
```typescript
|
|
120
|
+
// packages/db/src/index.ts
|
|
121
|
+
export { prisma } from "./client"
|
|
122
|
+
export * from "./generated/prisma"
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
```json
|
|
126
|
+
// packages/db/package.json
|
|
127
|
+
{
|
|
128
|
+
"name": "@repo/db",
|
|
129
|
+
"private": true,
|
|
130
|
+
"main": "src/index.ts",
|
|
131
|
+
"types": "src/index.ts",
|
|
132
|
+
"scripts": {
|
|
133
|
+
"db:generate": "prisma generate",
|
|
134
|
+
"db:push": "prisma db push",
|
|
135
|
+
"db:migrate": "prisma migrate dev",
|
|
136
|
+
"db:studio": "prisma studio",
|
|
137
|
+
"db:test": "tsx scripts/test-database.ts"
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
|
|
144
|
+
## Turbo Configuration
|
|
145
|
+
|
|
146
|
+
```json
|
|
147
|
+
// turbo.json
|
|
148
|
+
{
|
|
149
|
+
"globalEnv": ["DATABASE_URL"],
|
|
150
|
+
"tasks": {
|
|
151
|
+
"dev": {
|
|
152
|
+
"cache": false,
|
|
153
|
+
"persistent": true,
|
|
154
|
+
"dependsOn": ["^db:generate"]
|
|
155
|
+
},
|
|
156
|
+
"build": {
|
|
157
|
+
"dependsOn": ["^db:generate"],
|
|
158
|
+
"outputs": [".next/**", "dist/**"]
|
|
159
|
+
},
|
|
160
|
+
"db:generate": {
|
|
161
|
+
"cache": false
|
|
162
|
+
},
|
|
163
|
+
"db:migrate": {
|
|
164
|
+
"cache": false
|
|
165
|
+
},
|
|
166
|
+
"db:studio": {
|
|
167
|
+
"cache": false
|
|
168
|
+
},
|
|
169
|
+
"db:test": {
|
|
170
|
+
"cache": false,
|
|
171
|
+
"dependsOn": ["db:generate"]
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## Root Scripts
|
|
180
|
+
|
|
181
|
+
```json
|
|
182
|
+
// package.json (root)
|
|
183
|
+
{
|
|
184
|
+
"scripts": {
|
|
185
|
+
"dev": "turbo dev",
|
|
186
|
+
"build": "turbo build",
|
|
187
|
+
"db:generate": "turbo run db:generate",
|
|
188
|
+
"db:push": "turbo run db:push",
|
|
189
|
+
"db:migrate": "turbo run db:migrate",
|
|
190
|
+
"db:studio": "turbo run db:studio",
|
|
191
|
+
"db:test": "turbo run db:test"
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
## Using in Apps
|
|
199
|
+
|
|
200
|
+
### Add Dependency
|
|
201
|
+
|
|
202
|
+
```json
|
|
203
|
+
// apps/web/package.json
|
|
204
|
+
{
|
|
205
|
+
"dependencies": {
|
|
206
|
+
"@repo/db": "*"
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
```
|
|
210
|
+
|
|
211
|
+
### Import in Server Code
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
// apps/web/app/api/users/route.ts
|
|
215
|
+
import { prisma } from "@repo/db"
|
|
216
|
+
import { NextResponse } from "next/server"
|
|
217
|
+
|
|
218
|
+
export async function GET() {
|
|
219
|
+
try {
|
|
220
|
+
const users = await prisma.user.findMany()
|
|
221
|
+
return NextResponse.json(users)
|
|
222
|
+
} catch (e) {
|
|
223
|
+
console.error(e)
|
|
224
|
+
return NextResponse.json({ error: "Failed" }, { status: 500 })
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
231
|
+
## Test Script
|
|
232
|
+
|
|
233
|
+
```typescript
|
|
234
|
+
// packages/db/scripts/test-database.ts
|
|
235
|
+
import "dotenv/config"
|
|
236
|
+
import prisma from "../src/client"
|
|
237
|
+
|
|
238
|
+
async function testDatabase() {
|
|
239
|
+
console.log("Testing connection...\n")
|
|
240
|
+
|
|
241
|
+
try {
|
|
242
|
+
console.log("Connected!")
|
|
243
|
+
|
|
244
|
+
const user = await prisma.user.create({
|
|
245
|
+
data: { email: "demo@example.com", name: "Demo" }
|
|
246
|
+
})
|
|
247
|
+
console.log("Created:", user)
|
|
248
|
+
|
|
249
|
+
const users = await prisma.user.findMany()
|
|
250
|
+
console.log(`Found ${users.length} users`)
|
|
251
|
+
|
|
252
|
+
console.log("\nAll tests passed!")
|
|
253
|
+
} catch (error) {
|
|
254
|
+
console.error("Error:", error)
|
|
255
|
+
process.exit(1)
|
|
256
|
+
} finally {
|
|
257
|
+
await prisma.$disconnect()
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
testDatabase()
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
---
|
|
265
|
+
|
|
266
|
+
## Setup Workflow
|
|
267
|
+
|
|
268
|
+
1. Create Turborepo or use existing
|
|
269
|
+
2. Add `packages/db`, install Prisma v7 deps
|
|
270
|
+
3. Initialize Prisma in packages/db:
|
|
271
|
+
```bash
|
|
272
|
+
cd packages/db
|
|
273
|
+
npx prisma init
|
|
274
|
+
```
|
|
275
|
+
4. Update `prisma.config.ts` with `import "dotenv/config"`
|
|
276
|
+
5. Update schema with v7 generator + output
|
|
277
|
+
6. Create `src/client.ts` singleton
|
|
278
|
+
7. Wire Turbo tasks in `turbo.json`
|
|
279
|
+
8. Add `.env` at root and/or `packages/db/.env`
|
|
280
|
+
9. Push schema:
|
|
281
|
+
```bash
|
|
282
|
+
npm run db:push
|
|
283
|
+
```
|
|
284
|
+
10. Test:
|
|
285
|
+
```bash
|
|
286
|
+
npm run db:test
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
---
|
|
290
|
+
|
|
291
|
+
## Verification Checklist
|
|
292
|
+
|
|
293
|
+
1. `provider = "prisma-client"`?
|
|
294
|
+
2. `output = "../src/generated/prisma"` in packages/db?
|
|
295
|
+
3. All Prisma files in `packages/db`?
|
|
296
|
+
4. Client imports from generated path or `@repo/db`?
|
|
297
|
+
5. `import "dotenv/config"` in prisma.config.ts?
|
|
298
|
+
6. Turbo tasks depend on `db:generate`?
|
|
299
|
+
7. `DATABASE_URL` in `globalEnv`?
|
|
300
|
+
8. All DB ops wrapped in try/catch?
|
|
301
|
+
9. Test script exists in packages/db?
|