How to put Drizzle schemas in shared folder (monorepo) and have api's drizzle.config recognize them
I have a monorepo with top level folders: shared, frontend, backend. I've put my Drizzle tables in the shared folder so that I can have the inferred TS types in the shared folder as well, because both the frontend and backend use them.
How do I point to these schemas in the shared folder for when I set up my drizzle.config in my backend folder?
On a separate but maybe related note, intellisense is giving me this error when using my pgTables in the api after importing them from the shared folder:
Property '[IsDrizzleTable]' is missing in type 'PgTable
Thank you so much!3 Replies
P.P.S - does it make sense for me to pull the Drizzle tables into the shared folder? Or is there a better way to set this up - again, I need both frontend and backend to see the types in production (frontend and backend are deployed to separate servers), and I'm inferring the TS types like this per the docs:
And here's my
Drizzle.config.ts
which is in the root of my backend folder:
I have a similar monorepo structure, with each database definition in different services.
My config looks like this:
import { defineConfig } from "drizzle-kit";
export default defineConfig({
driver: "aws-data-api",
dialect: "postgresql",
dbCredentials: {
database: Something,
secretArn: Something,
resourceArn: Something,
},
// Pick up all our schema files
schema: ["./packages/**/*.sql.ts"],
out: "./packages/core/migrations",
});
And is working like a charm.so your approach was to place the config file in the root level of the monorepo?
I think the preferred way would be to actually just point a namespace like a npm package in the same workspace/monrepo like so:
I actually am trying to achieve this, I can run with no errors but it ends up with Drizzle dropping all my tables and having to drop migrations after that...
I hoped this would be possible with less effort
I just ended up moving all drizzle kit related things into a data package that exposes typings via exports - the migrations are triggered if any change happens in the db package which is where the schema is anyway so that should be safe enough - if you're curious Im using turborepo to orchestrate the tasks