sql-migrate icon indicating copy to clipboard operation
sql-migrate copied to clipboard

is it possible to create database on first migration?

Open opensas opened this issue 6 years ago • 2 comments
trafficstars

I guess it's not possible because the db every other migration should be run doesn't exist yet, but I'd like to know if there's some workaround or something

ideally, sql-migrate up would create the db and then run the rest of the migrations, and sql-migrate down -limit=0 would end up dropping the whole db.

Is it possible? Or is there a better way to do it? Or maybe it's just a bad idea?


I did a test, and sql-migrate ended up creating the migrations table on the master db (I'm using msssql), and the following migration failed because it couldn't find the migrations table

opensas avatar Mar 27 '19 06:03 opensas

Creating a database is something I always felt that it shouldn't have a place in sql-migrate: it'll make your application unportable because you're hardcoding connection details (in this case the database name).

Always provision a database upfront and pass the connection details as parameters to your application.

rubenv avatar Mar 27 '19 06:03 rubenv

Great, it makes sense, I should handle that with a previous script or something like that. I've just found you answered something similar here great utility BTW, I'm putting it to the test in a medium sized application with a sql db to see how it goes. Marvellous job indeed!

opensas avatar Mar 27 '19 07:03 opensas