Class: Graffable::MigrationTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- Graffable::MigrationTask
- Defined in:
- lib/graffable/migration_task.rb
Instance Method Summary collapse
-
#initialize ⇒ MigrationTask
constructor
A new instance of MigrationTask.
Constructor Details
#initialize ⇒ MigrationTask
Returns a new instance of MigrationTask.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/graffable/migration_task.rb', line 8 def initialize Sequel.extension :migration namespace = 'graffable:migrate' migrations = File.join( File.dirname(__FILE__), '../../db/migrations' ) desc 'Perform migration down (erase all data)' task "#{namespace}:down" do db = Graffable::Database.connect Sequel::Migrator.run db, migrations, target: 0 puts "<= #{namespace}:down executed" end desc 'Perform migration reset (full erase and migration up)' task "#{namespace}:reset" do db = Graffable::Database.connect Sequel::Migrator.run db, migrations, target: 0 Sequel::Migrator.run db, migrations puts "<= #{namespace}:reset executed" end desc 'Perform migration down (erase all data)' task "#{namespace}:down" do db = Graffable::Database.connect Sequel::Migrator.run db, migrations, target: 0 puts "<= #{namespace}:down executed" end desc 'Perform migration up/down to VERSION' task "#{namespace}:to" do version = ENV['VERSION'].to_i raise 'No VERSION was provided' if version.nil? db = Graffable::Database.connect Sequel::Migrator.run db, migrations, target: version puts "<= #{namespace}:to version=[#{version}] executed" end desc 'Perform migration to latest migration available' task "#{namespace}:up" do db = Graffable::Database.connect Sequel::Migrator.run db, migrations puts "<= #{namespace}:up executed" end end |