Unable to setup supabase with drizzle

Using this https://orm.drizzle.team/learn/tutorials/drizzle-with-supabase#setup-supabase-and-drizzle-orm to setup supabase but always getting errors on migration and studio scripts. I'm using pnpm and have setup my .env.local variables. Drizzle version:
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10
drizzle-kit: v0.21.2
drizzle-orm: v0.30.10
Drizzle ORM - Drizzle with Supabase Database
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
9 Replies
Mykhailo
Mykhailo7mo ago
Hey @Servesh, what errors do you get?
Servesh
ServeshOP7mo ago
process exit with error code 1
Mykhailo
Mykhailo7mo ago
Could you clarify your workflow please? And when you get the error Also, could you console.log your db_url to be sure that env variables are loaded?
Servesh
ServeshOP7mo ago
Using this drizzle config
import 'dotenv/config'
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
schema: './db/schema.ts',
out: './supabase/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
})
import 'dotenv/config'
import { defineConfig } from 'drizzle-kit'

export default defineConfig({
schema: './db/schema.ts',
out: './supabase/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
})
running npx drizzle-kit migrate. My db url is in .env.local Thanks for your time and interest Okay, so I updated my drizzle config to this and now it's working fine!
import { config } from 'dotenv'
import { defineConfig } from 'drizzle-kit'

config({ path: '.env.local' })

export default defineConfig({
schema: './db/schema.ts',
out: './supabase/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
verbose: true,
})
import { config } from 'dotenv'
import { defineConfig } from 'drizzle-kit'

config({ path: '.env.local' })

export default defineConfig({
schema: './db/schema.ts',
out: './supabase/migrations',
dialect: 'postgresql',
dbCredentials: {
url: process.env.DATABASE_URL!,
},
verbose: true,
})
Mykhailo
Mykhailo7mo ago
Super! Looks like problem with env variables
Servesh
ServeshOP7mo ago
@Mykhailo could we add this to the official docs please Yeah it was, already suspected it
Mykhailo
Mykhailo7mo ago
yep, we will specify it
Servesh
ServeshOP7mo ago
Thank you so much, you guys are awesome
Stefano Sandes
Stefano Sandes7mo ago
If someone here could help with my issue with Supabase too: https://discord.com/channels/1043890932593987624/1238579269991399507
Want results from more Discord servers?
Add your server