- Add @tpmjs/db package with Prisma ORM setup - Define Tool model with NPM metadata and TPMJS fields - Define SyncCheckpoint model for tracking sync worker progress - Define SyncLog model for audit trail of sync operations - Add Prisma client singleton with dev logging - Add seed script for initializing sync checkpoints - Include comprehensive README with setup instructions Package includes: - Complete Prisma schema matching NPM_MIRROR.md spec - Three models: Tool, SyncCheckpoint, SyncLog - Indexes for performance on key fields - TypeScript support via @tpmjs/tsconfig - Scripts for db:migrate, db:push, db:studio, db:seed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
73 lines
1.3 KiB
Markdown
73 lines
1.3 KiB
Markdown
# @tpmjs/db
|
|
|
|
Database package for TPMJS NPM Registry. Provides Prisma ORM setup and database client for storing tool metadata.
|
|
|
|
## Setup
|
|
|
|
### 1. Create Neon Database
|
|
|
|
1. Go to https://neon.tech/
|
|
2. Create a new project
|
|
3. Copy the connection string
|
|
|
|
### 2. Configure Environment
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
# Edit .env and add your DATABASE_URL
|
|
```
|
|
|
|
### 3. Run Migrations
|
|
|
|
```bash
|
|
pnpm db:migrate
|
|
pnpm db:seed
|
|
```
|
|
|
|
## Usage
|
|
|
|
```typescript
|
|
import { prisma } from '@tpmjs/db';
|
|
|
|
// Query tools
|
|
const tools = await prisma.tool.findMany({
|
|
where: {
|
|
category: 'web-scraping',
|
|
isOfficial: true,
|
|
},
|
|
orderBy: {
|
|
qualityScore: 'desc',
|
|
},
|
|
take: 10,
|
|
});
|
|
|
|
// Update sync checkpoint
|
|
await prisma.syncCheckpoint.update({
|
|
where: { source: 'changes-feed' },
|
|
data: {
|
|
checkpoint: {
|
|
sequence: '12345',
|
|
lastProcessed: new Date().toISOString(),
|
|
},
|
|
},
|
|
});
|
|
```
|
|
|
|
## Scripts
|
|
|
|
- `pnpm db:generate` - Generate Prisma client
|
|
- `pnpm db:push` - Push schema to database (for development)
|
|
- `pnpm db:migrate` - Create and run migrations (for production)
|
|
- `pnpm db:studio` - Open Prisma Studio GUI
|
|
- `pnpm db:seed` - Seed initial data
|
|
|
|
## Schema
|
|
|
|
### Tool
|
|
Stores NPM packages with TPMJS metadata from their `package.json`.
|
|
|
|
### SyncCheckpoint
|
|
Tracks progress of sync workers (changes feed, keyword search, metrics).
|
|
|
|
### SyncLog
|
|
Audit trail of all sync operations.
|