Setup for multiple databases

Looking to get some help on how to configure drizzle with an application that connects to multiple databases. Establishing different connection pools is pretty intuitive, but I could use some help understanding the setup for different configs for each database and different migration directories.
8 Replies
Angelelz
Angelelz11mo ago
Are this databases related in some way? Are they replicas?
b_patel
b_patelOP11mo ago
Nope, no relationship We might have an analytics db that does some replication with AWS DMS in the future, but not likely right now
Angelelz
Angelelz11mo ago
Are you migrating from another ORM? How did you handle this before? I would suggest creating a new db instance with the drizzle function separately. If you also want to handle the schema and migrations with drizzle, you should definitely have those in different folders to make sure they're not interfering with each other
b_patel
b_patelOP11mo ago
How would I properly setup the config to support 2 dbs? All the examples show a default config so its not clear to me how 2 would be supported.
import type { Config as DrizzleConfig } from "drizzle-kit";

export default {
schema: [
"api/src/db/schema/app1.ts",
],
out: "api/app1/drizzle/migrations/",
driver: "pg",
dbCredentials: {
connectionString:
"postgresql://postgres:docker@localhost:5432",
},
} satisfies DrizzleConfig;
import type { Config as DrizzleConfig } from "drizzle-kit";

export default {
schema: [
"api/src/db/schema/app1.ts",
],
out: "api/app1/drizzle/migrations/",
driver: "pg",
dbCredentials: {
connectionString:
"postgresql://postgres:docker@localhost:5432",
},
} satisfies DrizzleConfig;
Angelelz
Angelelz11mo ago
You would probably need different drizzle config files for each Check for example this repo, that I usually use for manual tests
Angelelz
Angelelz11mo ago
GitHub
GitHub - rphlmr/drizzle-playground
Contribute to rphlmr/drizzle-playground development by creating an account on GitHub.
Angelelz
Angelelz11mo ago
Then you can set up the appropriate one per database in the scripts key in you package.json
b_patel
b_patelOP11mo ago
@Angelelz thank you! This is exactly what I needed.
Want results from more Discord servers?
Add your server