Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added consistent sql annotations

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