partitioned 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. data/Gemfile +17 -0
  2. data/LICENSE +30 -0
  3. data/PARTITIONING_EXPLAINED.txt +351 -0
  4. data/README +111 -0
  5. data/Rakefile +27 -0
  6. data/examples/README +23 -0
  7. data/examples/company_id.rb +417 -0
  8. data/examples/company_id_and_created_at.rb +689 -0
  9. data/examples/created_at.rb +590 -0
  10. data/examples/created_at_referencing_awards.rb +1000 -0
  11. data/examples/id.rb +475 -0
  12. data/examples/lib/by_company_id.rb +11 -0
  13. data/examples/lib/command_line_tool_mixin.rb +71 -0
  14. data/examples/lib/company.rb +29 -0
  15. data/examples/lib/get_options.rb +44 -0
  16. data/examples/lib/roman.rb +41 -0
  17. data/examples/start_date.rb +621 -0
  18. data/init.rb +1 -0
  19. data/lib/monkey_patch_activerecord.rb +92 -0
  20. data/lib/monkey_patch_postgres.rb +73 -0
  21. data/lib/partitioned.rb +26 -0
  22. data/lib/partitioned/active_record_overrides.rb +34 -0
  23. data/lib/partitioned/bulk_methods_mixin.rb +288 -0
  24. data/lib/partitioned/by_created_at.rb +13 -0
  25. data/lib/partitioned/by_foreign_key.rb +21 -0
  26. data/lib/partitioned/by_id.rb +35 -0
  27. data/lib/partitioned/by_integer_field.rb +32 -0
  28. data/lib/partitioned/by_monthly_time_field.rb +23 -0
  29. data/lib/partitioned/by_time_field.rb +65 -0
  30. data/lib/partitioned/by_weekly_time_field.rb +30 -0
  31. data/lib/partitioned/multi_level.rb +20 -0
  32. data/lib/partitioned/multi_level/configurator/data.rb +14 -0
  33. data/lib/partitioned/multi_level/configurator/dsl.rb +32 -0
  34. data/lib/partitioned/multi_level/configurator/reader.rb +162 -0
  35. data/lib/partitioned/multi_level/partition_manager.rb +47 -0
  36. data/lib/partitioned/partitioned_base.rb +354 -0
  37. data/lib/partitioned/partitioned_base/configurator.rb +6 -0
  38. data/lib/partitioned/partitioned_base/configurator/data.rb +62 -0
  39. data/lib/partitioned/partitioned_base/configurator/dsl.rb +628 -0
  40. data/lib/partitioned/partitioned_base/configurator/reader.rb +209 -0
  41. data/lib/partitioned/partitioned_base/partition_manager.rb +138 -0
  42. data/lib/partitioned/partitioned_base/sql_adapter.rb +286 -0
  43. data/lib/partitioned/version.rb +3 -0
  44. data/lib/tasks/desirable_tasks.rake +4 -0
  45. data/partitioned.gemspec +21 -0
  46. data/spec/dummy/.rspec +1 -0
  47. data/spec/dummy/README.rdoc +261 -0
  48. data/spec/dummy/Rakefile +7 -0
  49. data/spec/dummy/app/assets/javascripts/application.js +9 -0
  50. data/spec/dummy/app/assets/stylesheets/application.css +7 -0
  51. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  52. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  53. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  54. data/spec/dummy/config.ru +4 -0
  55. data/spec/dummy/config/application.rb +51 -0
  56. data/spec/dummy/config/boot.rb +10 -0
  57. data/spec/dummy/config/database.yml +32 -0
  58. data/spec/dummy/config/environment.rb +5 -0
  59. data/spec/dummy/config/environments/development.rb +30 -0
  60. data/spec/dummy/config/environments/production.rb +60 -0
  61. data/spec/dummy/config/environments/test.rb +39 -0
  62. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  63. data/spec/dummy/config/initializers/inflections.rb +10 -0
  64. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  65. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  66. data/spec/dummy/config/initializers/session_store.rb +8 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/en.yml +5 -0
  69. data/spec/dummy/config/routes.rb +58 -0
  70. data/spec/dummy/public/404.html +26 -0
  71. data/spec/dummy/public/422.html +26 -0
  72. data/spec/dummy/public/500.html +26 -0
  73. data/spec/dummy/public/favicon.ico +0 -0
  74. data/spec/dummy/script/rails +6 -0
  75. data/spec/dummy/spec/spec_helper.rb +27 -0
  76. data/spec/monkey_patch_posgres_spec.rb +176 -0
  77. data/spec/partitioned/bulk_methods_mixin_spec.rb +512 -0
  78. data/spec/partitioned/by_created_at_spec.rb +62 -0
  79. data/spec/partitioned/by_foreign_key_spec.rb +95 -0
  80. data/spec/partitioned/by_id_spec.rb +97 -0
  81. data/spec/partitioned/by_integer_field_spec.rb +143 -0
  82. data/spec/partitioned/by_monthly_time_field_spec.rb +100 -0
  83. data/spec/partitioned/by_time_field_spec.rb +182 -0
  84. data/spec/partitioned/by_weekly_time_field_spec.rb +100 -0
  85. data/spec/partitioned/multi_level/configurator/dsl_spec.rb +88 -0
  86. data/spec/partitioned/multi_level/configurator/reader_spec.rb +147 -0
  87. data/spec/partitioned/partitioned_base/configurator/dsl_spec.rb +459 -0
  88. data/spec/partitioned/partitioned_base/configurator/reader_spec.rb +513 -0
  89. data/spec/partitioned/partitioned_base/sql_adapter_spec.rb +204 -0
  90. data/spec/partitioned/partitioned_base_spec.rb +173 -0
  91. data/spec/spec_helper.rb +32 -0
  92. data/spec/support/shared_example_spec_helper_for_integer_key.rb +137 -0
  93. data/spec/support/shared_example_spec_helper_for_time_key.rb +147 -0
  94. data/spec/support/tables_spec_helper.rb +47 -0
  95. metadata +250 -0
@@ -0,0 +1,147 @@
1
+ DATE_NOW = Date.today
2
+
3
+ shared_examples_for "check that basic operations with postgres works correctly for time key" do |class_name|
4
+
5
+ let!(:subject) do
6
+ class_name.reset_column_information
7
+ class_name
8
+ end
9
+
10
+ context "when try to create one record" do
11
+
12
+ it "record created" do
13
+ lambda { subject.create(:name => 'Phil', :company_id => 3, :created_at => DATE_NOW + 1)
14
+ }.should_not raise_error
15
+ end
16
+
17
+ end # when try to create one record
18
+
19
+ context "when try to create one record using new/save" do
20
+
21
+ it "record created" do
22
+ lambda {
23
+ instance = subject.new(:name => 'Mike', :company_id => 1, :created_at => DATE_NOW + 1)
24
+ instance.save!
25
+ }.should_not raise_error
26
+ end
27
+
28
+ end # when try to create one record using new/save
29
+
30
+ context "when try to create many records" do
31
+
32
+ it "records created" do
33
+ lambda { subject.create_many([
34
+ { :name => 'Alex', :company_id => 2, :created_at => DATE_NOW + 1 },
35
+ { :name => 'Aaron', :company_id => 3, :created_at => DATE_NOW + 1 }])
36
+ }.should_not raise_error
37
+ end
38
+
39
+ end # when try to create many records
40
+
41
+ context "when try to find a record with the search term is id" do
42
+
43
+ it "returns employee name" do
44
+ subject.find(1).name.should == "Keith"
45
+ end
46
+
47
+ end # when try to find a record with the search term is id
48
+
49
+ context "when try to find a record with the search term is name" do
50
+
51
+ it "returns employee name" do
52
+ subject.where(:name => 'Keith').first.name.should == "Keith"
53
+ end
54
+
55
+ end # when try to find a record with the search term is name
56
+
57
+ context "when try to find a record with the search term is company_id" do
58
+
59
+ it "returns employee name" do
60
+ subject.where(:company_id => 1).first.name.should == "Keith"
61
+ end
62
+
63
+ end # when try to find a record with the search term is company_id
64
+
65
+ context "when try to find a record which is showing partition table" do
66
+
67
+ it "returns employee name" do
68
+ subject.from_partition(DATE_NOW).find(1).name.should == "Keith"
69
+ end
70
+
71
+ end # when try to find a record which is showing partition table
72
+
73
+ context "when try to update a record with id = 1" do
74
+
75
+ it "returns updated employee name" do
76
+ subject.update(1, :name => 'Kevin')
77
+ subject.find(1).name.should == "Kevin"
78
+ end
79
+
80
+ end # when try to update a record with id = 1
81
+
82
+ context "when try to update a record with update_many functions" do
83
+
84
+ it "returns updated employee name" do
85
+ subject.update_many( {
86
+ { :id => 1 } => {
87
+ :name => 'Alex',
88
+ :company_id => 3,
89
+ :created_at => DATE_NOW
90
+ }
91
+ } )
92
+ subject.find(1).name.should == "Alex"
93
+ end
94
+
95
+ it "returns updated employee name" do
96
+ rows = [{
97
+ :id => 1,
98
+ :name => 'Pit',
99
+ :created_at => DATE_NOW
100
+ }]
101
+
102
+ options = {
103
+ :set_array => '"name = datatable.name"',
104
+ :where => '"#{table_name}.id = datatable.id"'
105
+ }
106
+ subject.update_many(rows, options)
107
+ subject.find(1).name.should == "Pit"
108
+ end
109
+
110
+ end # when try to update a record with update_many functions
111
+
112
+ context "when try to delete a record with id = 1" do
113
+
114
+ it "returns empty array" do
115
+ subject.delete(1)
116
+ subject.find(:all).should == []
117
+ end
118
+
119
+ end # when try to delete a record with id = 1
120
+
121
+ context "when try to create new record outside the range of partitions" do
122
+
123
+ it "raises ActiveRecord::StatementInvalid" do
124
+ lambda { subject.create_many([{ :created_at => DATE_NOW + 1.year, :company_id => 1 }])
125
+ }.should raise_error(ActiveRecord::StatementInvalid)
126
+ end
127
+
128
+ end # when try to create new record outside the range of partitions
129
+
130
+ context "when try to update a record outside the range of partitions" do
131
+
132
+ it "raises ActiveRecord::StatementInvalid" do
133
+ lambda { subject.update(1, :name => 'Kevin', :created_at => DATE_NOW + 1.year)
134
+ }.should raise_error(ActiveRecord::StatementInvalid)
135
+ end
136
+
137
+ end # when try to update a record outside the range of partitions
138
+
139
+ context "when try to find a record outside the range of partitions" do
140
+
141
+ it "raises ActiveRecord::StatementInvalid" do
142
+ lambda { subject.from_partition(DATE_NOW + 1.year).find(1)
143
+ }.should raise_error(ActiveRecord::StatementInvalid)
144
+ end
145
+
146
+ end # when try to find a record outside the range of partitions
147
+ end # check that basic operations with postgres works correctly for time key
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ module TablesSpecHelper
4
+
5
+ class Company < ActiveRecord::Base
6
+ extend Partitioned::BulkMethodsMixin
7
+ has_many :employees, :class_name => 'Company', :conditions => "companies.id = employees.companies_id"
8
+ end
9
+
10
+ def create_tables
11
+ ActiveRecord::Base.connection.execute <<-SQL
12
+ create table companies
13
+ (
14
+ id serial not null primary key,
15
+ created_at timestamp not null default now(),
16
+ updated_at timestamp,
17
+ name text null
18
+ );
19
+
20
+ insert into companies (name) values ('Fluent Mobile, inc.');
21
+ insert into companies (name) values ('Fiksu, inc.');
22
+ insert into companies (name) values ('FreeMyApps, inc.');
23
+
24
+ create table employees
25
+ (
26
+ id serial not null primary key,
27
+ created_at timestamp not null default now(),
28
+ updated_at timestamp,
29
+ name text not null,
30
+ salary integer default 3,
31
+ company_id integer not null,
32
+ integer_field integer not null default 1
33
+ );
34
+
35
+ create schema employees_partitions;
36
+ SQL
37
+ end
38
+
39
+ def drop_tables
40
+ ActiveRecord::Base.connection.execute <<-SQL
41
+ drop schema employees_partitions cascade;
42
+ drop table employees;
43
+ drop table companies;
44
+ SQL
45
+ end
46
+
47
+ end
metadata ADDED
@@ -0,0 +1,250 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: partitioned
3
+ version: !ruby/object:Gem::Version
4
+ hash: 63
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 8
9
+ - 0
10
+ version: 0.8.0
11
+ platform: ruby
12
+ authors:
13
+ - Keith Gabryelski
14
+ - Aleksandr Dembskiy
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-03-07 00:00:00 Z
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: pg
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: rails
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 7
44
+ segments:
45
+ - 3
46
+ - 0
47
+ - 0
48
+ version: 3.0.0
49
+ type: :runtime
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: rspec-rails
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 3
60
+ segments:
61
+ - 0
62
+ version: "0"
63
+ type: :runtime
64
+ version_requirements: *id003
65
+ description: A gem providing support for table partitioning in ActiveRecord. Support is currently only supported for postgres database. Other features include child table management (creation and deletion) abd bulk data creating and updating
66
+ email: keith@fiksu.com
67
+ executables: []
68
+
69
+ extensions: []
70
+
71
+ extra_rdoc_files: []
72
+
73
+ files:
74
+ - Gemfile
75
+ - LICENSE
76
+ - PARTITIONING_EXPLAINED.txt
77
+ - README
78
+ - Rakefile
79
+ - examples/README
80
+ - examples/company_id.rb
81
+ - examples/company_id_and_created_at.rb
82
+ - examples/created_at.rb
83
+ - examples/created_at_referencing_awards.rb
84
+ - examples/id.rb
85
+ - examples/lib/by_company_id.rb
86
+ - examples/lib/command_line_tool_mixin.rb
87
+ - examples/lib/company.rb
88
+ - examples/lib/get_options.rb
89
+ - examples/lib/roman.rb
90
+ - examples/start_date.rb
91
+ - init.rb
92
+ - lib/monkey_patch_activerecord.rb
93
+ - lib/monkey_patch_postgres.rb
94
+ - lib/partitioned.rb
95
+ - lib/partitioned/active_record_overrides.rb
96
+ - lib/partitioned/bulk_methods_mixin.rb
97
+ - lib/partitioned/by_created_at.rb
98
+ - lib/partitioned/by_foreign_key.rb
99
+ - lib/partitioned/by_id.rb
100
+ - lib/partitioned/by_integer_field.rb
101
+ - lib/partitioned/by_monthly_time_field.rb
102
+ - lib/partitioned/by_time_field.rb
103
+ - lib/partitioned/by_weekly_time_field.rb
104
+ - lib/partitioned/multi_level.rb
105
+ - lib/partitioned/multi_level/configurator/data.rb
106
+ - lib/partitioned/multi_level/configurator/dsl.rb
107
+ - lib/partitioned/multi_level/configurator/reader.rb
108
+ - lib/partitioned/multi_level/partition_manager.rb
109
+ - lib/partitioned/partitioned_base.rb
110
+ - lib/partitioned/partitioned_base/configurator.rb
111
+ - lib/partitioned/partitioned_base/configurator/data.rb
112
+ - lib/partitioned/partitioned_base/configurator/dsl.rb
113
+ - lib/partitioned/partitioned_base/configurator/reader.rb
114
+ - lib/partitioned/partitioned_base/partition_manager.rb
115
+ - lib/partitioned/partitioned_base/sql_adapter.rb
116
+ - lib/partitioned/version.rb
117
+ - lib/tasks/desirable_tasks.rake
118
+ - partitioned.gemspec
119
+ - spec/dummy/.rspec
120
+ - spec/dummy/README.rdoc
121
+ - spec/dummy/Rakefile
122
+ - spec/dummy/app/assets/javascripts/application.js
123
+ - spec/dummy/app/assets/stylesheets/application.css
124
+ - spec/dummy/app/controllers/application_controller.rb
125
+ - spec/dummy/app/helpers/application_helper.rb
126
+ - spec/dummy/app/views/layouts/application.html.erb
127
+ - spec/dummy/config.ru
128
+ - spec/dummy/config/application.rb
129
+ - spec/dummy/config/boot.rb
130
+ - spec/dummy/config/database.yml
131
+ - spec/dummy/config/environment.rb
132
+ - spec/dummy/config/environments/development.rb
133
+ - spec/dummy/config/environments/production.rb
134
+ - spec/dummy/config/environments/test.rb
135
+ - spec/dummy/config/initializers/backtrace_silencers.rb
136
+ - spec/dummy/config/initializers/inflections.rb
137
+ - spec/dummy/config/initializers/mime_types.rb
138
+ - spec/dummy/config/initializers/secret_token.rb
139
+ - spec/dummy/config/initializers/session_store.rb
140
+ - spec/dummy/config/initializers/wrap_parameters.rb
141
+ - spec/dummy/config/locales/en.yml
142
+ - spec/dummy/config/routes.rb
143
+ - spec/dummy/public/404.html
144
+ - spec/dummy/public/422.html
145
+ - spec/dummy/public/500.html
146
+ - spec/dummy/public/favicon.ico
147
+ - spec/dummy/script/rails
148
+ - spec/dummy/spec/spec_helper.rb
149
+ - spec/monkey_patch_posgres_spec.rb
150
+ - spec/partitioned/bulk_methods_mixin_spec.rb
151
+ - spec/partitioned/by_created_at_spec.rb
152
+ - spec/partitioned/by_foreign_key_spec.rb
153
+ - spec/partitioned/by_id_spec.rb
154
+ - spec/partitioned/by_integer_field_spec.rb
155
+ - spec/partitioned/by_monthly_time_field_spec.rb
156
+ - spec/partitioned/by_time_field_spec.rb
157
+ - spec/partitioned/by_weekly_time_field_spec.rb
158
+ - spec/partitioned/multi_level/configurator/dsl_spec.rb
159
+ - spec/partitioned/multi_level/configurator/reader_spec.rb
160
+ - spec/partitioned/partitioned_base/configurator/dsl_spec.rb
161
+ - spec/partitioned/partitioned_base/configurator/reader_spec.rb
162
+ - spec/partitioned/partitioned_base/sql_adapter_spec.rb
163
+ - spec/partitioned/partitioned_base_spec.rb
164
+ - spec/spec_helper.rb
165
+ - spec/support/shared_example_spec_helper_for_integer_key.rb
166
+ - spec/support/shared_example_spec_helper_for_time_key.rb
167
+ - spec/support/tables_spec_helper.rb
168
+ homepage: http://www.fiksu.com
169
+ licenses: []
170
+
171
+ post_install_message:
172
+ rdoc_options: []
173
+
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ">="
180
+ - !ruby/object:Gem::Version
181
+ hash: 3
182
+ segments:
183
+ - 0
184
+ version: "0"
185
+ required_rubygems_version: !ruby/object:Gem::Requirement
186
+ none: false
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ hash: 3
191
+ segments:
192
+ - 0
193
+ version: "0"
194
+ requirements: []
195
+
196
+ rubyforge_project:
197
+ rubygems_version: 1.8.21
198
+ signing_key:
199
+ specification_version: 3
200
+ summary: Postgres table partitioning support for ActiveRecord.
201
+ test_files:
202
+ - spec/dummy/.rspec
203
+ - spec/dummy/README.rdoc
204
+ - spec/dummy/Rakefile
205
+ - spec/dummy/app/assets/javascripts/application.js
206
+ - spec/dummy/app/assets/stylesheets/application.css
207
+ - spec/dummy/app/controllers/application_controller.rb
208
+ - spec/dummy/app/helpers/application_helper.rb
209
+ - spec/dummy/app/views/layouts/application.html.erb
210
+ - spec/dummy/config.ru
211
+ - spec/dummy/config/application.rb
212
+ - spec/dummy/config/boot.rb
213
+ - spec/dummy/config/database.yml
214
+ - spec/dummy/config/environment.rb
215
+ - spec/dummy/config/environments/development.rb
216
+ - spec/dummy/config/environments/production.rb
217
+ - spec/dummy/config/environments/test.rb
218
+ - spec/dummy/config/initializers/backtrace_silencers.rb
219
+ - spec/dummy/config/initializers/inflections.rb
220
+ - spec/dummy/config/initializers/mime_types.rb
221
+ - spec/dummy/config/initializers/secret_token.rb
222
+ - spec/dummy/config/initializers/session_store.rb
223
+ - spec/dummy/config/initializers/wrap_parameters.rb
224
+ - spec/dummy/config/locales/en.yml
225
+ - spec/dummy/config/routes.rb
226
+ - spec/dummy/public/404.html
227
+ - spec/dummy/public/422.html
228
+ - spec/dummy/public/500.html
229
+ - spec/dummy/public/favicon.ico
230
+ - spec/dummy/script/rails
231
+ - spec/dummy/spec/spec_helper.rb
232
+ - spec/monkey_patch_posgres_spec.rb
233
+ - spec/partitioned/bulk_methods_mixin_spec.rb
234
+ - spec/partitioned/by_created_at_spec.rb
235
+ - spec/partitioned/by_foreign_key_spec.rb
236
+ - spec/partitioned/by_id_spec.rb
237
+ - spec/partitioned/by_integer_field_spec.rb
238
+ - spec/partitioned/by_monthly_time_field_spec.rb
239
+ - spec/partitioned/by_time_field_spec.rb
240
+ - spec/partitioned/by_weekly_time_field_spec.rb
241
+ - spec/partitioned/multi_level/configurator/dsl_spec.rb
242
+ - spec/partitioned/multi_level/configurator/reader_spec.rb
243
+ - spec/partitioned/partitioned_base/configurator/dsl_spec.rb
244
+ - spec/partitioned/partitioned_base/configurator/reader_spec.rb
245
+ - spec/partitioned/partitioned_base/sql_adapter_spec.rb
246
+ - spec/partitioned/partitioned_base_spec.rb
247
+ - spec/spec_helper.rb
248
+ - spec/support/shared_example_spec_helper_for_integer_key.rb
249
+ - spec/support/shared_example_spec_helper_for_time_key.rb
250
+ - spec/support/tables_spec_helper.rb