2
0
Fork 0

fix: let caller set data type for uuid_column() and uuid_fk_column()

and rattail now sets the data type, so we should be more free to
experiment with UUID data type
This commit is contained in:
Lance Edgar 2024-11-30 16:06:37 -06:00
parent f63028bf8e
commit 8b6e32145c

View file

@ -61,10 +61,12 @@ def uuid_column(*args, **kwargs):
""" """
Returns a UUID column for use as a table's primary key. Returns a UUID column for use as a table's primary key.
""" """
if not args:
args = (sa.String(length=32),)
kwargs.setdefault('primary_key', True) kwargs.setdefault('primary_key', True)
kwargs.setdefault('nullable', False) kwargs.setdefault('nullable', False)
kwargs.setdefault('default', make_uuid) kwargs.setdefault('default', make_uuid)
return sa.Column(sa.String(length=32), *args, **kwargs) return sa.Column(*args, **kwargs)
def uuid_fk_column(target_column, *args, **kwargs): def uuid_fk_column(target_column, *args, **kwargs):
@ -74,4 +76,6 @@ def uuid_fk_column(target_column, *args, **kwargs):
:param target_column: Name of the table column on the remote side, :param target_column: Name of the table column on the remote side,
e.g. ``'user.uuid'``. e.g. ``'user.uuid'``.
""" """
return sa.Column(sa.String(length=32), sa.ForeignKey(target_column), *args, **kwargs) if not args:
args = (sa.String(length=32), sa.ForeignKey(target_column))
return sa.Column(*args, **kwargs)