🧠Use Prisma as a multi-tenant provider for your application
This version fixes a small bug with Windows and directories with spaces
In this release:
This version of Prisma-multi-tenant now comes with Prisma v2.10.1. (See Prisma release notes)
Unfortunately, Nexus Framework has been deprecated. (See deprecation notice). Therefore, we removed the Nexus plugin and its documentation from the repository
In this release:
--schema
optionThis version of Prisma-multi-tenant now comes with Prisma v2.4.1. (See Prisma release notes)
Redwood is a Framework "Bringing full-stack to the Jamstack", using Prisma to handle your database.
This release introduce a new Redwood plugin, @prisma-multi-tenant/redwood
, which adds multi-tenancy:
api/src/lib/db.js
:
import { MultiTenant, fromContext } from '@prisma-multi-tenant/redwood'
export const multiTenant = new MultiTenant()
export const db = fromContext()
api/src/functions/graphql.js
:
import { multiTenant } from 'src/lib/db'
export const handler = createGraphQLHandler({
schema: makeMergedSchema({
schemas,
services: makeServices({ services }),
}),
context: async ({ event }) => ({
// The name can come from anywhere (headers, token, ...)
db: await multiTenant.get('my_tenant_A').catch(console.error),
}),
})
Check out the documentation and example project to learn more on how to add multi-tenancy to your Redwood apps!
--schema
optionIf your schema isn't placed at the default location (prisma/schema.prisma
), you can now use the --schema
option on the Prisma-multi-tenant CLI to still be able to find it.
pmt init --no-example
prisma/
)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!
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.
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 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!
This release was also an opportunity to improve the onboarding of new users. To do that, nothing beats examples and tutorials!
pmt
command as an alias to the prisma-multi-tenant
command for better developer experiencepmt studio <name>
better handles when port is already in usepmt init
flow to handle more edge casesToday, we release the version 2.1.0! It mainly ships the new dynamic database provider feature coming from [email protected]
You can now have tenants from multiple providers (eg. One on Mysql, the other on Postgresql). No configuration needed on your end, just run prisma-multi-tenant new
and select whichever provider you want. It will just work!
prisma-multi-tenant studio
Today is the day! 🥳
Here is the release of prisma-multi-tenant, compatible with the Prisma2 release and forward. 🎉
Compatible with @prisma/cli@^2.0.0 and after
Note: This version is compatible with @prisma/[email protected]
Upgraded all occurences of @prisma/cli to 2.0.0-beta.6
Note: This version is compatible with @prisma/[email protected]
Upgraded all occurences of @prisma/cli to 2.0.0-beta.5
Note: This version is compatible with @prisma/[email protected]
Upgraded all occurences of @prisma/cli to 2.0.0-beta.4
Following the move of the generated Prisma Client to .prisma/client
, the generated management prisma client was also moved to .prisma-multi-tenant/management
. This should ensure more stability and less re-generations.
prisma/.env
file to access the management env variablesNote: This version is compatible with @prisma/[email protected]
Upgraded all occurences of @prisma/cli to 2.0.0-beta.3
init
with a postgresql management db