Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 161 lines (132 sloc) 5.169 kb
1 2 3 4 5 6 7 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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
require 'rubygems'
require 'rake'
require "yaml"
require "active_support"
require 'active_support/json'
begin
  require 'metric_fu'
  MetricFu::Configuration.run do |config|
    config.metrics = [:churn,:flay, :flog, :reek, :roodi, :saikuro]
    config.graphs = [:flog, :flay, :reek, :roodi]
    config.flay = { :dirs_to_flay => ['spec', 'lib'] }
    config.flog = { :dirs_to_flog => ['spec', 'lib'] }
    config.reek = { :dirs_to_reek => ['spec', 'lib'] }
    config.roodi = { :dirs_to_roodi => ['spec', 'lib'] }
    config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
  end
rescue LoadError
end

begin
  require 'jeweler'
  Jeweler::Tasks.new do |gem|
    gem.name = "ar-octopus"
    gem.summary = "Easy Database Sharding for ActiveRecord"
    gem.description = "This gem allows you to use sharded databases with ActiveRecord. this also provides a interface for replication and for running migrations with multiples shards."
    gem.email = "tchandy@gmail.com"
    gem.homepage = "http://github.com/tchandy/octopus"
    gem.authors = ["Thiago Pradi", "Mike Perham", "Amit Agarwal"]
    gem.add_development_dependency "rspec", ">= 1.2.9"
    gem.add_dependency('activerecord')
    gem.version = "0.0.6"
  end
  Jeweler::GemcutterTasks.new
rescue LoadError
  puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

require 'spec/rake/spectask'
Spec::Rake::SpecTask.new(:spec) do |spec|
  spec.libs << 'lib' << 'spec'
  spec.spec_files = FileList['spec/**/*_spec.rb']
end

Spec::Rake::SpecTask.new(:rcov) do |spec|
  spec.libs << 'lib' << 'spec'
  spec.pattern = 'spec/**/*_spec.rb'
  spec.rcov = true
end

task :spec => :check_dependencies

task :default => :spec

require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
  version = File.exist?('VERSION') ? File.read('VERSION') : ""

  rdoc.rdoc_dir = 'rdoc'
  rdoc.title = "octopus #{version}"
  rdoc.rdoc_files.include('README*')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

namespace :db do
  desc 'Build the databases for tests'
  task :build_databases do
    mysql_user = ENV['MYSQL_USER'] || "root"
    postgres_user = ENV['POSTGRES_USER'] || "postgres"
    (1..5).each do |idx|
      %x( echo "create DATABASE octopus_shard#{idx} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{mysql_user})
    end
    
    %x( createdb -E UTF8 -U #{postgres_user} octopus_shard1 )
  end

  desc 'Drop the tests databases'
  task :drop_databases do
    mysql_user = ENV['MYSQL_USER'] || "root"
    postgres_user = ENV['POSTGRES_USER'] || "postgres"
    (1..5).each do |idx|
      %x( mysqladmin --user=#{mysql_user} -f drop octopus_shard#{idx} )
    end
    
    %x( dropdb -U #{postgres_user} octopus_shard1 )
  end

  desc 'Create tables on tests databases'
  task :create_tables do
    Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/spec"))
    require "database_connection"
    require "octopus"
    [:master, :brazil, :canada, :russia, :alone_shard, :postgresql_shard].each do |shard_symbol|
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:users) do |u|
        u.string :name
        u.integer :number
        u.boolean :admin
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:clients) do |u|
        u.string :country
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:cats) do |u|
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:items) do |u|
        u.string :name
        u.integer :client_id
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:schema_migrations) do |u|
        u.string :version, :unique => true, :null => false
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:computers) do |u|
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:keyboards) do |u|
        u.string :name
        u.integer :computer_id
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:roles) do |u|
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:permissions) do |u|
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:permissions_roles, :id => false) do |u|
        u.integer :role_id
        u.integer :permission_id
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:assignments) do |u|
        u.integer :programmer_id
        u.integer :project_id
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:programmers) do |u|
        u.string :name
      end
      
      ActiveRecord::Base.using(shard_symbol).connection.create_table(:projects) do |u|
        u.string :name
      end
    end
  end
  
  desc 'Prepare the test databases'
  task :prepare => [:drop_databases, :build_databases, :create_tables]
end



Something went wrong with that request. Please try again.