Skip to content

Commit

Permalink
separate primary key from column type
Browse files Browse the repository at this point in the history
  • Loading branch information
tenderlove committed Mar 23, 2013
1 parent 2ac300b commit d25e407
Showing 1 changed file with 11 additions and 10 deletions.
Expand Up @@ -15,13 +15,13 @@ class IndexDefinition < Struct.new(:table, :name, :unique, :columns, :lengths, :
# are typically created by methods in TableDefinition, and added to the
# +columns+ attribute of said TableDefinition object, in order to be used
# for generating a number of table creation or table changing SQL statements.
class ColumnDefinition < Struct.new(:name, :type, :limit, :precision, :scale, :default, :null, :first, :after) #:nodoc:
class ColumnDefinition < Struct.new(:name, :type, :limit, :precision, :scale, :default, :null, :first, :after, :primary_key) #:nodoc:
def string_to_binary(value)
value
end

def primary_key?
type.to_sym == :primary_key
primary_key || type.to_sym == :primary_key
end
end

Expand Down Expand Up @@ -65,7 +65,7 @@ def columns; @columns_hash.values; end
# Appends a primary key definition to the table definition.
# Can be called multiple times, but this is probably not a good idea.
def primary_key(name)
column(name, :primary_key)
column(name, :primary_key, primary_key: true)
end

# Returns a ColumnDefinition for the column with name +name+.
Expand Down Expand Up @@ -268,13 +268,14 @@ def new_column_definition(name, type, options) # :nodoc:
native[type][:limit] if native[type].is_a?(Hash)
end

column.limit = limit
column.precision = options[:precision]
column.scale = options[:scale]
column.default = options[:default]
column.null = options[:null]
column.first = options[:first]
column.after = options[:after]
column.limit = limit
column.precision = options[:precision]
column.scale = options[:scale]
column.default = options[:default]
column.null = options[:null]
column.first = options[:first]
column.after = options[:after]
column.primary_key = type == :primary_key || options[:primary_key]
column
end

Expand Down

0 comments on commit d25e407

Please sign in to comment.