Sha256: 545c28b7abc37b35d51b601be740903de02b9280ff9cec9f5d0efcc59bb1cf75

Contents?: true

Size: 1.32 KB

Versions: 5

Compression:

Stored size: 1.32 KB

Contents

load 'active_record/railties/databases.rake'

ActiveRecord::Tasks::DatabaseTasks.tap do |config|
  config.db_dir = 'db'
  config.migrations_paths = ['db/migrate']
  config.seed_loader = Class.new do
    def self.load_seed
      load Grape::App.root.join('db', 'seeds.rb').to_s
    end
  end
end

namespace :db do
  Rake::Task['load_config'].clear

  task load_config: :environment do
    ActiveRecord::Tasks::DatabaseTasks.tap do |config|
      config.root   = Grape::App.root
      config.env    = Grape::App.env
      config.database_configuration = ActiveRecord::Base.configurations
    end
  end

  desc 'Create a new migration using NAME'
  task migration: :environment do
    name = ENV.fetch('NAME', nil)
    abort 'No NAME specified. Example usage: `rake db:migration NAME=create_widgets`' unless name

    migrations_path = ActiveRecord::Migrator.migrations_paths.first
    path = File.join(migrations_path, "#{Time.now.utc.strftime('%Y%m%d%H%M%S')}_#{name}.rb")

    ar_version = [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR].join('.')

    FileUtils.mkdir_p(migrations_path)
    File.write path, <<~RUBY
      class #{name.camelize} < ActiveRecord::Migration[#{ar_version}]
        def change
        end
      end
    RUBY
    puts path
  end

  namespace :test do
    desc 'Prepare test DB'
    task :prepare
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
grape-app-0.11.3 lib/grape/app/tasks/databases.rake
grape-app-0.11.2 lib/grape/app/tasks/databases.rake
grape-app-0.11.1 lib/grape/app/tasks/databases.rake
grape-app-0.11.0 lib/grape/app/tasks/databases.rake
grape-app-0.10.1 lib/grape/app/tasks/databases.rake