[BUG]: Drizzle migration dont create data base if not existed in postgres
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
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
This is not a bug, this is intentional. The developer is responsible for the creation of the database.
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.
This is not a bug, this is intentional. The developer is responsible for the creation of the database.
With such attitude a developer should not use migrator at all. He should do everything manually.
This is not a bug, this is intentional. The developer is responsible for the creation of the database.
With such attitude a developer should not use migrator at all. He should do everything manually.
But I guess the problem is handling database directly is quite involved, like managing extensions to install as well as other thing, so it is quite personalized, in our case we make some helper scripts that runs before every migration that checks if a database exists and what additional parameter being given to the script, if it doesn't exists, it will just create the database with all the required extension we need, but if it does exists, it won't touch it and go straight into the migration part, unless something like --force is passed an the DB is destroyed and re-built before doing migration
Maybe drizzle could give some middle ground, a good default DB migration but can be extended for specific use case
Prisma creates the database though
then add a flag to create db ... I don't see why not