Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added consistent sql annotations

  • Loading branch information...
commit 2cd918eaa479b4c725907bac50484b596542f315 1 parent 95bae33
Rany Keddo purzelrakete authored
6 CHANGELOG.md
Source Rendered
... ... @@ -1,3 +1,9 @@
  1 +# 1.0.0.rc7 (January 31, 2012)
  2 +
  3 +* added SqlHelper.annotation into the middle of trigger statements. this
  4 + is for the benefit of the killer script which should not kill trigger
  5 + statements.
  6 +
1 7 # 1.0.0.rc6 (January 30, 2012)
2 8
3 9 * added --confirm to kill script; fixes to kill script
8 bin/lhm-kill-queue
... ... @@ -1,6 +1,7 @@
1 1 #!/usr/bin/env ruby
2 2
3 3 require 'active_record'
  4 +require 'lhm/sql_helper'
4 5 require 'optparse'
5 6
6 7 module Lhm
@@ -10,6 +11,7 @@ module Lhm
10 11 @port = 3306
11 12 @grace = 10
12 13 @tiny = 0.1
  14 + @marker = "%#{ SqlHelper.annotation }%"
13 15
14 16 OptionParser.new do |opts|
15 17 opts.on("-h", "--hostname HOSTNAME") { |v| @hostname = v }
@@ -33,7 +35,7 @@ module Lhm
33 35
34 36 def usage
35 37 <<-desc.gsub(/^ /, '')
36   - kills queries on the given server after detecting 'lock table% -- lhm'.
  38 + kills queries on the given server after detecting 'lock table#{ @marker }'.
37 39 usage:
38 40 lhm-kill-queue -h hostname -u username -p password -d database \\
39 41 (-m kill | -m master | -m slave) [--confirm]
@@ -97,12 +99,12 @@ module Lhm
97 99
98 100 def list_non_lhm
99 101 select_processes %Q(
100   - info not like '% -- lhm' and time > #{ @grace } and command = 'Query'
  102 + info not like '#{ @marker }' and time > #{ @grace } and command = 'Query'
101 103 )
102 104 end
103 105
104 106 def trip
105   - until res = select_processes("info like 'lock table% -- lhm'").first
  107 + until res = select_processes("info like 'lock table#{ @marker }'").first
106 108 sleep @tiny
107 109 print '.'
108 110 end
6 lib/lhm.rb
@@ -17,7 +17,6 @@
17 17 # end
18 18 #
19 19 module Lhm
20   - extend self
21 20
22 21 # Alters a table with the changes described in the block
23 22 #
@@ -28,9 +27,9 @@ module Lhm
28 27 # @option chunk_options [Fixnum] :throttle
29 28 # Time to wait between chunks in milliseconds (defaults to: 100)
30 29 # @yield [Migrator] Yielded Migrator object records the changes
31   - # @return [Boolean] Returns true if the migration finishs
  30 + # @return [Boolean] Returns true if the migration finishes
32 31 # @raise [Error] Raises Lhm::Error in case of a error and aborts the migration
33   - def change_table(table_name, chunk_options = {}, &block)
  32 + def self.change_table(table_name, chunk_options = {}, &block)
34 33 connection = ActiveRecord::Base.connection
35 34 origin = Table.parse(table_name, connection)
36 35 invoker = Invoker.new(origin, connection)
@@ -40,3 +39,4 @@ def change_table(table_name, chunk_options = {}, &block)
40 39 true
41 40 end
42 41 end
  42 +
6 lib/lhm/entangler.rb
@@ -40,7 +40,7 @@ def create_insert_trigger
40 40 strip %Q{
41 41 create trigger `#{ trigger(:ins) }`
42 42 after insert on `#{ @origin.name }` for each row
43   - replace into `#{ @destination.name }` (#{ @common.joined })
  43 + replace into `#{ @destination.name }` (#{ @common.joined }) #{ SqlHelper.annotation }
44 44 values (#{ @common.typed("NEW") })
45 45 }
46 46 end
@@ -49,7 +49,7 @@ def create_update_trigger
49 49 strip %Q{
50 50 create trigger `#{ trigger(:upd) }`
51 51 after update on `#{ @origin.name }` for each row
52   - replace into `#{ @destination.name }` (#{ @common.joined })
  52 + replace into `#{ @destination.name }` (#{ @common.joined }) #{ SqlHelper.annotation }
53 53 values (#{ @common.typed("NEW") })
54 54 }
55 55 end
@@ -58,7 +58,7 @@ def create_delete_trigger
58 58 strip %Q{
59 59 create trigger `#{ trigger(:del) }`
60 60 after delete on `#{ @origin.name }` for each row
61   - delete ignore from `#{ @destination.name }`
  61 + delete ignore from `#{ @destination.name }` #{ SqlHelper.annotation }
62 62 where `#{ @destination.name }`.`id` = OLD.`id`
63 63 }
64 64 end
8 lib/lhm/sql_helper.rb
@@ -5,6 +5,10 @@ module Lhm
5 5 module SqlHelper
6 6 extend self
7 7
  8 + def annotation
  9 + "/* large hadron migration */"
  10 + end
  11 +
8 12 def idx_name(table_name, cols)
9 13 column_names = column_definition(cols).map(&:first)
10 14 "index_#{ table_name }_on_#{ column_names.join("_and_") }"
@@ -12,7 +16,7 @@ def idx_name(table_name, cols)
12 16
13 17 def idx_spec(cols)
14 18 column_definition(cols).map do |name, length|
15   - "`#{name}`#{length}"
  19 + "`#{ name }`#{ length }"
16 20 end.join(', ')
17 21 end
18 22
@@ -39,7 +43,7 @@ def update(statements)
39 43 private
40 44
41 45 def tagged(statement)
42   - statement + " -- lhm"
  46 + "#{ statement } #{ SqlHelper.annotation }"
43 47 end
44 48
45 49 def column_definition(cols)
2  lib/lhm/version.rb
@@ -2,5 +2,5 @@
2 2 # Schmidt
3 3
4 4 module Lhm
5   - VERSION = "1.0.0.rc6"
  5 + VERSION = "1.0.0.rc7"
6 6 end
6 spec/unit/entangler_spec.rb
@@ -30,7 +30,7 @@
30 30 ddl = %Q{
31 31 create trigger `lhmt_ins_origin`
32 32 after insert on `origin` for each row
33   - replace into `destination` (`info`, `tags`)
  33 + replace into `destination` (`info`, `tags`) /* large hadron migration */
34 34 values (NEW.`info`, NEW.`tags`)
35 35 }
36 36
@@ -41,7 +41,7 @@
41 41 ddl = %Q{
42 42 create trigger `lhmt_upd_origin`
43 43 after update on `origin` for each row
44   - replace into `destination` (`info`, `tags`)
  44 + replace into `destination` (`info`, `tags`) /* large hadron migration */
45 45 values (NEW.`info`, NEW.`tags`)
46 46 }
47 47
@@ -52,7 +52,7 @@
52 52 ddl = %Q{
53 53 create trigger `lhmt_del_origin`
54 54 after delete on `origin` for each row
55   - delete ignore from `destination`
  55 + delete ignore from `destination` /* large hadron migration */
56 56 where `destination`.`id` = OLD.`id`
57 57 }
58 58

0 comments on commit 2cd918e

Please sign in to comment.
Something went wrong with that request. Please try again.