plentz / lol_dba

lol_dba is a small package of rake tasks that scan your application models and displays a list of columns that probably should be indexed. Also, it can generate .sql migration scripts.
1.59k stars 69 forks source link

Create differently titled migration if migration exists already #55

Open westonganger opened 9 years ago

westonganger commented 9 years ago

I have previously run rails g migration AddMissingIndexes

I wanted to run it again but there is a name clash with the previous migration. Would be helpful it it automatically added a number to the name or something or had an options to manually change the name

plentz commented 9 years ago

@westonganger PR's are welcome. All you need to do is check if the file already exists before printing this message.

westonganger commented 9 years ago

I misunderstood what this was supposed to do. I thought it automatically created a migration file. The best solution I came up with was this but its probably not great and im not sure if using system commands are frowned upon and it will probably slow down the command somewhat significantly.

`bundle exec rake db:migrate:status | grep 'Add missing indexes'`.scan(/Add missing indexes/).count

I would then take that number+1 and append it to the migration name. I also may have to check for existance of bundler gem too.

Let me know what you think, if I shouldn't bother then you can just close the issue.

plentz commented 9 years ago

@westonganger I think that the idea of getting the count is cool, but this way we will depend on grep. I think that's better to use ruby's File API to check if we already have any migration. What do you think?

westonganger commented 9 years ago

Yeah that would be better I just whipped it up quickly. Now that we are ensuring its an unused name is it desired to actually run rails g migration AddMissingIndexes3 and fill the file with the information?