npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@danielcok17/prisma-db

v1.3.0

Published

Shared Prisma schema for Legal AI applications

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 schema app)
  • prisma/law.prisma — existing public.law_* and public.version_paragraphs tables (introspection only)
  • src/utils.ts — exports appPrisma and lawPrisma

Scripts

  • npm run db:generate — generate both Prisma clients
  • npm run db:migrate — run migrations for app.prisma only
  • npm run db:migrate:prod — deploy migrations (app)
  • npm run db:pull:law — introspect existing public law tables
  • npm run db:studio — open Prisma Studio for app

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/DB

Notes:

  • 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-db

The package runs Prisma generate on postinstall. If your environment blocks lifecycle scripts, run generate manually using appPrismaSchemaPath as shown below.

Quick start

  1. Set env vars (match the names used in .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/DB
  1. Apply migrations for the app schema:
APP_SCHEMA=$(node -e "console.log(require('@danielcok17/prisma-db').appPrismaSchemaPath)")
npx prisma migrate deploy --schema "$APP_SCHEMA"
  1. 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 dev in 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 app schema exists.
  • Read-only access to law tables: use a user/role with SELECT-only permissions for POSTGRES_PRISMA_URL_LAW.