mattes / migrate

Database migrations. CLI and Golang library.
Other
2.29k stars 326 forks source link

CLI down with no arguments will drop the entire DB by default, making it unnecessarily dangerous. #289

Open andrewmains12 opened 7 years ago

andrewmains12 commented 7 years ago

Hello,

The current behavior of down is as follows:

migrate down 1 # run one down migration migrate down # run *all* down migrations

Running a down migration is generally a destructive act, making it dangerous. For instance, in the simple migration pair:

-- 1_add_foo.up.sql
ALTER TABLE my_table ADD COLUMN foo int;
-- 1_add_foo.down.sql
ALTER TABLE my_table DROP COLUMN foo int;

the down migration will drop any data in column foo.

Since down migrations typically drop data, having down run all down migrations by default is dangerous--the default of down is to drop your database, which is almost never what you want. It would be preferable imo to make down require an argument, which would eliminate this class of error.

I can work around this by implementing my own CLI off of the lib, but I'd much prefer to use yours :)

Thanks for all the work on this!

Andrew