drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.2k stars 617 forks source link

[BUG]: Drizzle migration dont create data base if not existed in postgres #2768

Closed lord007tn closed 1 week ago

lord007tn commented 2 months ago

What version of drizzle-orm are you using?

0.32.2

What version of drizzle-kit are you using?

0.23.2

Describe the Bug

not sure if its a bug or a feature

When starting a migration and running drizzle-kit migrate if database not existed locally it rise an error.

Expected behavior

it should create the database if not existed like prisma do ( i came from prisma background )

Environment & setup

System: Windows 11 Bun: 1.1.21

deanrih commented 2 months ago

I believe this is intentional, the migration only do the table schema migration, however someone from drizzle team probably could clarify, anyway, as a workaround we have our custom script for migration and add it to the package.json scripts, when the script is executed, it first check if the database exists or not, if not it create the database otherwise do nothing, and then additionally the script ensuring the extensions are created CREATE EXTENSION IF NOT EXISTS ...; and after that finally the actual migration script got executed and run the migrate function from drizzle migrator

L-Mario564 commented 1 week ago

This is not a bug, this is intentional. The developer is responsible for the creation of the database.

gunslingor commented 6 days ago

IMHO, developer should be responsible for standing up a DB server for certain... but the DB itself is debatable IMHO. In Dev mode, we tear down and redeploy fresh constantly. In Prod mode, we definitely want safeties. Would be real nice to have the 0000 migration default to CREATE DB blah blah. Remember, the hope is that 10 million people use your software... but in the end its only purpose is doing work for them and saving them time... one has to look at every crevasse, every benefit danger and drawback... great thing about software, everyone can be made happy... the only real challenge is organization... IMHO.