Sha256: 0653d7e066fb4de699c3b4534f72207f96a2489d23d47c794b59d1f519a24c4f

Contents?: true

Size: 1.29 KB

Versions: 6

Compression:

Stored size: 1.29 KB

Contents

require 'yaml'
require 'logger'
MIGRATIONS_DIR = 'db/migrate'

namespace :db do
  task :env do
    ENV['RACK_ENV'] ||= 'development'
    DATABASE_ENV = ENV['RACK_ENV']
    require_relative 'database'
  end

  task :migrate => :env do
    ActiveRecord::Migration.verbose = true
    ActiveRecord::Migrator.migrate MIGRATIONS_DIR, ENV['VERSION'] ? ENV['VERSION'].to_i : nil
  end

  task :rollback => :env do
    init_connection
    step = ENV['STEP'] ? ENV['STEP'].to_i : 1
    ActiveRecord::Migrator.rollback MIGRATIONS_DIR, step
  end

  task :version => :env do
    puts "Current version: #{ActiveRecord::Migrator.current_version}"
  end

  task :create_migration do
    name = ENV['NAME']
    abort("no NAME specified. use `rake db:create_migration NAME=create_users`") if !name

    migrations_dir = File.join("db", "migrate")
    version = ENV["VERSION"] || Time.now.utc.strftime("%Y%m%d%H%M%S")
    filename = "#{version}_#{name}.rb"
    migration_name = name.gsub(/_(.)/) { $1.upcase }.gsub(/^(.)/) { $1.upcase }

    FileUtils.mkdir_p(migrations_dir)

    open(File.join(migrations_dir, filename), 'w') do |f|
      f << (<<-EOS).gsub("      ", "")
      class #{migration_name} < ActiveRecord::Migration
        def self.up
        end

        def self.down
        end
      end
      EOS
    end
  end
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
nyny-2.0.0 examples/active_record/Rakefile
nyny-1.0.2 examples/active_record/Rakefile
nyny-1.0.1 examples/active_record/Rakefile
nyny-1.0.0 examples/active_record/Rakefile
nyny-1.0.0.pre1 examples/active_record/Rakefile
little_frankie-1.0.0.pre1 examples/active_record/Rakefile