1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Fix warnings for undefined local variable

* Add private method primary_key_for, which more clearly shows that the
expected return value is nil when a primary key is not found.
This commit is contained in:
Tee Parham 2014-09-06 11:52:26 -06:00
parent 95456eb4ef
commit 92fb0815ed

View file

@ -105,18 +105,22 @@ HEADER
end
end
def primary_key_for(table)
if @connection.respond_to?(:pk_and_sequence_for)
pk, _ = @connection.pk_and_sequence_for(table)
return pk if pk
end
return @connection.primary_key(table) if @connection.respond_to?(:primary_key)
nil
end
def table(table, stream)
columns = @connection.columns(table)
begin
tbl = StringIO.new
# first dump primary key column
if @connection.respond_to?(:pk_and_sequence_for)
pk, _ = @connection.pk_and_sequence_for(table)
end
if !pk && @connection.respond_to?(:primary_key)
pk = @connection.primary_key(table)
end
pk = primary_key_for(table)
tbl.print " create_table #{remove_prefix_and_suffix(table).inspect}"
pkcol = columns.detect { |c| c.name == pk }