2.2.0
Today, we release the version 2.2.0! 🥳
It includes many changes, including a new architecture (multiple packages), nexus & blitz plugins, many examples, and more stuff!
New architecture
Prisma-multi-tenant has been split into multiple smaller packages:
@prisma-multi-tenant/shared
with code used by other packages@prisma-multi-tenant/client
which is used by your projects to access tenantsprisma-multi-tenant
is the CLI that you will use to manage and migrate your tenants (same as before)
Here are the steps to migrate to this new architecture in your project:
npm i -g [email protected] # Install the new version of the CLI globally
npm uninstall prisma-multi-tenant # Remove `prisma-multi-tenant` from your project
npm install @prisma-multi-tenant/client # Add the client in your project
Then, in your code, change the following:
- import { MultiTenant } from "prisma-multi-tenant"
+ import { MultiTenant } from "@prisma-multi-tenant/client"
This new architecture removes the need for your project to add lot of dependencies coming from the CLI.
Nexus plugin
The Nexus Framework is a "Node.js TypeScript-focused code-first GraphQL framework", developed by Prisma.
Nexus can be coupled with Prisma to handle the data of your application, with a simple plugin:
import { use } from 'nexus'
import { prisma } from 'nexus-plugin-prisma'
use(prisma())
This release introduce a new Nexus plugin, @prisma-multi-tenant/nexus
, which wraps the prisma plugin and adds multi-tenancy:
import { use } from 'nexus'
import { prismaMultiTenant } from '@prisma-multi-tenant/nexus'
const tenantRouter = (req) => {
// The name can come from anywhere (headers, token, ...)
return 'my_tenant_A'
}
use(prismaMultiTenant({ tenantRouter }))
Check out the documentation and example project to learn more on how to add multi-tenancy to your Nexus apps!
Blitz plugin
Blitz is a "The Fullstack React Framework", using Prisma to handle your database.
This release introduce a new Blitz plugin, @prisma-multi-tenant/blitz
, which adds multi-tenancy:
const { multiTenantMiddleware } = require('@prisma-multi-tenant/blitz')
module.exports = {
// ...
middleware: [
multiTenantMiddleware((req, res) => {
// The name can come from anywhere (headers, token, ...)
return 'my_tenant_A'
}),
],
}
export default async function getProjects(args, ctx) {
const projects = await ctx.db.project.findMany(args)
return projects
}
Check out the documentation and example project to learn more on how to add multi-tenancy to your Blitz apps!
Documentation and examples
This release was also an opportunity to improve the onboarding of new users. To do that, nothing beats examples and tutorials!
- How to integrate with:
- Examples
- Basic (JS)
- Basic (TS)
- Express
- Apollo
- Nexus
- Blitz (Coming soon)
- Redwood (Coming soon)
More stuff
- Fix issues when running cli on Windows
- Adds
pmt
command as an alias to theprisma-multi-tenant
command for better developer experience pmt studio <name>
better handles when port is already in use- Improves
pmt init
flow to handle more edge cases