@cresium/mage-models
v0.1.2
Published
Mage Prisma schema and generated client
Readme
@cresium/mage-models
Mage Prisma schema, generated client types, and shared model interfaces. Use this in any Cresium service that needs to talk to the Mage database.
Note: inside this monorepo the package is named
@mage/model. It is renamed to@cresium/mage-modelsonly at publish time (seescripts/swapName.ts).
Install
npm install @cresium/mage-models @prisma/client @prisma/adapter-pg prisma dayjs@prisma/client, @prisma/adapter-pg, prisma, and dayjs are peer dependencies — install them in the consumer to keep a single copy.
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/mage-models/src/prisma/schema.prismaRecommended: add this to a postinstall script in your package.json:
{
"scripts": {
"postinstall": "prisma generate --schema=./node_modules/@cresium/mage-models/src/prisma/schema.prisma"
}
}Usage
import {
PrismaClient,
type SomeMageType,
} from "@cresium/mage-models";
const prisma = new PrismaClient();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/mage-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@mage/modelto@cresium/mage-modelsnpm publish→ uploads the package as@cresium/mage-modelspostpublish→ restores the name back to@mage/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).
