Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ags committed Mar 25, 2015
1 parent d373e71 commit 633ec01
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/lhm/migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ def validate
end

unless @origin.satisfies_id_autoincrement_requirement?
if @options[:order_column]
error("order column needs to be specified because no satisfactory primary key exists") unless @origin.can_use_order_column?(@options[:order_column])
if @options[:order_column] && !@origin.can_use_order_column?(@options[:order_column])
error("order column needs to be specified because no satisfactory primary key exists")
else
error("origin does not satisfy primary key requirements")
end
Expand Down
14 changes: 7 additions & 7 deletions lib/lhm/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,11 @@ def initialize(name, pk = 'id', ddl = nil)
end

def satisfies_id_autoincrement_requirement?
!!((id = columns[@pk]) &&
id[:extra] == 'auto_increment' &&
id[:type] =~ /int\(\d+\)/)
monotonically_increasing_numeric_key?(columns[@pk])
end

def can_use_order_column?(column)
numeric_type?(@columns[column][:type])
def can_use_order_column?(column_name)
monotonically_increasing_numeric_key?(columns[column_name])
end

def destination_name
Expand Down Expand Up @@ -121,8 +119,10 @@ def extract_primary_key(schema)
end
end

def numeric_type?(type)
!!(type.match(/int\(\d+\)|decimal|numeric|float|double|integer/))
def monotonically_increasing_numeric_key?(key)
!!(key &&
key[:extra] == 'auto_increment' &&
key[:type] =~ /int\(\d+\)/)
end
end
end
19 changes: 2 additions & 17 deletions spec/integration/lhm_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -334,23 +334,8 @@
table_read(:primary_keys).columns["weird_id"].must_equal({
:type => "int(5)",
:is_nullable => "NO",
:column_default => "0"
})
end
end

it "should change a table with a no primary key" do
table_create(:no_primary_key)

Lhm.change_table(:no_primary_key, :atomic_switch => false, :order_column => 'foreign_id') do |t|
t.change_column(:value, "text")
end

slave do
table_read(:no_primary_key).columns["value"].must_equal({
:type => "text",
:is_nullable => "YES",
:column_default => nil
:column_default => "0",
:extra => ""
})
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/integration/lock_wait_timeout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
global_innodb_lock_wait_timeout = connection.execute("SHOW GLOBAL VARIABLES LIKE 'innodb_lock_wait_timeout'").first.last.to_i
global_lock_wait_timeout = connection.execute("SHOW GLOBAL VARIABLES LIKE 'lock_wait_timeout'").first.last.to_i

invoker = Lhm::Invoker.new(Lhm::Table.parse(:users, connection), connection)
invoker = Lhm::Invoker.new(Lhm::Table.parse(:users, connection), connection, nil)
invoker.set_session_lock_wait_timeouts

session_innodb_lock_wait_timeout = connection.execute("SHOW SESSION VARIABLES LIKE 'innodb_lock_wait_timeout'").first.last.to_i
Expand Down

0 comments on commit 633ec01

Please sign in to comment.