Budi
Budi
Explore posts from servers
DTDrizzle Team
Created by Budi on 10/27/2024 in #help
How to keep dev and production DBs in sync?
I think I will write a blog post about this once I figure it out, since it's been hard to find any resources for this process and the Drizzle docs aren't explicit about it either.
8 replies
DTDrizzle Team
Created by Budi on 10/27/2024 in #help
How to keep dev and production DBs in sync?
I'm using Railway for hosting which creates a new environment of my app and database for each PR. This DB will have its own URLs which are dynamically injected by Railway. I believe I'm successfully accessing these with how I've configured my drizzle-*.config.ts files. I'd love to know what a decent process would be for testing a PR in a staging environment, and then running those same migrations in my production environment. I would think I need to do this: 1. Create PR which spawns a staging env and db. Run generate on that staging db to generate the migration files. Then add migrate in my start scripts (I'm building with Docker) to have the migrations be run on deployment (when I commit these changes to Github). 2. Assuming state between the staging and production environments are the same, this should mean that when merging to main, the same migration files that have been generated the staging db can be applied to production db. Is this the right way to do this? Any suggestions, articles or references you could share wrt how to do this best would be much appreciated.
8 replies
DTDrizzle Team
Created by Budi on 10/27/2024 in #help
How to keep dev and production DBs in sync?
I've now succeeded by doing pnpm db:prod:generate and pnpm db:prod:migrate but it required me dropping the existing tables on the database. Is there a command I can use to first introspect the current database state to ensure the generate will create the right SQL?
8 replies
DTDrizzle Team
Created by Budi on 10/27/2024 in #help
How to keep dev and production DBs in sync?
Thanks for the response. How can I run individual migrations? I'm lacking an understanding of the workflow I should use to separate my local dev migrations vs. my production ones. The best solution I could find was the one provided here (https://github.com/drizzle-team/drizzle-orm/discussions/2832?sort=top#discussioncomment-10463438). Creating two different Drizzle config files for dev and production respectively. I have now done this as such:
drizzle-dev.config.ts:

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations/dev',
dialect: 'postgresql',
dbCredentials: {
url: getDbUrl() as string,
ssl: process.env.NODE_ENV === 'production' ? 'require' : undefined
},
strict: true
})
drizzle-dev.config.ts:

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations/dev',
dialect: 'postgresql',
dbCredentials: {
url: getDbUrl() as string,
ssl: process.env.NODE_ENV === 'production' ? 'require' : undefined
},
strict: true
})
drizzle-prod.config.ts:

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: getDbUrl() as string,
ssl: process.env.NODE_ENV === 'production' ? 'require' : undefined
},
strict: true
})
drizzle-prod.config.ts:

export default defineConfig({
schema: './src/lib/database/schema.ts',
out: './.drizzle/migrations',
dialect: 'postgresql',
dbCredentials: {
url: getDbUrl() as string,
ssl: process.env.NODE_ENV === 'production' ? 'require' : undefined
},
strict: true
})
And I've defined my scripts as such:
package.json:

"db:generate": "dotenvx run -- drizzle-kit generate --config drizzle-dev.config.ts",
"db:migrate": "dotenvx run -- drizzle-kit migrate --config drizzle-dev.config.ts",
"db:clear": "dotenvx run -- vite-node .src/lib/database/clear.ts",
"db:seed": "dotenvx run -- vite-node .src/lib/database/seed.ts",
"db:studio": "dotenvx run -- drizzle-kit studio --config drizzle-dev.config.ts",
"db:prod:generate": "NODE_ENV=production dotenvx run -- drizzle-kit generate --config drizzle-prod.config.ts",
"db:prod:migrate": "NODE_ENV=production dotenvx run -- vite-node .drizzle/migrate.ts",
package.json:

"db:generate": "dotenvx run -- drizzle-kit generate --config drizzle-dev.config.ts",
"db:migrate": "dotenvx run -- drizzle-kit migrate --config drizzle-dev.config.ts",
"db:clear": "dotenvx run -- vite-node .src/lib/database/clear.ts",
"db:seed": "dotenvx run -- vite-node .src/lib/database/seed.ts",
"db:studio": "dotenvx run -- drizzle-kit studio --config drizzle-dev.config.ts",
"db:prod:generate": "NODE_ENV=production dotenvx run -- drizzle-kit generate --config drizzle-prod.config.ts",
"db:prod:migrate": "NODE_ENV=production dotenvx run -- vite-node .drizzle/migrate.ts",
8 replies
DTDrizzle Team
Created by Nate Vukovich on 3/9/2024 in #help
Setting up Drizzle with 2 DB sources
Can you explain how you did this? Trying to use local and hosted Postgres in dev and production respectively, but can't get the migrations to work on production since the db's out of sync.
3 replies
DTDrizzle Team
Created by regex on 6/22/2024 in #help
Is this a bad pattern to do? I wanna call my local postgre while developing and use neon in prod.
Curious about the same. Have you figured out how to get this to work?
5 replies
DTDrizzle Team
Created by Boby on 9/11/2024 in #help
error in production, using Vercel
No sweat. Hope you were able to figure it out.
9 replies
DTDrizzle Team
Created by Boby on 9/11/2024 in #help
error in production, using Vercel
If you sign up with this ref link I get some credits 🙂 https://railway.app?referralCode=hxCjRd
9 replies
DTDrizzle Team
Created by Boby on 9/11/2024 in #help
error in production, using Vercel
I would try hosting this on Railway. They conveniently allow you to create Postgres instances next to your app.
9 replies
DTDrizzle Team
Created by peterstnsz on 6/1/2024 in #help
Supabase + Drizzle + Nuxt 3 + Node - SSL 'SELF_SIGNED_CERT_IN_CHAIN' and drizzle-kit studio issues
This worked for me too. Thanks for sharing this.
5 replies
DTDrizzle Team
Created by Budi on 3/31/2024 in #help
What's the best way to query my db?
Thanks -- I suspect the same.
8 replies
DTDrizzle Team
Created by Budi on 3/31/2024 in #help
What's the best way to query my db?
Bumping this, thank you.
8 replies
DTDrizzle Team
Created by Budi on 3/30/2024 in #help
Studio not enough info to infer relation
And the reason why is because the tags table isn't related to posts directly, so I have to use the tagsToPosts table which defines those relationships?
19 replies
DTDrizzle Team
Created by Budi on 3/30/2024 in #help
Studio not enough info to infer relation
That fixed it! Good eye.
19 replies
DTDrizzle Team
Created by Budi on 3/15/2024 in #help
Can't access innerJoin result in page data using Svelte
Ah I found the issue. While it was being returned from layout.server.ts I wasn't passing it to the client in layout.ts. Thanks for your help everyone.
4 replies
DTDrizzle Team
Created by Budi on 3/15/2024 in #help
Can't access innerJoin result in page data using Svelte
Thanks. I thought so too but restarting the TS or Svelte language servers isn't resolving the issue. Any idea what else it could be?
4 replies
DTDrizzle Team
Created by Boxer on 11/29/2023 in #help
Supabase/postgres get query is stuck on prod app
For your Supabase connection string
25 replies
DTDrizzle Team
Created by nils_77339 on 8/16/2023 in #help
Setting up Drizzle with Supabase in Next.js App Router
Looks like an import issue
7 replies
DTDrizzle Team
Created by Boxer on 11/29/2023 in #help
Supabase/postgres get query is stuck on prod app
@Boxer did you try the new Supavisa connection Pooler? Might resolve things
25 replies
DTDrizzle Team
Created by boggin on 12/1/2023 in #help
Drizzle + Sveltekit + Cloudflare + Supabase cannot get to work.
Did you try postgres-js instead of node-postgres for the drizzle import? Worked for me
6 replies