Skip to content

Commit

Permalink
Upgrade to the improved property api
Browse files Browse the repository at this point in the history
  • Loading branch information
solnic committed Sep 12, 2011
1 parent a07ce2f commit 3758c71
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 9 deletions.
11 changes: 6 additions & 5 deletions lib/dm-migrations/adapters/dm-do-adapter.rb
Expand Up @@ -195,16 +195,17 @@ def create_unique_index_statements(model)

# @api private
def property_schema_hash(property)
primitive = property.primitive
type_map = self.class.type_map
dump_class = property.dump_class
type_map = self.class.type_map
schema = type_map[property.class] || type_map[dump_class]

schema = (type_map[property.class] || type_map[primitive]).merge(:name => property.field)
schema.merge!(:name => property.field)

schema_primitive = schema[:primitive]

if primitive == String && schema_primitive != 'TEXT' && schema_primitive != 'CLOB' && schema_primitive != 'NVARCHAR'
if dump_class.equal?(String) && schema_primitive != 'TEXT' && schema_primitive != 'CLOB' && schema_primitive != 'NVARCHAR'
schema[:length] = property.length
elsif primitive == BigDecimal || primitive == Float
elsif dump_class.equal?(BigDecimal) || dump_class.equal?(Float)
schema[:precision] = property.precision
schema[:scale] = property.scale
end
Expand Down
4 changes: 1 addition & 3 deletions lib/dm-migrations/adapters/dm-postgres-adapter.rb
Expand Up @@ -65,10 +65,8 @@ def without_notices
def property_schema_hash(property)
schema = super

primitive = property.primitive

# Postgres does not support precision and scale for Float
if primitive == Float
if property.kind_of?(Property::Float)
schema.delete(:precision)
schema.delete(:scale)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/dm-migrations/sql/table_creator.rb
Expand Up @@ -83,7 +83,7 @@ def build_type(type_class)
schema[:primitive] = type_class
else
type_map = @adapter.class.type_map
primitive = type_class.respond_to?(:primitive) ? type_class.primitive : type_class
primitive = type_class.respond_to?(:dump_as) ? type_class.dump_as : type_class
options = (type_map[type_class] || type_map[primitive])

schema.update(type_class.options) if type_class.respond_to?(:options)
Expand Down

0 comments on commit 3758c71

Please sign in to comment.