Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #60 from spickermann/fixes-migrations-on-tables-wi…

…th-reserved-names

Quote table names
  • Loading branch information...
commit c6d1b9e367472328aaef7e96da7240082976e66f 2 parents 28c30da + b93b49d
@grobie grobie authored
View
4 lib/lhm/chunker.rb
@@ -51,7 +51,7 @@ def top(stride)
def copy(lowest, highest)
"insert ignore into `#{ destination_name }` (#{ columns }) " +
"select #{ select_columns } from `#{ origin_name }` " +
- "#{ conditions } #{ origin_name }.`id` between #{ lowest } and #{ highest }"
+ "#{ conditions } `#{ origin_name }`.`id` between #{ lowest } and #{ highest }"
end
def select_start
@@ -96,7 +96,7 @@ def columns
end
def select_columns
- @select_columns ||= @migration.intersection.typed(origin_name)
+ @select_columns ||= @migration.intersection.typed("`#{origin_name}`")
end
def validate
View
2  lib/lhm/invoker.rb
@@ -54,7 +54,7 @@ def normalize_options(options)
options[:throttler] = Throttler::Factory.create_throttler(*options[:throttler])
elsif options[:throttle] || options[:stride]
# we still support the throttle and stride as a Fixnum input
- warn "throttle option will no loger accept a Fixnum in the next versions."
+ warn "throttle option will no longer accept a Fixnum in the next versions."
options[:throttler] = Throttler::LegacyTime.new(options[:throttle], options[:stride])
else
options[:throttler] = Lhm.throttler
View
2  spec/integration/integration_helper.rb
@@ -131,7 +131,7 @@ def count(table, column, value)
end
def count_all(table)
- query = "select count(*) from #{ table }"
+ query = "select count(*) from `#{ table }`"
select_value(query).to_i
end
View
3  spec/integration/lhm_spec.rb
@@ -207,6 +207,8 @@
it "works when mysql reserved words are used" do
table_create(:lines)
+ execute("insert into `lines` set id = 1, `between` = 'foo'")
+ execute("insert into `lines` set id = 2, `between` = 'bar'")
Lhm.change_table(:lines) do |t|
t.add_column('by', 'varchar(10)')
@@ -221,6 +223,7 @@
table_read(:lines).columns.wont_include 'lines'
index_on_columns?(:lines, ['between'], :unique).must_equal true
index_on_columns?(:lines, ['by']).must_equal false
+ count_all(:lines).must_equal(2)
end
end
View
4 spec/unit/chunker_spec.rb
@@ -22,7 +22,7 @@ def @throttler.run
#noop
end
def @throttler.stride
- 1
+ 1
end
@chunker = Lhm::Chunker.new(@migration, @connection, :throttler => @throttler,
:start => 1,
@@ -89,7 +89,7 @@ def @throttler.stride
:start => 1,
:limit => 2)
@connection.expect(:update, 1) do |stmt|
- stmt.first =~ /where \(foo.created_at > '2013-07-10' or foo.baz = 'quux'\) and foo/
+ stmt.first =~ /where \(foo.created_at > '2013-07-10' or foo.baz = 'quux'\) and `foo`/
end
def @migration.conditions
Please sign in to comment.
Something went wrong with that request. Please try again.