migrator.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. module Migrator
  2.   mattr_accessor :offer_migration_when_available
  3.   @@offer_migration_when_available = true
  4.   def self.migrations_path
  5.     "#{RAILS_ROOT}/db/migrate"
  6.   end
  7.   def self.available_migrations
  8.     Dir["#{migrations_path}/[0-9]*_*.rb"].sort_by { |name| name.scan(/d+/).first.to_i }
  9.   end
  10.   def self.current_schema_version
  11.     ActiveRecord::Migrator.current_version rescue 0
  12.   end
  13.   def self.max_schema_version
  14.     available_migrations.size
  15.   end
  16.   def self.db_supports_migrations?
  17.     ActiveRecord::Base.connection.supports_migrations?
  18.   end
  19.   def self.migrate(version = nil)
  20.     ActiveRecord::Migrator.migrate("#{migrations_path}/", version)
  21.   end
  22. end