ar-octopus 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. data/.gitignore +11 -0
  2. data/.travis.yml +22 -0
  3. data/Appraisals +18 -0
  4. data/Gemfile +3 -12
  5. data/README.mkdn +63 -24
  6. data/Rakefile +70 -92
  7. data/ar-octopus.gemspec +25 -198
  8. data/lib/ar-octopus.rb +1 -0
  9. data/lib/octopus.rb +73 -25
  10. data/lib/octopus/association.rb +6 -5
  11. data/lib/octopus/association_collection.rb +58 -4
  12. data/lib/octopus/has_and_belongs_to_many_association.rb +4 -4
  13. data/lib/octopus/logger.rb +9 -4
  14. data/lib/octopus/migration.rb +155 -50
  15. data/lib/octopus/model.rb +98 -34
  16. data/lib/octopus/proxy.rb +124 -53
  17. data/lib/octopus/rails2/association.rb +46 -93
  18. data/lib/octopus/rails2/persistence.rb +1 -1
  19. data/lib/octopus/rails2/scope.rb +17 -0
  20. data/lib/octopus/rails3.1/singular_association.rb +34 -0
  21. data/lib/octopus/rails3.2/persistence.rb +12 -0
  22. data/lib/octopus/rails3/abstract_adapter.rb +39 -0
  23. data/lib/octopus/rails3/arel.rb +5 -5
  24. data/lib/octopus/rails3/log_subscriber.rb +22 -0
  25. data/lib/octopus/rails3/persistence.rb +10 -5
  26. data/lib/octopus/railtie.rb +13 -0
  27. data/lib/octopus/scope_proxy.rb +22 -16
  28. data/lib/octopus/version.rb +3 -0
  29. data/lib/tasks/octopus.rake +20 -0
  30. data/sample_app/Gemfile +2 -2
  31. data/sample_app/config/initializers/inflections.rb +1 -1
  32. data/sample_app/config/initializers/secret_token.rb +1 -1
  33. data/sample_app/db/migrate/20100720172730_create_items.rb +1 -1
  34. data/sample_app/db/migrate/20100720210335_create_sample_users.rb +1 -1
  35. data/sample_app/db/seeds.rb +1 -1
  36. data/sample_app/features/migrate.feature +12 -12
  37. data/sample_app/features/seed.feature +3 -3
  38. data/sample_app/features/step_definitions/web_steps.rb +5 -5
  39. data/sample_app/features/support/env.rb +8 -8
  40. data/sample_app/lib/tasks/cucumber.rake +2 -2
  41. data/sample_app/public/javascripts/effects.js +1 -1
  42. data/spec/config/shards.yml +38 -28
  43. data/spec/migrations/11_add_field_in_all_slaves.rb +1 -1
  44. data/spec/migrations/12_create_users_using_block.rb +2 -2
  45. data/spec/migrations/13_create_users_using_block_and_using.rb +2 -2
  46. data/spec/migrations/14_create_users_on_shards_of_a_group_with_versions.rb +11 -0
  47. data/spec/migrations/1_create_users_on_master.rb +1 -1
  48. data/spec/migrations/2_create_users_on_canada.rb +1 -1
  49. data/spec/migrations/3_create_users_on_both_shards.rb +1 -1
  50. data/spec/migrations/4_create_users_on_shards_of_a_group.rb +1 -1
  51. data/spec/migrations/5_create_users_on_multiples_groups.rb +1 -1
  52. data/spec/migrations/6_raise_exception_with_invalid_shard_name.rb +1 -1
  53. data/spec/migrations/7_raise_exception_with_invalid_multiple_shard_names.rb +1 -1
  54. data/spec/migrations/8_raise_exception_with_invalid_group_name.rb +1 -1
  55. data/spec/migrations/9_raise_exception_with_multiple_invalid_group_names.rb +1 -1
  56. data/spec/octopus/association_spec.rb +88 -70
  57. data/spec/octopus/log_subscriber_spec.rb +22 -0
  58. data/spec/octopus/logger_spec.rb +28 -15
  59. data/spec/octopus/migration_spec.rb +47 -43
  60. data/spec/octopus/model_spec.rb +179 -13
  61. data/spec/octopus/octopus_spec.rb +26 -4
  62. data/spec/octopus/proxy_spec.rb +61 -23
  63. data/spec/octopus/{replication_specs.rb → replication_spec.rb} +33 -26
  64. data/spec/octopus/scope_proxy_spec.rb +3 -3
  65. data/spec/octopus/sharded_spec.rb +9 -9
  66. data/spec/spec_helper.rb +10 -12
  67. data/spec/support/active_record/connection_adapters/modify_config_adapter.rb +17 -0
  68. data/spec/support/database_connection.rb +2 -0
  69. data/spec/{database_models.rb → support/database_models.rb} +27 -2
  70. data/spec/support/octopus_helper.rb +50 -0
  71. data/spec/tasks/octopus.rake_spec.rb +36 -0
  72. metadata +188 -169
  73. data/Gemfile.lock +0 -68
  74. data/lib/octopus/rails3/association.rb +0 -112
  75. data/spec/database_connection.rb +0 -4
  76. data/spec/octopus/controller_spec.rb +0 -34
  77. data/spec/octopus_helper.rb +0 -37
@@ -0,0 +1,11 @@
1
+ *.gem
2
+ *.sqlite3
3
+ .bundle
4
+ .rvmrc
5
+ Gemfile.lock
6
+ gemfiles/*
7
+ pkg/*
8
+ *.rbc
9
+ tmp/*
10
+ .*.sw[a-z]
11
+ database.log
@@ -0,0 +1,22 @@
1
+ language: ruby
2
+ env:
3
+ - CI=true
4
+ before_script:
5
+ - "bundle install"
6
+ - "bundle exec rake db:prepare"
7
+ bundler_args: --without development
8
+
9
+ rvm:
10
+ - 1.8.7
11
+ - 1.9.3
12
+
13
+ gemfile:
14
+ - gemfiles/rails2.gemfile
15
+ - gemfiles/rails3.gemfile
16
+ - gemfiles/rails31.gemfile
17
+ - gemfiles/rails32.gemfile
18
+
19
+ notifications:
20
+ recipients:
21
+ - gabriel.sobrinho@gmail.com
22
+ - thiago.pradi@gmail.com
@@ -0,0 +1,18 @@
1
+ appraise "rails2" do
2
+ gem "activerecord", "~> 2.3"
3
+ gem "actionpack", "~> 2.3"
4
+ end
5
+
6
+ appraise "rails30" do
7
+ gem "activerecord", "~> 3.0.11"
8
+ end
9
+
10
+ appraise "rails31" do
11
+ gem "activerecord", "~> 3.1.3"
12
+ end
13
+
14
+ appraise "rails32" do
15
+ gem "activerecord", "~> 3.2.0"
16
+ end
17
+
18
+ # vim: ft=ruby
data/Gemfile CHANGED
@@ -1,13 +1,4 @@
1
- source :rubygems
1
+ source "http://rubygems.org"
2
2
 
3
- gem 'activerecord', '3.0.6'
4
- gem 'actionpack', '3.0.6'
5
-
6
- group :test do
7
- gem "rake", ">= 0.8.7"
8
- gem "jeweler", ">= 1.4"
9
- gem "rspec"
10
- gem "mysql2"
11
- gem "pg", ">= 0.9.0"
12
- gem "sqlite3-ruby", ">= 1.3.1"
13
- end
3
+ # Specify your gem's dependencies in ar-octopus.gemspec
4
+ gemspec
@@ -1,5 +1,7 @@
1
1
  # Octopus - Easy Database Sharding for ActiveRecord
2
2
 
3
+ [![Build Status](https://travis-ci.org/tchandy/octopus.png)](https://travis-ci.org/tchandy/octopus) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/tchandy/octopus)
4
+
3
5
  Octopus is a better way to do Database Sharding in ActiveRecord. Sharding allows multiple databases in the same rails application. While there are several projects that implement Sharding (e.g. DbCharmer, DataFabric, MultiDb), each project has its own limitations. The main goal of octopus project is to provide a better way of doing Database Sharding.
4
6
 
5
7
  ## Feature list:
@@ -16,14 +18,14 @@ Octopus supports:
16
18
  When using replication, all writes queries will be sent to master, and read queries to slaves. More info could be found at: <a href="http://wiki.github.com/tchandy/octopus/replication"> Wiki</a>
17
19
 
18
20
  ### Sharding
19
- When using sharding, you need to specify which shard to send the query. Octopus supports selecting the shard inside a controller, or manually in each object. More could be found at <a href="http://wiki.github.com/tchandy/octopus/sharding"> Wiki</a>
21
+ When using sharding, you need to specify which shard to send the query. Octopus supports selecting the shard inside a controller, or manually in each object. More could be found at <a href="http://wiki.github.com/tchandy/octopus/sharding"> Wiki</a>
20
22
 
21
23
  ### Replication + Sharding
22
24
  Replication + Sharding isn't supported yet. This is on our TODO list and will be done ASAP. If you need, feel free to fork and implement it.
23
25
 
24
- ## Install
26
+ ## Install
25
27
 
26
- ### Rails 2.x
28
+ ### Rails 2.x
27
29
 
28
30
  Install the octopus gem:
29
31
 
@@ -33,29 +35,51 @@ Add this line to enviroment.rb:
33
35
 
34
36
  config.gem 'ar-octopus', :lib => "octopus"
35
37
 
36
- ### Rails 3.x
38
+ ### Rails 3.x
37
39
 
38
40
  Add this line to Gemfile:
39
41
 
40
- gem 'ar-octopus', :require => "octopus"
42
+ gem 'ar-octopus', :require => 'octopus'
43
+
44
+ **Note**: The `ar-octopus` gem build is out of date. Until a new build is created, we recommend using the gem from this repo by placing `gem "ar-octopus", github: "tchandy/octopus", require: "octopus"` in your Gemfile instead of the above line. Alternatively you can [create your own fork](https://github.com/tchandy/octopus/fork_select) (for added stability against changes to master) and reference that fork from your Gemfile: `gem "ar-octopus", github: "<fork owner>/octopus", require: "octopus"`.
41
45
 
42
- Runs a bundle install:
46
+ Run a bundle install:
43
47
 
44
48
  bundle install
45
49
 
46
- ## How to use Octopus?
50
+ ## Upgrading
51
+
52
+ ### From < 0.5.0
53
+
54
+ Octopus < 0.5.0 stored schema version information in the master database defined in the database.yml file, and assumed
55
+ that each shard's schema matched the others and the master database. Beginning with Octopus 0.5.0, the schema version
56
+ information for each shard is stored within that shard's database.
57
+
58
+ If you are upgrading from < 0.5.0 run the `copy_schema_versions` rake task to copy the schema version information in the
59
+ master database to each of the shards:
60
+
61
+ rake octopus:copy_schema_versions
62
+
63
+ Once the task completes migrations will operate normally and schema information will be stored in each shard database
64
+ going forward.
65
+
66
+ In order to run this task in Rails 2.3, you'll need to tell Rails to load Octopus' rake tasks by adding this to your `Rakefile`:
67
+
68
+ Dir["#{Gem.searcher.find('ar-octopus').full_gem_path}/lib/tasks/**/*.rake"].each { |ext| load ext }
69
+
70
+ ## How to use Octopus?
47
71
 
48
72
  First, you need to create a config file, shards.yml, inside your config/ directory. to see the syntax and how this file should look, please checkout <a href="http://wiki.github.com/tchandy/octopus/config-file">this page on wiki</a>.
49
73
 
50
- ### Syntax
74
+ ### Syntax
51
75
 
52
- Octopus adds a method to each AR Class and object: the using method is used to select the shard like this:
76
+ Octopus adds a method to each AR Class and object: the using method is used to select the shard like this:
53
77
 
54
78
  User.where(:name => "Thiago").limit(3).using(:slave_one)
55
79
 
56
- Octopus also supports queries within a block. When you pass a block to the using method, all queries inside the block will be sent to the specified shard.
80
+ Octopus also supports queries within a block. When you pass a block to the using method, all queries inside the block will be sent to the specified shard.
57
81
 
58
- Octopus.using(:slave_two) do
82
+ Octopus.using(:slave_two) do
59
83
  User.create(:name => "Mike")
60
84
  end
61
85
 
@@ -70,7 +94,7 @@ Each model instance knows which shard it came from so this will work automatical
70
94
  #Sets the name
71
95
  @user.name = "Mike"
72
96
 
73
- # Save the user in the correct shard, shard1.
97
+ # Save the user in the correct shard, shard1.
74
98
  @user.save
75
99
 
76
100
  ### Migrations
@@ -89,7 +113,7 @@ In migrations, you also have access to the using method. The syntax is basically
89
113
  end
90
114
  end
91
115
 
92
- You also could send a migration to a group of shards. This migration will be sent to all shards that belongs to history_shards group, specified in shards.yml:
116
+ You also could send a migration to a group of shards. This migration will be sent to all shards that belongs to history_shards group, specified in shards.yml:
93
117
 
94
118
  class CreateUsersOnMultiplesGroups < ActiveRecord::Migration
95
119
  using_group(:history_shards)
@@ -106,13 +130,13 @@ You also could send a migration to a group of shards. This migration will be se
106
130
  ### Rails Controllers
107
131
 
108
132
  If you want to send a specified action, or all actions from a controller, to a specific shard, use this syntax:
109
-
133
+
110
134
  class ApplicationController < ActionController::Base
111
- around_filter :select_shard
112
-
135
+ around_filter :select_shard
136
+
113
137
  def select_shard(&block)
114
138
  Octopus.using(:brazil, &block)
115
- end
139
+ end
116
140
  end
117
141
 
118
142
  To see the complete list of features and syntax, please check out our <a href="http://wiki.github.com/tchandy/octopus/"> Wiki</a>
@@ -120,23 +144,36 @@ Want to see sample rails applications using octopus features? please check it ou
120
144
 
121
145
 
122
146
  ## Important!
123
- Sometimes, when a connection isn't used for much time, this will makes ActiveRecord raising an exception. if you have this kind of applications, please, add the following line to your configuration:
147
+ Occasionally, an application might lose a connection to a database; when this happens, ActiveRecord will raise an exception. Add the following line to your application configuration if you are experiencing this issue:
124
148
 
125
149
  verify_connection: true
126
150
 
127
151
  This will tell Octopus to verify the connection before sending the query.
128
152
 
129
153
  ## Mixing Octopus with the Rails multiple database model
130
- If you want to set a custom connection to a specific model, use this syntax:
154
+ If you want to set a custom connection to a specific model, use the syntax `octopus_establish_connection` syntax:
131
155
 
132
156
  #This class sets its own connection
133
- # establish_connection will not work, use octopus_establish_connection instead.
134
157
  class CustomConnection < ActiveRecord::Base
135
158
  octopus_establish_connection(:adapter => "mysql", :database => "octopus_shard2")
136
159
  end
137
160
 
138
161
  ## Set table names
139
- If you want to use specific table names, please visit: <a href="https://github.com/tchandy/octopus/wiki/Table-names"> this link</a>
162
+ If you want to use specific table names, use the correct syntax for your version of Rails.
163
+
164
+ ### Rails <= 3.1
165
+
166
+ class Bacon < ActiveRecord::Base
167
+ set_table_name("yummy")
168
+ end
169
+
170
+ ### Rails >= 3.2
171
+
172
+ class Bacon < ActiveRecord::Base
173
+ self.table_name = "yummy"
174
+ end
175
+
176
+ Unfortunately the `self.table_name=` syntax isn't supported on versions of Rails <= 3.1.
140
177
 
141
178
  ## Contributing with Octopus
142
179
  Contributors are welcome! To run the test suite, you need mysql, postgresql and sqlite3 installed. This is what you need to setup your Octopus development environment:
@@ -144,9 +181,11 @@ Contributors are welcome! To run the test suite, you need mysql, postgresql and
144
181
  git clone http://github.com/tchandy/octopus.git
145
182
  cd octopus
146
183
  bundle install
147
- rake db:prepare
148
- rake
184
+ bundle exec rake db:prepare
185
+ bundle exec rake appraisal:install
186
+ bundle exec rake spec
149
187
 
188
+ This command will run the spec suite for all rails versions supported (Rails 2.3, Rails 3.0 and Rails 3.1).
150
189
  To run our integrations tests inside sample_app, you need to following commands:
151
190
 
152
191
  cd sample_app
@@ -168,4 +207,4 @@ and my mentors <a href="http://github.com/mperham">Mike Perham</a> and <a href="
168
207
 
169
208
  ## Copyright
170
209
 
171
- Copyright (c) 2010 Thiago Pradi, released under the MIT license.
210
+ Copyright (c) Thiago Pradi, released under the MIT license.
data/Rakefile CHANGED
@@ -1,168 +1,146 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
2
- $LOAD_PATH << (File.dirname(__FILE__) + '/spec')
3
- require 'rubygems'
4
- require 'rake'
5
- require 'rake/tasklib'
6
- require "yaml"
7
- require "bundler"
8
- Bundler.setup()
9
-
10
- begin
11
- require 'metric_fu'
12
- MetricFu::Configuration.run do |config|
13
- config.metrics = [:churn,:flay, :flog, :reek, :roodi, :saikuro]
14
- config.graphs = [:flog, :flay, :reek, :roodi]
15
- config.flay = { :dirs_to_flay => ['spec', 'lib'] }
16
- config.flog = { :dirs_to_flog => ['spec', 'lib'] }
17
- config.reek = { :dirs_to_reek => ['spec', 'lib'] }
18
- config.roodi = { :dirs_to_roodi => ['spec', 'lib'] }
19
- config.churn = { :start_date => "1 year ago", :minimum_churn_count => 10}
20
- end
21
- rescue LoadError
22
- end
23
-
24
- begin
25
- require 'jeweler'
26
- Jeweler::Tasks.new do |gem|
27
- gem.name = "ar-octopus"
28
- gem.summary = "Easy Database Sharding for ActiveRecord"
29
- 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."
30
- gem.email = "tchandy@gmail.com"
31
- gem.homepage = "http://github.com/tchandy/octopus"
32
- gem.authors = ["Thiago Pradi", "Mike Perham"]
33
- gem.add_development_dependency "rspec", ">= 2.0.0.beta.19"
34
- gem.add_development_dependency "mysql2"
35
- gem.add_development_dependency "pg", ">= 0.9.0"
36
- gem.add_development_dependency "sqlite3-ruby", ">= 1.3.1"
37
- gem.add_development_dependency "jeweler", ">= 1.4"
38
- gem.add_development_dependency "actionpack", ">= 2.3"
39
- gem.add_dependency('activerecord', '>= 2.3')
40
- gem.version = "0.4.0"
41
- end
42
- Jeweler::GemcutterTasks.new
43
- rescue LoadError
44
- puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
45
- end
46
-
47
- require 'rspec/core'
1
+ require 'bundler/gem_tasks'
48
2
  require 'rspec/core/rake_task'
49
-
50
- RSpec::Core::RakeTask.new(:spec) do |spec|
51
- end
52
-
53
- RSpec::Core::RakeTask.new(:rcov) do |spec|
54
- end
3
+ require 'appraisal'
55
4
 
56
5
  task :default => :spec
57
6
 
7
+ RSpec::Core::RakeTask.new(:spec) do |spec|
8
+ end
58
9
 
59
10
  namespace :db do
60
11
  desc 'Build the databases for tests'
61
12
  task :build_databases do
62
- mysql_user = ENV['MYSQL_USER'] || "root"
63
- postgres_user = ENV['POSTGRES_USER'] || "postgres"
64
- (1..5).each do |idx|
65
- %x( echo "create DATABASE octopus_shard#{idx} DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{mysql_user})
13
+ pg_spec = {
14
+ :adapter => 'postgresql',
15
+ :host => 'localhost',
16
+ :username => (ENV['POSTGRES_USER'] || "postgres"),
17
+ :encoding => 'utf8'
18
+ }
19
+
20
+ mysql_spec = {
21
+ :adapter => 'mysql',
22
+ :host => 'localhost',
23
+ :username => (ENV['MYSQL_USER'] || "root"),
24
+ :encoding => 'utf8'
25
+ }
26
+
27
+ %x( rm -f /tmp/database.sqlite3 )
28
+
29
+ require "active_record"
30
+
31
+ # Connects to PostgreSQL
32
+ ActiveRecord::Base.establish_connection(pg_spec.merge('database' => 'postgres', 'schema_search_path' => 'public'))
33
+ (1..2).map do |i|
34
+ # drop the old database (if it exists)
35
+ ActiveRecord::Base.connection.drop_database("octopus_shard_#{i}")
36
+ # create new database
37
+ ActiveRecord::Base.connection.create_database("octopus_shard_#{i}")
66
38
  end
67
39
 
68
- %x( createdb -E UTF8 -U #{postgres_user} octopus_shard1 )
69
- end
70
-
71
- desc 'Drop the tests databases'
72
- task :drop_databases do
73
- mysql_user = ENV['MYSQL_USER'] || "root"
74
- postgres_user = ENV['POSTGRES_USER'] || "postgres"
75
- (1..5).each do |idx|
76
- %x( mysqladmin --user=#{mysql_user} -f drop octopus_shard#{idx} )
40
+ # Connect to MYSQL
41
+ ActiveRecord::Base.establish_connection(mysql_spec)
42
+ (1..5).map do |i|
43
+ # drop the old database (if it exists)
44
+ ActiveRecord::Base.connection.drop_database("octopus_shard_#{i}")
45
+ # create new database
46
+ ActiveRecord::Base.connection.create_database("octopus_shard_#{i}")
77
47
  end
78
-
79
- %x( dropdb -U #{postgres_user} octopus_shard1 )
80
- %x(rm -f /tmp/database.sqlite3)
81
48
  end
82
49
 
83
50
  desc 'Create tables on tests databases'
84
51
  task :create_tables do
85
- Dir.chdir(File.expand_path(File.dirname(__FILE__) + "/spec"))
86
- require "database_connection"
87
52
  require "octopus"
88
- [:master, :brazil, :canada, :russia, :alone_shard, :postgresql_shard, :sqlite_shard].each do |shard_symbol|
89
- ActiveRecord::Base.using(shard_symbol).connection.initialize_schema_migrations_table()
53
+ # Set the octopus variable directory to spec dir, in order to load the config/shards.yml file.
54
+ Octopus.instance_variable_set(:@directory, "#{File.dirname(__FILE__)}/spec/" )
55
+
56
+ # Require the database connection
57
+ require "#{File.dirname(__FILE__)}/spec/support/database_connection"
58
+
59
+ [:master, :brazil, :canada, :russia, :alone_shard, :postgresql_shard, :sqlite_shard, :protocol_shard].each do |shard_symbol|
60
+ # Rails 3.1 needs to do some introspection around the base class, which requires
61
+ # the model be a descendent of ActiveRecord::Base.
62
+ class BlankModel < ActiveRecord::Base; end;
63
+
64
+ BlankModel.using(shard_symbol).connection.initialize_schema_migrations_table()
90
65
 
91
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:users) do |u|
66
+ BlankModel.using(shard_symbol).connection.create_table(:users) do |u|
92
67
  u.string :name
93
68
  u.integer :number
94
69
  u.boolean :admin
70
+ u.datetime :created_at
71
+ u.datetime :updated_at
95
72
  end
96
73
 
97
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:clients) do |u|
74
+ BlankModel.using(shard_symbol).connection.create_table(:clients) do |u|
98
75
  u.string :country
99
76
  u.string :name
100
77
  end
101
78
 
102
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:cats) do |u|
79
+ BlankModel.using(shard_symbol).connection.create_table(:cats) do |u|
103
80
  u.string :name
104
81
  end
105
82
 
106
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:items) do |u|
83
+ BlankModel.using(shard_symbol).connection.create_table(:items) do |u|
107
84
  u.string :name
108
85
  u.integer :client_id
109
86
  end
110
87
 
111
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:computers) do |u|
88
+ BlankModel.using(shard_symbol).connection.create_table(:computers) do |u|
112
89
  u.string :name
113
90
  end
114
91
 
115
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:keyboards) do |u|
92
+ BlankModel.using(shard_symbol).connection.create_table(:keyboards) do |u|
116
93
  u.string :name
117
94
  u.integer :computer_id
118
95
  end
119
96
 
120
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:roles) do |u|
97
+ BlankModel.using(shard_symbol).connection.create_table(:roles) do |u|
121
98
  u.string :name
122
99
  end
123
100
 
124
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:permissions) do |u|
101
+ BlankModel.using(shard_symbol).connection.create_table(:permissions) do |u|
125
102
  u.string :name
126
103
  end
127
104
 
128
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:permissions_roles, :id => false) do |u|
105
+ BlankModel.using(shard_symbol).connection.create_table(:permissions_roles, :id => false) do |u|
129
106
  u.integer :role_id
130
107
  u.integer :permission_id
131
108
  end
132
109
 
133
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:assignments) do |u|
110
+ BlankModel.using(shard_symbol).connection.create_table(:assignments) do |u|
134
111
  u.integer :programmer_id
135
112
  u.integer :project_id
136
113
  end
137
114
 
138
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:programmers) do |u|
115
+ BlankModel.using(shard_symbol).connection.create_table(:programmers) do |u|
139
116
  u.string :name
140
117
  end
141
118
 
142
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:projects) do |u|
119
+ BlankModel.using(shard_symbol).connection.create_table(:projects) do |u|
143
120
  u.string :name
144
121
  end
145
122
 
146
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:comments) do |u|
123
+ BlankModel.using(shard_symbol).connection.create_table(:comments) do |u|
147
124
  u.string :name
148
125
  u.string :commentable_type
149
126
  u.integer :commentable_id
150
127
  end
151
128
 
152
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:parts) do |u|
129
+ BlankModel.using(shard_symbol).connection.create_table(:parts) do |u|
153
130
  u.string :name
154
131
  u.integer :item_id
155
132
  end
156
133
 
157
- ActiveRecord::Base.using(shard_symbol).connection.create_table(:yummy) do |u|
134
+ BlankModel.using(shard_symbol).connection.create_table(:yummy) do |u|
135
+ u.string :name
136
+ end
137
+
138
+ BlankModel.using(shard_symbol).connection.create_table(:adverts) do |u|
158
139
  u.string :name
159
140
  end
160
141
  end
161
142
  end
162
143
 
163
144
  desc 'Prepare the test databases'
164
- task :prepare => [:drop_databases, :build_databases, :create_tables]
145
+ task :prepare => [:build_databases, :create_tables]
165
146
  end
166
-
167
-
168
-