Class: OpenHood::Rake::SequelTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- OpenHood::Rake::SequelTask
- Defined in:
- lib/openhood/rake/sequel.rb
Instance Method Summary collapse
- #base_path ⇒ Object
- #config ⇒ Object
- #connection ⇒ Object
- #default_options ⇒ Object
-
#initialize ⇒ SequelTask
constructor
A new instance of SequelTask.
- #path ⇒ Object
Constructor Details
#initialize ⇒ SequelTask
Returns a new instance of SequelTask.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/openhood/rake/sequel.rb', line 30 def initialize desc "Sequel migration" namespace :db do namespace :migrate do desc "Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x" task :redo => [ "db:rollback", "db:migrate" ] end desc "Migrate the database through scripts in db/migrate. Target specific version with VERSION=x" task :migrate do connection = [:target] = ENV["VERSION"].to_i if ENV["VERSION"] Sequel::Migrator.run(Sequel::Model.db, path, ) end desc "Rolls the schema back to the previous version. Specify the number of steps with STEP=n" task :rollback do connection step = ENV["STEP"] ? ENV["STEP"].to_i : 1 target = Sequel::Migrator.get_current_migration_version(Sequel::Model.db) - step Sequel::Migrator.run(Sequel::Model.db, path, .merge({:target => target})) end desc "Retrieves the current schema version number" task :version do connection puts "Current version: #{Sequel::Migrator.get_current_migration_version(Sequel::Model.db, )}" end end end |
Instance Method Details
#base_path ⇒ Object
9 10 11 |
# File 'lib/openhood/rake/sequel.rb', line 9 def base_path File.('.') end |
#config ⇒ Object
17 18 19 20 |
# File 'lib/openhood/rake/sequel.rb', line 17 def config environment = ENV["RACK_ENV"] || "development" @config ||= YAML.load_file(File.join(base_path, "config", "#{environment}.yml")) end |
#connection ⇒ Object
22 23 24 |
# File 'lib/openhood/rake/sequel.rb', line 22 def connection Sequel.connect(config[:db][:uri]) end |
#default_options ⇒ Object
26 27 28 |
# File 'lib/openhood/rake/sequel.rb', line 26 def {:table => :"#{config[:app_name]}_schema_info", :column => :version} end |
#path ⇒ Object
13 14 15 |
# File 'lib/openhood/rake/sequel.rb', line 13 def path File.join(base_path, "migrations") end |