@cresium/knight-models
v0.1.4
Published
Knight Prisma schema and generated client
Readme
@cresium/knight-models
Knight Prisma schema, generated client types, and shared model interfaces. Use this in any Cresium service that needs to talk to the Knight database.
Note: inside this monorepo the package is named
@knight/model. It is renamed to@cresium/knight-modelsonly at publish time (seescripts/publish.js).
Install
npm install @cresium/knight-models @prisma/client @prisma/adapter-pg prisma@prisma/client, @prisma/adapter-pg, and prisma are peer dependencies — install them in the consumer to keep a single copy of Prisma.
Generate the Prisma client
The package ships with the schema (src/prisma/schema.prisma) but does not ship a generated client. The consumer must generate it once after install:
npx prisma generate --schema=./node_modules/@cresium/knight-models/src/prisma/schema.prismaRecommended: add this to a postinstall script in your package.json:
{
"scripts": {
"postinstall": "prisma generate --schema=./node_modules/@cresium/knight-models/src/prisma/schema.prisma"
}
}Usage
import {
PrismaClient,
Registration,
Company,
CountryCode,
type PopulatedRegistration,
} from "@cresium/knight-models";
const prisma = new PrismaClient();
const reg: PopulatedRegistration | null = await prisma.registration.findFirst({
include: { company: true },
});Migrations
If your service owns its own database with this schema, you can run migrations from your project:
npx prisma migrate deploy --schema=./node_modules/@cresium/knight-models/src/prisma/schema.prismaThe published package includes both schema.prisma and src/prisma/migrations (see the files field in package.json).
Publishing
From packages/model:
npm publishThat's it. The npm lifecycle hooks (prepublishOnly and postpublish in package.json) take care of everything:
prepublishOnly→ cleans, builds, typechecks, and swaps the package name from@knight/modelto@cresium/knight-modelsnpm publish→ uploads the package as@cresium/knight-modelspostpublish→ restores the name back to@knight/modelso the monorepo keeps working
Bump the version in package.json before publishing (or let the GitHub Actions workflow do it automatically — see .github/workflows/publish-models.yml).
