@danielcok17/prisma-db
v1.3.0
Published
Shared Prisma schema for Legal AI applications
Maintainers
Readme
@danielcok17/prisma-db
Shared Prisma setup with dual Prisma clients: one for your app tables (app schema), one for existing law tables (public schema).
Structure
prisma/app.prisma— your models, migrate here (uses schemaapp)prisma/law.prisma— existingpublic.law_*andpublic.version_paragraphstables (introspection only)src/utils.ts— exportsappPrismaandlawPrisma
Scripts
npm run db:generate— generate both Prisma clientsnpm run db:migrate— run migrations forapp.prismaonlynpm run db:migrate:prod— deploy migrations (app)npm run db:pull:law— introspect existing public law tablesnpm run db:studio— open Prisma Studio forapp
Import
import { appPrisma, lawPrisma } from '@danielcok17/prisma-db';
// or direct clients if you need advanced typing control
import { AppPrismaClient, LawPrismaClient } from '@danielcok17/prisma-db';Environment
Set the following env vars in your runtime/build (names match the .prisma files):
POSTGRES_PRISMA_URL=postgres://USER:PASS@HOST:PORT/DB?schema=app
POSTGRES_URL_NON_POOLING=postgres://USER:PASS@HOST:PORT/DB?schema=app
POSTGRES_PRISMA_URL_LAW=postgres://READONLY_USER:PASS@HOST:PORT/DB
POSTGRES_URL_NON_POOLING_LAW=postgres://READONLY_USER:PASS@HOST:PORT/DBNotes:
- Use a read-only role for
POSTGRES_PRISMA_URL_LAW. - Ensure the DB has
CREATE SCHEMA IF NOT EXISTS app;executed once.
Schema paths (for tooling / CI)
This package publishes the prisma directory. You can get absolute paths to the schemas programmatically:
import { appPrismaSchemaPath, lawPrismaSchemaPath, prismaMigrationsPath } from '@danielcok17/prisma-db';Examples:
# Use the packaged app schema with Prisma CLI
npx prisma migrate deploy --schema "$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")"
# Or resolve directly to the file shipped in the package
APP_SCHEMA=$(node -e "console.log(require.resolve('@danielcok17/prisma-db/prisma/app.prisma'))")
npx prisma generate --schema "$APP_SCHEMA"Installation
npm install @danielcok17/prisma-db
# or
yarn add @danielcok17/prisma-dbThe package runs Prisma generate on postinstall. If your environment blocks lifecycle scripts, run generate manually using appPrismaSchemaPath as shown below.
Quick start
- Set env vars (match the names used in
.prismafiles):
POSTGRES_PRISMA_URL=postgres://USER:PASS@HOST:PORT/DB?schema=app
POSTGRES_URL_NON_POOLING=postgres://USER:PASS@HOST:PORT/DB?schema=app
POSTGRES_PRISMA_URL_LAW=postgres://READONLY_USER:PASS@HOST:PORT/DB
POSTGRES_URL_NON_POOLING_LAW=postgres://READONLY_USER:PASS@HOST:PORT/DB- Apply migrations for the
appschema:
APP_SCHEMA=$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")
npx prisma migrate deploy --schema "$APP_SCHEMA"- Use the clients:
import { appPrisma, lawPrisma } from '@danielcok17/prisma-db';
const users = await appPrisma.user.findMany();
const laws = await lawPrisma.lawVersion.findMany({ take: 5 });Upgrading to a new version
When you update the package, always apply migrations shipped with the new version.
npm install @danielcok17/prisma-db@latest
# Regenerate client (if your CI blocks postinstall or you want to be explicit)
APP_SCHEMA=$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")
npx prisma generate --schema "$APP_SCHEMA"
# Apply new migrations
npx prisma migrate deploy --schema "$APP_SCHEMA"Notes:
- Do not run
prisma migrate devin consumer apps. Schema changes are managed in this package and released via versions. - If there are breaking changes, check the release notes for manual steps.
CI/CD snippet
Add a deploy step to apply migrations using the schema from this package:
APP_SCHEMA=$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")
npx prisma migrate deploy --schema "$APP_SCHEMA"Optionally regenerate the client at build/deploy time:
npx prisma generate --schema "$APP_SCHEMA"Prisma Studio (optional)
APP_SCHEMA=$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")
npx prisma studio --schema "$APP_SCHEMA"Troubleshooting
- Missing client types/runtime: run
npx prisma generate --schema "$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")". - Migrate deploy fails: verify env vars and DB connectivity; ensure the
appschema exists. - Read-only access to law tables: use a user/role with SELECT-only permissions for
POSTGRES_PRISMA_URL_LAW.
