stratal-zenstack-plugin
@stratal/zenstack-plugin
ZenStack plugin for Stratal that enables multi-connection database support through schema slicing and connection-specific migrations. It splits a single .zmodel schema into per-connection schemas based on the @@connection attribute.
Plugin Setup
In your .zmodel file:
plugin stratal {
provider = '@stratal/zenstack-plugin'
output = './zenstack'
default = 'main'
}
model User {
id String @id @default(cuid())
@@connection('main')
}
model AuditLog {
id String @id @default(cuid())
@@connection('analytics')
}
Models without @@connection are assigned to the default connection.
Generated Output
After running npx zenstack generate, the plugin produces:
slicing.ts— Export map used byDatabaseModulefor connection-aware query routing- Per-connection schemas — Separate Prisma schemas for each connection (used for migrations)
CLI: stratal-db
| Command | Description |
|---|---|
stratal-db migrate dev --connection <name> --name <name> |
Create a new migration |
stratal-db migrate deploy --connection <name> |
Apply pending migrations |
stratal-db migrate reset --connection <name> |
Reset database and re-apply migrations |
stratal-db push --connection <name> |
Push schema changes without migration files |
stratal-db migrate dev --all-connections |
Run migration on all connections at once |
Common options: --connection <name> to target a specific connection, --all-connections to target all.
Conventions
- Always set a
defaultconnection in the plugin config - Run
npx zenstack generatebeforestratal-dbcommands to update schemas - The generated
slicing.tsintegrates directly withDatabaseModule.forRoot()via theslicingoption on each connection - Cross-connection relations are validated at generation time — models in different connections cannot have direct relations
More from strataljs/stratal
stratal
Build Cloudflare Workers applications with the Stratal framework. Use when code imports from 'stratal' or '@stratal/*', when creating modules, controllers, services, routes, queue consumers, cron jobs, or CLI commands, or when user mentions Stratal, asks to 'create a module', 'add an endpoint', 'set up auth', 'configure database', 'add error handling', 'set up Inertia', or 'run quarry'. Covers DI, routing with OpenAPI, error handling, i18n, testing, auth, RBAC, Inertia.js SSR, and MCP server. Do NOT use for generic Hono apps, plain Cloudflare Workers, or NestJS.
20stratal-framework
>-
7stratal-testing
>-
6stratal-incremental-adoption
>-
6stratal-seeders
>-
5