TalentBox / sequel-rails

A gem for using Sequel with Rails 5.x, 6.x, 7.x, 8.x
http://talentbox.github.io/sequel-rails/
MIT License
326 stars 81 forks source link

rake db:migrate raises error when there is no file in db/migrate #127

Closed gittmaekawa closed 7 years ago

gittmaekawa commented 7 years ago

I encountered an error at rake db:migrate

$ bundle exec rails db:migrate
rails aborted!
NoMethodError: undefined method `>' for nil:NilClass
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/sequel-4.42.1/lib/sequel/extensions/migration.rb:536:in `initialize'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/sequel-4.42.1/lib/sequel/extensions/migration.rb:401:in `new'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/sequel-4.42.1/lib/sequel/extensions/migration.rb:401:in `run'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/sequel-rails-0.9.14/lib/sequel_rails/migrations.rb:9:in `migrate'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/sequel-rails-0.9.14/lib/sequel_rails/railties/database.rake:164:in `block (2 levels) in <top (required)>'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:14:in `block in run_rake_task'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/commands/rake_proxy.rb:11:in `run_rake_task'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/home/vagrant/carering/greenwig/vendor/bundle/ruby/2.3.0/gems/railties-5.0.1/lib/rails/commands.rb:18:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:migrate

I stepped into with debugger and found a possibility that this happens when there is no file in db/migrate.

gittmaekawa commented 7 years ago

I changed the rake task and could avoid this problem:

#sequel-rails-0.9.14/lib/sequel_rails/railties/database.rake:
  task :migrate => 'migrate:load' do
    unless Dir[Rails.root.to_s + "/db/migrate/*"].blank?
      SequelRails::Migrations.migrate_up!(ENV['VERSION'] ? ENV['VERSION'].to_i : nil)
      Rake::Task["#{sequel_rails_namespace}:dump"].invoke if SequelRails.configuration.schema_dump
    end
  end