lhm 2.1.0 → 2.2.0

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 (51) hide show
  1. checksums.yaml +5 -13
  2. data/.rubocop.yml +256 -0
  3. data/.travis.yml +2 -3
  4. data/CHANGELOG.md +21 -0
  5. data/README.md +30 -3
  6. data/Rakefile +2 -2
  7. data/bin/lhm-config.sh +7 -0
  8. data/bin/lhm-kill-queue +13 -15
  9. data/bin/lhm-spec-clobber.sh +1 -1
  10. data/bin/lhm-spec-grants.sh +2 -2
  11. data/bin/lhm-spec-setup-cluster.sh +1 -1
  12. data/gemfiles/ar-2.3_mysql.gemfile +1 -0
  13. data/lhm.gemspec +6 -6
  14. data/lib/lhm.rb +20 -8
  15. data/lib/lhm/atomic_switcher.rb +2 -1
  16. data/lib/lhm/chunker.rb +19 -19
  17. data/lib/lhm/command.rb +1 -1
  18. data/lib/lhm/connection.rb +12 -0
  19. data/lib/lhm/entangler.rb +5 -5
  20. data/lib/lhm/intersection.rb +29 -16
  21. data/lib/lhm/invoker.rb +3 -3
  22. data/lib/lhm/locked_switcher.rb +6 -6
  23. data/lib/lhm/migration.rb +5 -4
  24. data/lib/lhm/migrator.rb +39 -10
  25. data/lib/lhm/printer.rb +4 -6
  26. data/lib/lhm/sql_helper.rb +4 -4
  27. data/lib/lhm/table.rb +12 -12
  28. data/lib/lhm/version.rb +1 -1
  29. data/spec/fixtures/users.ddl +1 -1
  30. data/spec/integration/atomic_switcher_spec.rb +7 -7
  31. data/spec/integration/chunker_spec.rb +2 -2
  32. data/spec/integration/cleanup_spec.rb +34 -10
  33. data/spec/integration/entangler_spec.rb +11 -11
  34. data/spec/integration/integration_helper.rb +10 -3
  35. data/spec/integration/lhm_spec.rb +96 -46
  36. data/spec/integration/locked_switcher_spec.rb +7 -7
  37. data/spec/integration/table_spec.rb +15 -15
  38. data/spec/test_helper.rb +4 -4
  39. data/spec/unit/atomic_switcher_spec.rb +6 -6
  40. data/spec/unit/chunker_spec.rb +22 -9
  41. data/spec/unit/entangler_spec.rb +19 -19
  42. data/spec/unit/intersection_spec.rb +27 -15
  43. data/spec/unit/lhm_spec.rb +6 -6
  44. data/spec/unit/locked_switcher_spec.rb +14 -14
  45. data/spec/unit/migration_spec.rb +6 -6
  46. data/spec/unit/migrator_spec.rb +53 -41
  47. data/spec/unit/printer_spec.rb +7 -7
  48. data/spec/unit/sql_helper_spec.rb +10 -10
  49. data/spec/unit/table_spec.rb +11 -11
  50. data/spec/unit/throttler_spec.rb +12 -12
  51. metadata +12 -10
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZWY5MTRiZmFmYTBkNzg0NDhhNjM1MjBlOGM5OWQ1YTljMTkzOTYxOQ==
5
- data.tar.gz: !binary |-
6
- MjE3ODI5NDk3MjUxNmRlNzFkN2ZmYTVmZjZmNWM1OTk3MzA1N2NiNA==
2
+ SHA1:
3
+ metadata.gz: dea357ff2aae21b2cee84cc6d546aa2328fd6164
4
+ data.tar.gz: b6b3e4b06ed6f7ea1b14ac2be2444cc8b6357966
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjBlNGMyNjllMDU5Y2ZmY2E0MjQwOWY0YzIzODk5YjQ0ZDAxOWVlMjU2OTA0
10
- ZWUxYmJmMzFiYzg1MTMzNmMzYzI5OWU3Y2M2MjBmOTQ3MzllZjA5MmViMGNh
11
- MzQ5NmM0YzVmZGMxZWQ3NzdiNmIxMzI1MGE2ZDM0MTU4NGU1NjQ=
12
- data.tar.gz: !binary |-
13
- ZmFlNTRkMDkyOWJlOTkzZjA2ZTdiNjA1MGNjZWVjODNiMGY3OWE1MWY2YmVk
14
- ZWFmZGFhMGJhODNjNGVjZGE1NmQyZWRjMTg5NzBkZDY5NWMxNDJmNWE2NTU3
15
- ODc4MmYxMWRmODM5NDdiNTRkNmVlMGQwZTEzNmE5MzM4YzlhMzY=
6
+ metadata.gz: a4a2e08f68b46ba6141bd37093f3c5341488c60d4a1bf6069b1339481f11ff1117ebe1198a383e09f1ae635d68966e98256d31a981ff89171eb582fd7b075170
7
+ data.tar.gz: 49174830b37493a1652394a4ee717f52939675d39289bc183f38969ae840cc5c9f00b5668d585888751916e395f471a3f24501192c8bf52cd3321d1c9d50dc32
@@ -0,0 +1,256 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-01-12 14:49:41 +0100 using RuboCop version 0.26.1.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 2
9
+ Lint/AmbiguousRegexpLiteral:
10
+ Enabled: false
11
+
12
+ # Offense count: 2
13
+ # Configuration parameters: AllowSafeAssignment.
14
+ Lint/AssignmentInCondition:
15
+ Enabled: false
16
+
17
+ # Offense count: 1
18
+ Lint/ConditionPosition:
19
+ Enabled: false
20
+
21
+ # Offense count: 1
22
+ Lint/HandleExceptions:
23
+ Enabled: false
24
+
25
+ # Offense count: 6
26
+ # Cop supports --auto-correct.
27
+ Lint/UnusedBlockArgument:
28
+ Enabled: false
29
+
30
+ # Offense count: 3
31
+ # Cop supports --auto-correct.
32
+ Lint/UnusedMethodArgument:
33
+ Enabled: false
34
+
35
+ # Offense count: 4
36
+ Lint/UselessAssignment:
37
+ Enabled: false
38
+
39
+ # Offense count: 1
40
+ # Configuration parameters: CountComments.
41
+ Metrics/ClassLength:
42
+ Max: 131
43
+
44
+ # Offense count: 3
45
+ Metrics/CyclomaticComplexity:
46
+ Max: 19
47
+
48
+ # Offense count: 77
49
+ # Configuration parameters: AllowURI, URISchemes.
50
+ Metrics/LineLength:
51
+ Max: 197
52
+
53
+ # Offense count: 11
54
+ # Configuration parameters: CountComments.
55
+ Metrics/MethodLength:
56
+ Max: 27
57
+
58
+ # Offense count: 3
59
+ Metrics/PerceivedComplexity:
60
+ Max: 15
61
+
62
+ # Offense count: 10
63
+ # Cop supports --auto-correct.
64
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
65
+ Style/AccessModifierIndentation:
66
+ Enabled: false
67
+
68
+ # Offense count: 4
69
+ # Cop supports --auto-correct.
70
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
71
+ Style/AlignParameters:
72
+ Enabled: false
73
+
74
+ # Offense count: 5
75
+ # Cop supports --auto-correct.
76
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
77
+ Style/AndOr:
78
+ Enabled: false
79
+
80
+ # Offense count: 13
81
+ # Cop supports --auto-correct.
82
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
83
+ Style/BarePercentLiterals:
84
+ Enabled: false
85
+
86
+ # Offense count: 1
87
+ # Cop supports --auto-correct.
88
+ Style/Blocks:
89
+ Enabled: false
90
+
91
+ # Offense count: 11
92
+ # Cop supports --auto-correct.
93
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
94
+ Style/BracesAroundHashParameters:
95
+ Enabled: false
96
+
97
+ # Offense count: 5
98
+ Style/ClassVars:
99
+ Enabled: false
100
+
101
+ # Offense count: 3
102
+ # Cop supports --auto-correct.
103
+ # Configuration parameters: PreferredMethods.
104
+ Style/CollectionMethods:
105
+ Enabled: false
106
+
107
+ # Offense count: 24
108
+ Style/Documentation:
109
+ Enabled: false
110
+
111
+ # Offense count: 28
112
+ # Cop supports --auto-correct.
113
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
114
+ Style/DotPosition:
115
+ Enabled: false
116
+
117
+ # Offense count: 4
118
+ Style/DoubleNegation:
119
+ Enabled: false
120
+
121
+ # Offense count: 1
122
+ Style/EachWithObject:
123
+ Enabled: false
124
+
125
+ # Offense count: 1
126
+ # Configuration parameters: Exclude.
127
+ Style/FileName:
128
+ Enabled: false
129
+
130
+ # Offense count: 11
131
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
132
+ Style/FormatString:
133
+ Enabled: false
134
+
135
+ # Offense count: 10
136
+ # Configuration parameters: AllowedVariables.
137
+ Style/GlobalVars:
138
+ Enabled: false
139
+
140
+ # Offense count: 9
141
+ # Configuration parameters: MinBodyLength.
142
+ Style/GuardClause:
143
+ Enabled: false
144
+
145
+ # Offense count: 88
146
+ # Cop supports --auto-correct.
147
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
148
+ Style/HashSyntax:
149
+ Enabled: false
150
+
151
+ # Offense count: 3
152
+ # Configuration parameters: MaxLineLength.
153
+ Style/IfUnlessModifier:
154
+ Enabled: false
155
+
156
+ # Offense count: 14
157
+ # Cop supports --auto-correct.
158
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
159
+ Style/IndentHash:
160
+ Enabled: false
161
+
162
+ # Offense count: 1
163
+ # Cop supports --auto-correct.
164
+ Style/IndentationConsistency:
165
+ Enabled: false
166
+
167
+ # Offense count: 1
168
+ # Cop supports --auto-correct.
169
+ Style/IndentationWidth:
170
+ Enabled: false
171
+
172
+ # Offense count: 2
173
+ Style/ModuleFunction:
174
+ Enabled: false
175
+
176
+ # Offense count: 2
177
+ Style/MultilineBlockChain:
178
+ Enabled: false
179
+
180
+ # Offense count: 1
181
+ # Cop supports --auto-correct.
182
+ Style/NegatedIf:
183
+ Enabled: false
184
+
185
+ # Offense count: 4
186
+ # Cop supports --auto-correct.
187
+ Style/NumericLiterals:
188
+ MinDigits: 8
189
+
190
+ # Offense count: 14
191
+ # Cop supports --auto-correct.
192
+ # Configuration parameters: PreferredDelimiters.
193
+ Style/PercentLiteralDelimiters:
194
+ Enabled: false
195
+
196
+ # Offense count: 3
197
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
198
+ Style/RaiseArgs:
199
+ Enabled: false
200
+
201
+ # Offense count: 1
202
+ # Cop supports --auto-correct.
203
+ # Configuration parameters: AllowMultipleReturnValues.
204
+ Style/RedundantReturn:
205
+ Enabled: false
206
+
207
+ # Offense count: 2
208
+ # Cop supports --auto-correct.
209
+ Style/RedundantSelf:
210
+ Enabled: false
211
+
212
+ # Offense count: 1
213
+ Style/RescueModifier:
214
+ Enabled: false
215
+
216
+ # Offense count: 1
217
+ Style/SelfAssignment:
218
+ Enabled: false
219
+
220
+ # Offense count: 7
221
+ # Cop supports --auto-correct.
222
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
223
+ Style/SignalException:
224
+ Enabled: false
225
+
226
+ # Cop supports --auto-correct.
227
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
228
+ Style/SpaceInsideHashLiteralBraces:
229
+ SupportedStyles: space
230
+
231
+ # Offense count: 2
232
+ # Cop supports --auto-correct.
233
+ Style/SpecialGlobalVars:
234
+ Enabled: false
235
+
236
+ # Offense count: 5
237
+ # Cop supports --auto-correct.
238
+ # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist.
239
+ Style/TrivialAccessors:
240
+ Enabled: false
241
+
242
+ # Offense count: 15
243
+ # Cop supports --auto-correct.
244
+ Style/UnneededPercentQ:
245
+ Enabled: false
246
+
247
+ # Offense count: 3
248
+ # Cop supports --auto-correct.
249
+ Style/WordArray:
250
+ MinSize: 2
251
+
252
+ # Offense count: 2
253
+ # Cop supports --auto-correct.
254
+ # Configuration parameters: AllowSafeAssignment.
255
+ Style/ParenthesesAroundCondition:
256
+ Enabled: false
@@ -4,10 +4,9 @@ before_script:
4
4
  rvm:
5
5
  - 1.9.3
6
6
  - 2.0.0
7
- - 2.1.1
7
+ - 2.1
8
+ sudo: false
8
9
  matrix:
9
- allow_failures:
10
- - gemfile: gemfiles/ar-2.3_mysql.gemfile
11
10
  fast_finish: true
12
11
  gemfile:
13
12
  - gemfiles/ar-2.3_mysql.gemfile
@@ -1,3 +1,24 @@
1
+ # 2.2.0 (not released)
2
+
3
+ * #84 - Require index names to be strings or symbols (Thibaut)
4
+ * #39 - Adding the ability to rename columns (erikogan)
5
+ * #67 - Allow for optional time filter on .cleanup (joelr)
6
+
7
+ # 2.1.0
8
+
9
+ * #48 - Add percentage output for migrations (@arthurnn)
10
+ * #60 - Quote table names (@spickermann)
11
+ * #59 - Escape table name in select_limit and select_start methods (@stevehodgkiss)
12
+ * #57 - Ensure chunking 'where' clause handled separately (@rentalcustard)
13
+ * #54 - Chunker handle stride changes (@rentalcustard)
14
+ * #52 - Implement ability to control timeout and stride from Throttler (@edmundsalvacion)
15
+ * #51 - Ensure Lhm.cleanup removes temporary triggers (@edmundsalvacion)
16
+ * #46 - Allow custom throttler (@arthurnn)
17
+
18
+ # 2.0.0
19
+
20
+ * #44 - Conditional migrations (@durran)
21
+
1
22
  # 1.3.0 (May 28, 2013)
2
23
 
3
24
  * Add Lhm.cleanup method for removing copy tables, thanks @bogdan
data/README.md CHANGED
@@ -45,15 +45,13 @@ the [twitter solution][2], it does not require the presence of an indexed
45
45
  Lhm currently only works with MySQL databases and requires an established
46
46
  ActiveRecord or DataMapper connection.
47
47
 
48
- It is compatible and [continuously tested][4] with MRI 1.9.x,
48
+ It is compatible and [continuously tested][4] with MRI 1.9.x, 2.0.x, 2.1.x,
49
49
  ActiveRecord 2.3.x and 3.x (mysql and mysql2 adapters), as well as DataMapper
50
50
  1.2 (dm-mysql-adapter).
51
51
 
52
52
  Lhm also works with dm-master-slave-adapter, it'll bind to the master before
53
53
  running the migrations.
54
54
 
55
- The test suite is also run against MRI 2.0.0 in Continuous Integration, but
56
- there are a few bugs left to fix.
57
55
 
58
56
  ## Limitations
59
57
 
@@ -141,6 +139,23 @@ end
141
139
  **Note:** Lhm won't delete the old, leftover table. This is on purpose, in order
142
140
  to prevent accidental data loss.
143
141
 
142
+ ## Throttler
143
+
144
+ Lhm is using a throttle mecanism to read data in your original table.
145
+
146
+ By default, 40000 rows are read each 0.1 second.
147
+
148
+ If you want to change that behiavour, you can pass an instance of a throttler with the `throttler` option.
149
+
150
+ In this example, 1000 rows will be read with a 10 seconds delay between each processing:
151
+ ```ruby
152
+ my_throttler = Lhm::Throttler::Time.new(stride: 1000, delay: 10)
153
+
154
+ Lhm.change_table :users, throttler: my_throttler do |m|
155
+ #
156
+ end
157
+ ```
158
+
144
159
  ## Table rename strategies
145
160
 
146
161
  There are two different table rename strategies available: LockedSwitcher and
@@ -198,6 +213,18 @@ To remove any Lhm tables/triggers found:
198
213
  Lhm.cleanup(true)
199
214
  ```
200
215
 
216
+ Optionally only remove tables up to a specific Time, if you want to retain previous migrations.
217
+
218
+ Rails:
219
+ ```ruby
220
+ Lhm.cleanup(true, until: 1.day.ago)
221
+ ```
222
+
223
+ Ruby:
224
+ ```ruby
225
+ Lhm.cleanup(true, until: Time.now - 86400)
226
+ ```
227
+
201
228
  ## Contributing
202
229
 
203
230
  First, get set up for local development:
data/Rakefile CHANGED
@@ -3,14 +3,14 @@ require 'bundler'
3
3
 
4
4
  Bundler::GemHelper.install_tasks
5
5
 
6
- Rake::TestTask.new("unit") do |t|
6
+ Rake::TestTask.new('unit') do |t|
7
7
  t.libs << 'lib'
8
8
  t.libs << 'spec'
9
9
  t.test_files = FileList['spec/unit/*_spec.rb']
10
10
  t.verbose = true
11
11
  end
12
12
 
13
- Rake::TestTask.new("integration") do |t|
13
+ Rake::TestTask.new('integration') do |t|
14
14
  t.libs << 'lib'
15
15
  t.libs << 'spec'
16
16
  t.test_files = FileList['spec/integration/*_spec.rb']
@@ -0,0 +1,7 @@
1
+ #!/bin/sh
2
+
3
+ if [ -z ${LHM_TEST_CONFIG+x} ] ; then
4
+ source $HOME/.lhm
5
+ else
6
+ source $LHM_TEST_CONFIG
7
+ fi
@@ -6,7 +6,6 @@ require 'optparse'
6
6
 
7
7
  module Lhm
8
8
  class KillQueue
9
-
10
9
  def initialize
11
10
  @port = 3306
12
11
  @grace = 10
@@ -14,20 +13,20 @@ module Lhm
14
13
  @marker = "%#{ SqlHelper.annotation }%"
15
14
 
16
15
  OptionParser.new do |opts|
17
- opts.on("-h", "--hostname HOSTNAME") { |v| @hostname = v }
18
- opts.on("-u", "--username USERNAME") { |v| @username = v }
19
- opts.on("-p", "--password PASSWORD") { |v| @password = v }
20
- opts.on("-d", "--database DATABASE") { |v| @database = v }
21
- opts.on("-m", "--mode MODE") { |v| @mode = v.to_sym }
22
- opts.on("-y", "--confirm") { |v| @confirm = true }
16
+ opts.on('-h', '--hostname HOSTNAME') { |v| @hostname = v }
17
+ opts.on('-u', '--username USERNAME') { |v| @username = v }
18
+ opts.on('-p', '--password PASSWORD') { |v| @password = v }
19
+ opts.on('-d', '--database DATABASE') { |v| @database = v }
20
+ opts.on('-m', '--mode MODE') { |v| @mode = v.to_sym }
21
+ opts.on('-y', '--confirm') { |v| @confirm = true }
23
22
  end.parse!
24
23
 
25
- unless(@hostname && @username && @password && @database)
24
+ unless (@hostname && @username && @password && @database)
26
25
  abort usage
27
26
  end
28
27
 
29
- unless([:kill, :master, :slave].include?(@mode))
30
- abort "specify -m kill OR -m master OR -m slave"
28
+ unless ([:kill, :master, :slave].include?(@mode))
29
+ abort 'specify -m kill OR -m master OR -m slave'
31
30
  end
32
31
 
33
32
  connect
@@ -73,7 +72,7 @@ module Lhm
73
72
  sleep(@grace + @tiny)
74
73
 
75
74
  [list_non_lhm].flatten.each do |process|
76
- if(select?(process))
75
+ if (select?(process))
77
76
  kill_process(process)
78
77
  sleep(@tiny)
79
78
  end
@@ -115,11 +114,11 @@ module Lhm
115
114
  def kill_process(process_id)
116
115
  puts "killing #{ select_statement(process_id) }"
117
116
 
118
- if(@confirm)
117
+ if (@confirm)
119
118
  print "confirm ('y' to confirm): "
120
119
 
121
- if(gets.strip != 'y')
122
- puts "skipped."
120
+ if (gets.strip != 'y')
121
+ puts 'skipped.'
123
122
  return
124
123
  end
125
124
  end
@@ -169,4 +168,3 @@ end
169
168
 
170
169
  killer = Lhm::KillQueue.new
171
170
  killer.run
172
-