Prod database and Test database in Drizzle

I would like to know how you are dealing with having a test (or dev) database in your projects beside the prod database. As I'm using postgre, all my environments are in the same database, just with different schemas. How should that reflect in my drizzle files ? Should I declare each table and each column 3 times ? (for prod, dev and test) I can't just use an env variable, because each time I change its value and try to migrate, drizzle delete the previous schema.
16 Replies
Trustody
TrustodyOP•4mo ago
any feedback, please ? 🥺
Angelelz
Angelelz•4mo ago
So you use different schemas for test, development and prod?
Angelelz
Angelelz•4mo ago
Drizzle ORM - Goodies
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Angelelz
Angelelz•4mo ago
That should solve your issue but I'm not sure that's a good approach. I feel weird about having test, dev and prod all in the same db. I suggest you use docker and have your prod env far away from testing and development
Trustody
TrustodyOP•4mo ago
I agree with you, best would be to completely separate the different environments, but I only have one database at disposal. They asked me to use 3 differents pgSchemas for test, dev and prod I've seen this but this would lead to have everything in one pgSchema with just prefixes on each table name
Angelelz
Angelelz•4mo ago
Drizzle ORM - Config Reference
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Angelelz
Angelelz•4mo ago
You can have as many databases as you want if you used docker
Angelelz
Angelelz•4mo ago
Drizzle ORM - List of commands
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Trustody
TrustodyOP•4mo ago
I'm really not a docker expert, gotta learn it first this looks promising Hello @Angelelz, I'm trying to use Docker for my test database but I don't know why my migrations won't be made
backend_test_app | No config path provided, using default 'drizzle.config.ts'
backend_test_app | Reading config file '/usr/src/app/drizzle.config.ts'
backend_test_app | 0 tables
backend_test_app |
backend_test_app |
backend_test_app | No schema changes, nothing to migrate 😴
backend_test_app | $ bun drizzle-kit migrate
backend_test_app | [bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.
backend_test_app | drizzle-kit: v0.22.8
backend_test_app | drizzle-orm: v0.31.4
backend_test_app |
backend_test_app | No config path provided, using default path
backend_test_app | Reading config file '/usr/src/app/drizzle.config.ts'
backend_test_app | No config path provided, using default 'drizzle.config.ts'
backend_test_app | Reading config file '/usr/src/app/drizzle.config.ts'
backend_test_app | 0 tables
backend_test_app |
backend_test_app |
backend_test_app | No schema changes, nothing to migrate 😴
backend_test_app | $ bun drizzle-kit migrate
backend_test_app | [bun] Warning: async_hooks.createHook is not implemented in Bun. Hooks can still be created but will never be called.
backend_test_app | drizzle-kit: v0.22.8
backend_test_app | drizzle-orm: v0.31.4
backend_test_app |
backend_test_app | No config path provided, using default path
backend_test_app | Reading config file '/usr/src/app/drizzle.config.ts'
I'm getting this, as if my files were empty but i can cat them and they seem intact Do you have any documentation or idea of my mistake ?
Angelelz
Angelelz•4mo ago
If you’re using docker only for the database, you would only need to change the database connection string Let me see if I can find a playground I use to use with docker
Angelelz
Angelelz•4mo ago
GitHub
GitHub - rphlmr/drizzle-playground
Contribute to rphlmr/drizzle-playground development by creating an account on GitHub.
Angelelz
Angelelz•4mo ago
He has a dockerfile with several databases set up
Trustody
TrustodyOP•4mo ago
i'm using docker for both, i'll try to figure it ou
Angelelz
Angelelz•4mo ago
I wouldn’t do it that way unless you had a reason. Using it for just the database lets you only change the connection string based on test prod or dev
Trustody
TrustodyOP•4mo ago
I was asked to push the app as a package to GitHub, so I had to dockerize it. Now, I want to set up tests in the CI/CD pipeline, and using containers that start up and shut down on their own seems like the best way to go, right?
Angelelz
Angelelz•4mo ago
Well if you already have the app and the db in the same container it only makes sense
Want results from more Discord servers?
Add your server