Finding it hard to get started with vercel postgres
Hi guys, I'm totally new to Drizzle and I want to know if there is any blog/article or something where I can read step by step guide to get started with nextjs + vercel postgres with Drizzle ORM. I tried to read many articles including official Drizzle docs and watched some YT videos also but couldn't grasp where they're getting all the details like creating migrate and push scripts, creating schema.ts etc. which I couldn't find in Drizzle docs.
38 Replies
I have a big app running with Prisma that I'd like to migrate to drizzle, but first I'm trying to create some small projects to get familiar with drizzle
I found prisma is very easy to setup and get started with but drizzle is kinda confusing at this moment
I think the docs is a good starting point, can you specify what you did not found in the docs?
lets start with the beginning, I'll refer to prisma. In prisma we can specify our schema and just run
prisma migrate dev
or prisma db push
or prisma db pull
to confirm if we're in sync with remote db or not. How to do it with drizzle?Ive go some issue too with the official docs (TS error, and others stuff...)
Medium
The Data-Access-Pattern first approach with Drizzle
Bringing database and backend work into a single TS file is just as beneficial as developing a full-stack application in one language.
Add script no ?
Yep I know but where is it in the official docs
I came across many things like these scripts too
but couln't find in official docs
At this moment I just want to connect with my vercel postgres
did you check the drizzle kit docs?
Drizzle ORM - Overview
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Nope
before that is Drizzle ORM
So I started from there
And got confused so came here
yes, but think about them as different tools
So lets start from the very beginning
I created a vercel postgres db and added it to env variables
now according to docs https://orm.drizzle.team/docs/get-started-postgresql#vercel-postgres
Drizzle ORM - PostgreSQL
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
I installed these
made a
index.ts
file inside drizzle/
Now what is next?
I want to create some tables in my dbok, you have to take into account 4 things,
1. you can create and manage your schema with drizzle [drizzle-orm] https://orm.drizzle.team/docs/sql-schema-declaration
2. you can generate migrations files that are the ones in charge of telling your database how to change to become what you have defined in yous schema (point 1) [drizzle-kit]
3. you apply your changes with [drizzle-kit] via terminal commands defined in the package.json
4. you can query with [drizzle-orm] your database in your application code
Drizzle ORM - Overview
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
in package.json inside scripts
you run this commands with
npm run migration:generate
...you have here 2 interesting post
https://medium.com/@andriisherman
Medium
Andrii Sherman – Medium
Read writing from Andrii Sherman on Medium. Building Drizzle ORM. Every day, Andrii Sherman and thousands of other voices read, write, and share important stories on Medium.
Ok let me go through all of these
Thanks @amg
I'll let you know shortly if it worked or not
you welcome!
reach me if you need something
🙌🏻
Hey @amg
Is there anything wrong with this schema file??
I run
drizzle-kit generate:pg --schema ./db/schema.ts --out=./db/migrations
and got the .sql
files under db/migrations
Now I want to push it to neon db for that I have configured drizzle.config.ts
like this:
But when I'm running
drizzle-kit push
it shows this error:just to be clear about deps I deleted and installed node modules
but its still same
This is my package.json file if it helps
can yo try
pnpx drizzle-kit push:pg
?yes, sure
give me a minute
unable to open studio also
Where are you executing it? Your machine?
nope
its a codespace
GitHub
GitHub - Naeem-gg/learn_drizzle
Contribute to Naeem-gg/learn_drizzle development by creating an account on GitHub.
is it possible to tell Drizzle which setup script to run? I want to have one script to work with local docker postgres (postgresjs) and another to run on Vercel (@vercel/postgress)?
you can specify different config file per script
for example
were you asking that?
Hi @amg, Thanks for your support in getting me started with drizzle
I can seamlessly deal with drizzle now
only one problem is there which is I think with
pnpm
,I have created an issue here also for it
https://github.com/drizzle-team/drizzle-orm/issues/2032GitHub
[BUG]:drizzle-kit commands not working with pnpx · Issue #2032 · dr...
What version of drizzle-orm are you using? 0.30.2 What version of drizzle-kit are you using? 0.20.14 Describe the Bug I was debugging my code when no drizzle-kit command was working, all the comman...
Hi. Thanks for the response.
I guess that could be it...
Will have a try and I'll respond with the info 😄
hi, I found this blog post really really helpful to get started with Vercel Postgres and Drizzle. Maybe you could find some answers to your questions.
https://www.thisdot.co/blog/configure-your-project-with-drizzle-for-local-and-deployed-databases
🙌🏻😊