如何判断rake db:migrate和rake db:seed是否成功

4

由于执行 db:abort_if_pending_migrations 命令时,我认为所有迁移都已成功完成,因此 Ruby rake db:seed 中止。

下面是运行 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

这是否意味着迁移和种子数据已经正常工作了呢?感谢您的时间和输入!
1个回答

8
如果它没有中止,那么它就成功了。看一下代码
# 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

如果没有未完成的迁移,则此操作实际上不会执行任何操作。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接