【问题标题】:How to tell if rake db:migrate and rake db:seed were successful如何判断 rake db:migrate 和 rake db:seed 是否成功
【发布时间】:2023-04-09 14:13:01
【问题描述】:

Ruby rake db:seed aborting due to ** Execute db:abort_if_pending_migrations,但我认为所有迁移都成功了。

这是我运行 rake db:migrate --trace 时输出的最后一部分

    ** Invoke db:load_config (first_time)
    ** Execute db:load_config
    ** Execute db:migrate
    ** Invoke db:_dump (first_time)
    ** Execute db:_dump
    ** Invoke db:schema:dump (first_time)
    ** Invoke environment 
    ** Invoke db:load_config 
    ** Execute db:schema:dump

我认为这意味着它是成功的(我没有看到任何中止)?

然后当我运行 rake db:seed --trace 我得到(总结):

    ** Invoke db:seed (first_time)
    ** Execute db:seed
    ** Invoke db:abort_if_pending_migrations (first_time)
    ** Invoke environment (first_time)
    ** Execute environment
    loading plugins

(插件加载没有错误)然后:

    ** Execute db:abort_if_pending_migrations

这是否意味着迁移和种子工作正常? 感谢您的宝贵时间和意见!

【问题讨论】:

    标签: ruby-on-rails ruby schema seed dbmigrate


    【解决方案1】:

    如果它没有中止,它就成功了。拍下look at the code:

    # desc "Raises an error if there are pending migrations"
    task :abort_if_pending_migrations => :environment do
      pending_migrations = ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations
    
      if pending_migrations.any?
        puts "You have #{pending_migrations.size} pending #{pending_migrations.size > 1 ? 'migrations:' : 'migration:'}"
        pending_migrations.each do |pending_migration|
          puts '  %4d %s' % [pending_migration.version, pending_migration.name]
        end
        abort %{Run `rake db:migrate` to update your database then try again.}
      end
    end
    

    如果没有任何待处理的迁移,它实际上什么都不做。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-06
      • 2015-07-13
      • 2014-11-07
      • 2013-09-21
      • 1970-01-01
      • 2016-11-19
      • 2013-02-13
      相关资源
      最近更新 更多