tpmjs/packages/db/prisma/seed.ts
Ajax Davis 3ae9ced6fa feat(db): create database package with Prisma schema for NPM registry
- 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>
2025-11-28 02:07:39 +10:00

55 lines
1.1 KiB
TypeScript

import { PrismaClient } from '@prisma/client';
const prisma = new PrismaClient();
async function main() {
console.log('Seeding sync checkpoints...');
// Create initial sync checkpoints
await prisma.syncCheckpoint.upsert({
where: { source: 'changes-feed' },
update: {},
create: {
source: 'changes-feed',
checkpoint: {
sequence: '0',
lastProcessed: null,
},
},
});
await prisma.syncCheckpoint.upsert({
where: { source: 'keyword-search' },
update: {},
create: {
source: 'keyword-search',
checkpoint: {
lastRun: null,
totalProcessed: 0,
},
},
});
await prisma.syncCheckpoint.upsert({
where: { source: 'metrics' },
update: {},
create: {
source: 'metrics',
checkpoint: {
lastRun: null,
totalProcessed: 0,
},
},
});
console.log('Seed completed successfully');
}
main()
.catch((e) => {
console.error('Seed failed:', e);
process.exit(1);
})
.finally(async () => {
await prisma.$disconnect();
});