Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I have a project. Migrations are stored in lib/foo/schema/xxx_description.rb,
- # with classes called Foo::Schema::Description.
- class Foo::Schema
- # Pretty simple, just tell AR to migrate based on my stored migrations
- def self.up
- ActiveRecord::Base.logger ||= Logger.new(StringIO.new)
- ActiveRecord::Migrator.up(migrations_path)
- end
- def self.migrations_path
- File.expand_path('../schema', __FILE__)
- end
- # Oh, but to make AR happy, the migration class names need to exist in the
- # global namespace, so I need to load my migrations and export all the
- # constants in Foo::Schema into the global namespace.
- Dir.entries(migrations_path).each do |file|
- path = File.join(migrations_path, file)
- require path if File.file?(path)
- end
- constants.each do |const_name|
- Kernel.const_set(const_name, const_get(const_name))
- end
- end
Add Comment
Please, Sign In to add comment