More concise declarative output.
https://code.google.com/p/sqlalchemy-migrate/issues/detail?id=122
This commit is contained in:
parent
75df12b227
commit
28d2ca21d5
@ -59,7 +59,7 @@ class ModelGenerator(object):
|
|||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
kwarg.append('default')
|
kwarg.append('default')
|
||||||
ks = ', '.join('%s=%r' % (k, getattr(col, k)) for k in kwarg)
|
args = ['%s=%r' % (k, getattr(col, k)) for k in kwarg]
|
||||||
|
|
||||||
# crs: not sure if this is good idea, but it gets rid of extra
|
# crs: not sure if this is good idea, but it gets rid of extra
|
||||||
# u''
|
# u''
|
||||||
@ -73,28 +73,21 @@ class ModelGenerator(object):
|
|||||||
type_ = cls()
|
type_ = cls()
|
||||||
break
|
break
|
||||||
|
|
||||||
|
type_repr = repr(type_)
|
||||||
|
if type_repr.endswith('()'):
|
||||||
|
type_repr = type_repr[:-2]
|
||||||
|
|
||||||
|
constraints = [repr(cn) for cn in col.constraints]
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
'name': name,
|
'name': name,
|
||||||
'type': type_,
|
'commonStuff': ', '.join([type_repr] + args + constraints),
|
||||||
'constraints': ', '.join([repr(cn) for cn in col.constraints]),
|
}
|
||||||
'args': ks and ks or ''}
|
|
||||||
|
|
||||||
if data['constraints']:
|
|
||||||
if data['args']:
|
|
||||||
data['args'] = ',' + data['args']
|
|
||||||
|
|
||||||
if data['constraints'] or data['args']:
|
|
||||||
data['maybeComma'] = ','
|
|
||||||
else:
|
|
||||||
data['maybeComma'] = ''
|
|
||||||
|
|
||||||
commonStuff = """ %(maybeComma)s %(constraints)s %(args)s)""" % data
|
|
||||||
commonStuff = commonStuff.strip()
|
|
||||||
data['commonStuff'] = commonStuff
|
|
||||||
if self.declarative:
|
if self.declarative:
|
||||||
return """%(name)s = Column(%(type)r%(commonStuff)s""" % data
|
return """%(name)s = Column(%(commonStuff)s)""" % data
|
||||||
else:
|
else:
|
||||||
return """Column(%(name)r, %(type)r%(commonStuff)s""" % data
|
return """Column(%(name)r, %(commonStuff)s)""" % data
|
||||||
|
|
||||||
def getTableDefn(self, table):
|
def getTableDefn(self, table):
|
||||||
out = []
|
out = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user