0

当我运行 db:migrate 任务时,迁移实际上并没有发生。这是我的 Rakefile 的代码:

namespace :db do
  desc "Migrate the database through scripts in lib/generators/facebook_event_fetcher/install/templates. Target specific version with VERSION=x"
  task :migrate => :environment do
    ActiveRecord::Migration.verbose = true
    #ActiveRecord::Migrator.migrate('db/migrate', ENV["VERSION"] ? ENV["VERSION"].to_i : nil )
    ActiveRecord::Migrator.migrate('lib/generators/facebook_event_fetcher/install/templates', nil)
  end

  task :environment do
    ActiveRecord::Base.establish_connection(YAML.load_file("config/database.yml"))
    ActiveRecord::Base.logger = Logger.new(File.open('db/database.log', 'a')) 
  end
end

您可以仔细查看 Github 存储库: https ://github.com/mabounassif/facebook_event_fetcher/blob/master/Rakefile#L42

为什么不会触发迁移?

4

1 回答 1

0

ActiveRecord::Migrator 需要迁移文件以数字或时间戳开头,以便跟踪版本。这是我为在您的存储库中运行迁移所做的工作:

facebook_event_fetcher/lib/generators/facebook_event_fetcher/install/templates$ mv create_delayed_jobs.rb 001_create_delayed_jobs.rb
facebook_event_fetcher/lib/generators/facebook_event_fetcher/install/templates$ cd ../../../../..
facebook_event_fetcher/lib$ cd ..
facebook_event_fetcher$ rake db:migrate
==  CreateDelayedJobs: migrating ==============================================
-- create_table(:delayed_jobs, {:force=>true})
   -> 0.0076s
-- add_index(:delayed_jobs, [:priority, :run_at], {:name=>"delayed_jobs_priority"})
   -> 0.0004s
==  CreateDelayedJobs: migrated (0.0081s) =====================================
于 2012-12-07T23:58:55.307 回答