How to share Drizzle schema in multiple projects?
Hi,
I have an Express.js application running with Drizzle ORM. The schemas are defined and migration are generated in this repository, no problem.
and now I'm going to have another application written in Next.js and it is going to access the same database. How can I share the Drizzle schema in multiple projects?
Currently, I'm duplicating the Drizzle's schema from the previous Express.js application repository and make sure I don't run the migration. Do you have a better suggestion?
2 Replies
A shared database package inside of a monorepo
Thanks, @JipSterk So this how I share the schema in monorepo:
I have created two packages,
db
to store the schema and app
to import the schema:
Note that the drizzle.config.js
is created in db
to generate the migration using drizzle-kit
. Then the schema looks like this,
and the package main script to export the schema,
then I import the schema in the app