Sha256: 65b3c03bb75838dc56f4930d0289ad2b92f8fa54bac05a356cd1baf256db6fd9

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

require 'tako'

namespace :db do
  namespace :tako do
    task :load_config do
      Tako.load_connections_from_yaml
    end

    task :check_protected_environments => [:environment, :load_config] do
      ActiveRecord::Tasks::DatabaseTasks.check_protected_environments!
    end

    task :create do
      (Tako.config[Tako.env] || []).values.each do |conf|
        ActiveRecord::Tasks::DatabaseTasks.create(conf)
      end
    end

    task :migrate => [:environment] do
      paths = ActiveRecord::Tasks::DatabaseTasks.migrations_paths
      # load all migration files
      paths.each do |path|
        Dir[File.join(path, "*")].each {|f| require f }
      end

      Tako.with_all_shards do
        version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
        revert = !!ENV["DOWN_MIGRATION"]

        migrations = if version
          [
            ActiveRecord::Migrator.migrations(paths).find {|proxy| proxy.version == version }.name.constantize
          ]
        else
          ActiveRecord::Migrator.migrations(paths).map(&:name).map(&:constantize)
        end

        ActiveRecord::Migration.run(*migrations, revert: revert)
      end
    end

    namespace :migrate do
      task :up => ['db:tako:migrate']

      task :down  => [:environment] do
        ENV["DOWN_MIGRATION"] = "y"
        Rake::Task['db:tako:migrate'].invoke
      end
    end

    task :drop => [:load_config, :check_protected_environments] do
      (Tako.config[Tako.env] || []).values.each do |conf|
        ActiveRecord::Tasks::DatabaseTasks.drop(conf)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tako-0.2.0 lib/tako/railties/databases.rake