【问题标题】:How to find out database migration logs on Rails?如何在 Rails 上查找数据库迁移日志?
【发布时间】:2013-04-27 04:55:02
【问题描述】:

我想使用 STEP 参数将我的数据库回滚到 Rails 上的某个版本,但我不知道应该回滚多少步,所以我想检查迁移日志。我可以在 Rails (v3.2.13) 上这样做吗?

【问题讨论】:

  • 您知道要回滚到的具体迁移

标签: ruby-on-rails ruby database


【解决方案1】:

尝试以下方法:

rake db:migrate:status

它将为您提供以下输出,up 表示迁移已运行,down 尚未运行:

Status   Migration ID    Migration Name
--------------------------------------------------
   up     20120328154345  Devise create users
   up     20120331182021  Create websites

【讨论】:

    【解决方案2】:

    您可以尝试获取迁移版本 由

     >  ActiveRecord::Migrator.current_version
       (38.7ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" 
     => 20130403113845 
    1.9.3-p392 :002 > ActiveRecord::Migrator.get_all_versions
       (0.8ms)  SELECT "schema_migrations"."version" FROM "schema_migrations" 
     => [20130327085819, 20130327085820, 20130327085821, 20130327085822, 20130327085823, 20130327085824, 20130327085825, 20130327085826, 20130327085827, 20130327085828, 20130327085829, 20130327085830,........
    

    或者您可以使用要回滚并使用的特定迁移的时间戳

    rake db:migrate:down VERSION= 时间戳

    【讨论】:

      猜你喜欢
      • 2010-12-10
      • 2013-08-15
      • 2012-03-12
      • 2012-07-10
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 2017-02-18
      • 2012-10-20
      相关资源
      最近更新 更多