rubenv / sql-migrate

SQL schema migration tool for Go.
MIT License
3.24k stars 280 forks source link

is it possible to create database on first migration? #134

Open opensas opened 5 years ago

opensas commented 5 years ago

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

rubenv commented 5 years ago

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.

opensas commented 5 years ago

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!