pg_partitioning 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +97 -0
  4. data/Rakefile +23 -0
  5. data/config/locales/en.yml +28 -0
  6. data/lib/generators/partitioning_generator.rb +18 -0
  7. data/lib/pg_partitioning/input_master.rb +83 -0
  8. data/lib/pg_partitioning/partitioning_master.rb +78 -0
  9. data/lib/pg_partitioning/printer.rb +28 -0
  10. data/lib/pg_partitioning/strategies/base.rb +72 -0
  11. data/lib/pg_partitioning/strategies/date.rb +73 -0
  12. data/lib/pg_partitioning/strategies/equal.rb +43 -0
  13. data/lib/pg_partitioning/strategies/step.rb +57 -0
  14. data/lib/pg_partitioning/version.rb +3 -0
  15. data/lib/pg_partitioning.rb +4 -0
  16. data/lib/tasks/pg_partitioning_tasks.rake +4 -0
  17. data/spec/db_helpers.rb +36 -0
  18. data/spec/dummy/README.rdoc +28 -0
  19. data/spec/dummy/Rakefile +6 -0
  20. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  21. data/spec/dummy/app/assets/stylesheets/application.css +15 -0
  22. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  23. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  24. data/spec/dummy/app/models/bandit.rb +4 -0
  25. data/spec/dummy/app/models/crime.rb +3 -0
  26. data/spec/dummy/app/models/gang.rb +3 -0
  27. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  28. data/spec/dummy/bin/bundle +3 -0
  29. data/spec/dummy/bin/rails +4 -0
  30. data/spec/dummy/bin/rake +4 -0
  31. data/spec/dummy/bin/setup +29 -0
  32. data/spec/dummy/config/application.rb +32 -0
  33. data/spec/dummy/config/boot.rb +5 -0
  34. data/spec/dummy/config/database.yml +28 -0
  35. data/spec/dummy/config/environment.rb +5 -0
  36. data/spec/dummy/config/environments/development.rb +41 -0
  37. data/spec/dummy/config/environments/production.rb +79 -0
  38. data/spec/dummy/config/environments/test.rb +42 -0
  39. data/spec/dummy/config/initializers/assets.rb +11 -0
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  42. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  43. data/spec/dummy/config/initializers/inflections.rb +16 -0
  44. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  45. data/spec/dummy/config/initializers/session_store.rb +3 -0
  46. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/spec/dummy/config/locales/en.yml +23 -0
  48. data/spec/dummy/config/routes.rb +56 -0
  49. data/spec/dummy/config/secrets.yml +22 -0
  50. data/spec/dummy/config.ru +4 -0
  51. data/spec/dummy/db/migrate/20160306173540_create_gangs.rb +9 -0
  52. data/spec/dummy/db/migrate/20160306174017_create_bandits.rb +12 -0
  53. data/spec/dummy/db/migrate/20160306174042_create_crimes.rb +10 -0
  54. data/spec/dummy/db/schema.rb +47 -0
  55. data/spec/dummy/log/development.log +3421 -0
  56. data/spec/dummy/log/production.log +0 -0
  57. data/spec/dummy/log/test.log +154834 -0
  58. data/spec/dummy/public/404.html +67 -0
  59. data/spec/dummy/public/422.html +67 -0
  60. data/spec/dummy/public/500.html +66 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/factories/bandits.rb +23 -0
  63. data/spec/factories/crimes.rb +6 -0
  64. data/spec/factories/gangs.rb +5 -0
  65. data/spec/input_master_spec.rb +74 -0
  66. data/spec/models/bandit_spec.rb +13 -0
  67. data/spec/models/crime_spec.rb +10 -0
  68. data/spec/models/gang_spec.rb +10 -0
  69. data/spec/partitioning_master_spec.rb +156 -0
  70. data/spec/rails_helper.rb +67 -0
  71. data/spec/shared_examples.rb +28 -0
  72. data/spec/spec_helper.rb +92 -0
  73. metadata +213 -0
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/404.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The page you were looking for doesn't exist.</h1>
62
+ <p>You may have mistyped the address or the page may have moved.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,67 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/422.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>The change you wanted was rejected.</h1>
62
+ <p>Maybe you tried to change something you didn't have access to.</p>
63
+ </div>
64
+ <p>If you are the application owner check the logs for more information.</p>
65
+ </div>
66
+ </body>
67
+ </html>
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <style>
7
+ body {
8
+ background-color: #EFEFEF;
9
+ color: #2E2F30;
10
+ text-align: center;
11
+ font-family: arial, sans-serif;
12
+ margin: 0;
13
+ }
14
+
15
+ div.dialog {
16
+ width: 95%;
17
+ max-width: 33em;
18
+ margin: 4em auto 0;
19
+ }
20
+
21
+ div.dialog > div {
22
+ border: 1px solid #CCC;
23
+ border-right-color: #999;
24
+ border-left-color: #999;
25
+ border-bottom-color: #BBB;
26
+ border-top: #B00100 solid 4px;
27
+ border-top-left-radius: 9px;
28
+ border-top-right-radius: 9px;
29
+ background-color: white;
30
+ padding: 7px 12% 0;
31
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
32
+ }
33
+
34
+ h1 {
35
+ font-size: 100%;
36
+ color: #730E15;
37
+ line-height: 1.5em;
38
+ }
39
+
40
+ div.dialog > p {
41
+ margin: 0 0 1em;
42
+ padding: 1em;
43
+ background-color: #F7F7F7;
44
+ border: 1px solid #CCC;
45
+ border-right-color: #999;
46
+ border-left-color: #999;
47
+ border-bottom-color: #999;
48
+ border-bottom-left-radius: 4px;
49
+ border-bottom-right-radius: 4px;
50
+ border-top-color: #DADADA;
51
+ color: #666;
52
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
53
+ }
54
+ </style>
55
+ </head>
56
+
57
+ <body>
58
+ <!-- This file lives in public/500.html -->
59
+ <div class="dialog">
60
+ <div>
61
+ <h1>We're sorry, but something went wrong.</h1>
62
+ </div>
63
+ <p>If you are the application owner check the logs for more information.</p>
64
+ </div>
65
+ </body>
66
+ </html>
File without changes
@@ -0,0 +1,23 @@
1
+ FactoryGirl.define do
2
+ factory :bandit do
3
+ date_of_birth 40.years.ago
4
+ name Faker::Lorem.characters(10)
5
+ specialization Faker::Lorem.characters(5)
6
+ association :gang
7
+
8
+ trait :thief do
9
+ id 1
10
+ specialization 'thief'
11
+ date_of_birth Date.new(1998, 1, 1)
12
+ end
13
+
14
+ trait :killer do
15
+ id 200
16
+ specialization 'killer'
17
+ date_of_birth Date.new(2001, 5, 10)
18
+ end
19
+
20
+ factory :thief, traits: [:thief]
21
+ factory :killer, traits: [:killer]
22
+ end
23
+ end
@@ -0,0 +1,6 @@
1
+ FactoryGirl.define do
2
+ factory :crime do
3
+ title Faker::Lorem.characters(10)
4
+ association :bandit
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :gang do
3
+ title Faker::Lorem.characters(10)
4
+ end
5
+ end
@@ -0,0 +1,74 @@
1
+ require_relative '../lib/pg_partitioning/input_master'
2
+
3
+ describe "PgPartitioning::InputMaster" do
4
+ subject { PgPartitioning::InputMaster.new }
5
+
6
+ it { is_expected.to respond_to :ask_mode }
7
+ it { is_expected.to respond_to :ask_table_name }
8
+ it { is_expected.to respond_to :ask_column_name }
9
+ it { is_expected.to respond_to :ask_cond }
10
+ it { is_expected.to respond_to :intro }
11
+ it { is_expected.to respond_to :print_row }
12
+ it { is_expected.to respond_to :info }
13
+ it { is_expected.to respond_to :alert }
14
+ it { is_expected.to respond_to :message }
15
+ it { is_expected.to respond_to :text_color }
16
+
17
+ describe "ask" do
18
+ before do
19
+ subject.instance_variable_set(:@error_message, nil)
20
+ end
21
+
22
+ context "with invalid" do
23
+ it "mode type" do
24
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.mode").and_return(5)
25
+ subject.ask_mode
26
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.mode")
27
+ end
28
+
29
+ it "cond step" do
30
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.cond_step").and_return("bla")
31
+ subject.ask_cond('step')
32
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.step")
33
+ end
34
+
35
+ it "cond date" do
36
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.cond_date").and_return("bla")
37
+ subject.ask_cond('date')
38
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.pattern")
39
+ end
40
+ end
41
+
42
+ context "with empty" do
43
+ it "mode type" do
44
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.mode").and_return("")
45
+ subject.ask_mode
46
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t 'pg_partitioning.failure.mode')
47
+ end
48
+
49
+ it "table name" do
50
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.table_name").and_return("")
51
+ subject.ask_table_name
52
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.answer")
53
+ end
54
+
55
+ it "column name" do
56
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.column_name").and_return("")
57
+ subject.ask_column_name
58
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.answer")
59
+ end
60
+
61
+ it "cond step" do
62
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.cond_step").and_return("")
63
+ subject.ask_cond('step')
64
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.step")
65
+ end
66
+
67
+ it "cond date" do
68
+ allow(subject).to receive(:ask).with(I18n.t "pg_partitioning.quests.cond_date").and_return("")
69
+ subject.ask_cond('date')
70
+ expect(subject.instance_variable_get(:@error_message)).to eq(I18n.t "pg_partitioning.failure.pattern")
71
+ end
72
+ end
73
+ end
74
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Bandit, type: :model do
4
+ subject { build :bandit }
5
+
6
+ it { is_expected.to be_valid }
7
+ it { is_expected.to respond_to :name }
8
+ it { is_expected.to respond_to :specialization }
9
+ it { is_expected.to respond_to :date_of_birth }
10
+
11
+ it { expect(Bandit.reflect_on_association(:gang).macro).to eq :belongs_to }
12
+ it { expect(Bandit.reflect_on_association(:crimes).macro).to eq :has_many }
13
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Crime, type: :model do
4
+ subject { build :crime }
5
+
6
+ it { is_expected.to be_valid }
7
+ it { is_expected.to respond_to :title }
8
+
9
+ it { expect(Crime.reflect_on_association(:bandit).macro).to eq :belongs_to }
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails_helper'
2
+
3
+ RSpec.describe Gang, type: :model do
4
+ subject { build :gang }
5
+
6
+ it { is_expected.to be_valid }
7
+ it { is_expected.to respond_to :title }
8
+
9
+ it { expect(Gang.reflect_on_association(:bandits).macro).to eq :has_many }
10
+ end
@@ -0,0 +1,156 @@
1
+ require_relative '../lib/pg_partitioning/partitioning_master'
2
+
3
+ describe "PgPartitioning::PartitioningMaster" do
4
+ let(:table) { 'bandits' }
5
+ let(:column) { 'specialization' }
6
+ let(:mode) { 0 }
7
+
8
+ subject { PgPartitioning::PartitioningMaster.new(table, column, mode) }
9
+
10
+ it { is_expected.to respond_to :partitioning }
11
+ it { expect(subject.instance_variable_get(:@table_name)).to eq table }
12
+ it { expect(subject.instance_variable_get(:@column_name)).to eq column }
13
+
14
+ context "mode is equal" do
15
+ before do
16
+ @master = PgPartitioning::PartitioningMaster.new(table, column, 0)
17
+ @strategy = @master.instance_variable_get :@strategy
18
+ end
19
+
20
+ it { expect(@strategy.class).to be PgPartitioning::Strategies::Equal }
21
+
22
+ describe "partitioning!" do
23
+
24
+ it_behaves_like "happy_partitioning"
25
+
26
+ describe "generate right table name" do
27
+ before do
28
+ Bandit.delete_all
29
+ clear_triggers(table)
30
+ @master.partitioning
31
+ @thief = create :thief
32
+ @killer = create :killer
33
+ end
34
+
35
+ it{ expect(Bandit.all.size).to be 2 }
36
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_killer").first).to eq @killer }
37
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_thief").first).to eq @thief }
38
+ end
39
+
40
+ context "with nonexistent name" do
41
+ it "raise error no table" do
42
+ master = PgPartitioning::PartitioningMaster.new('nonexistent table', column, 0)
43
+ strategy = master.instance_variable_get :@strategy
44
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.no_table" )
45
+ end
46
+
47
+ it "raise error no column" do
48
+ master = PgPartitioning::PartitioningMaster.new(table, "nonexistent column", 0)
49
+ strategy = master.instance_variable_get :@strategy
50
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.no_table" )
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ context "mode is step" do
57
+ before do
58
+ @master = PgPartitioning::PartitioningMaster.new(table, 'id', 1, 100)
59
+ end
60
+
61
+ it { expect(@master.instance_variable_get(:@strategy).class).to be PgPartitioning::Strategies::Step }
62
+
63
+ describe "partitioning!" do
64
+
65
+ it_behaves_like "happy_partitioning"
66
+
67
+ describe "generate right table name" do
68
+ before do
69
+ Bandit.delete_all
70
+ clear_triggers(table)
71
+ @master.partitioning
72
+ @thief = create :thief
73
+ @killer = create :killer
74
+ end
75
+
76
+ it{ expect(Bandit.all.size).to be 2 }
77
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_2").first).to eq @killer }
78
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_0").first).to eq @thief }
79
+ end
80
+
81
+ context "with invalid data" do
82
+ it "raise error type is not integer" do
83
+ master = PgPartitioning::PartitioningMaster.new(table, 'created_at', 1, 100)
84
+ strategy = master.instance_variable_get :@strategy
85
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.column_type" )
86
+ end
87
+
88
+ it "raise error condition is blank" do
89
+ master = PgPartitioning::PartitioningMaster.new(table, :id, 1)
90
+ strategy = master.instance_variable_get :@strategy
91
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.blank_cond" )
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+ context "mode is date" do
98
+ before do
99
+ @master = PgPartitioning::PartitioningMaster.new(table, 'date_of_birth', 2, 'YYYMMHH24')
100
+ end
101
+
102
+ it { expect(@master.instance_variable_get(:@strategy).class).to be PgPartitioning::Strategies::Date }
103
+
104
+ describe "partitioning!" do
105
+
106
+ it_behaves_like "happy_partitioning"
107
+
108
+ describe "generate right table name" do
109
+ before do
110
+ Bandit.delete_all
111
+ clear_triggers(table)
112
+ @master.partitioning
113
+ @thief = create :thief
114
+ @killer = create :killer
115
+ end
116
+
117
+ it{ expect(Bandit.all.size).to be 2 }
118
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_001_05_00").first).to eq @killer }
119
+ it{ expect(Bandit.find_by_sql("SELECT * FROM bandits_998_01_00").first).to eq @thief }
120
+ end
121
+
122
+ context "with invalid data" do
123
+ it "raise error type of column is not date/time" do
124
+ master = PgPartitioning::PartitioningMaster.new(table, 'id', 2, 'YYY')
125
+ strategy = master.instance_variable_get :@strategy
126
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.column_type" )
127
+ end
128
+
129
+ it "raise error condition is blank" do
130
+ master = PgPartitioning::PartitioningMaster.new(table, 'created_at', 2)
131
+ strategy = master.instance_variable_get :@strategy
132
+ expect{strategy.partitioning!}.to raise_error( I18n.t "pg_partitioning.failure.blank_cond" )
133
+ end
134
+ end
135
+ end
136
+ end
137
+
138
+ context "with old data" do
139
+ before do
140
+ 100.times.with_index do |index|
141
+ create(:bandit, {id: index})
142
+ end
143
+ @old_data = Bandit.all
144
+ master = PgPartitioning::PartitioningMaster.new(table, 'id', 1, 5)
145
+ master.partitioning
146
+ end
147
+
148
+ it "created" do
149
+ expect(Bandit.count).to eq 100
150
+ end
151
+
152
+ it "migrated" do
153
+ expect(Bandit.all).to eq @old_data
154
+ end
155
+ end
156
+ end