diff --git a/ereuse_devicehub/migrations/versions/6a2a939d5668_drop_unique_org_for_tag.py b/ereuse_devicehub/migrations/versions/6a2a939d5668_drop_unique_org_for_tag.py index 417c27f9..b6bdabff 100644 --- a/ereuse_devicehub/migrations/versions/6a2a939d5668_drop_unique_org_for_tag.py +++ b/ereuse_devicehub/migrations/versions/6a2a939d5668_drop_unique_org_for_tag.py @@ -24,10 +24,9 @@ def get_inv(): def upgrade(): op.drop_constraint('one tag id per organization', 'tag', schema=f'{get_inv()}') - op.drop_constraint('one secondary tag per organization', 'tag', schema=f'{get_inv()}') - op.create_unique_constraint('one tag id per owner', 'tag', ['id', 'owner_id'], schema=f'{get_inv()}') + op.create_primary_key('one tag id per owner', 'tag', ['id', 'owner_id'], schema=f'{get_inv()}'), def downgrade(): - op.create_unique_constraint('one tag id per organization', 'tag', ['id', 'org_id'], schema=f'{get_inv()}') - op.create_unique_constraint('one secondary tag per organization', 'tag', ['id', 'secondary'], schema=f'{get_inv()}') + op.drop_constraint('one tag id per owner', 'tag', schema=f'{get_inv()}') + op.create_primary_key('one tag id per organization', 'tag', ['id', 'org_id'], schema=f'{get_inv()}'), diff --git a/ereuse_devicehub/resources/tag/model.py b/ereuse_devicehub/resources/tag/model.py index b5128830..5adce308 100644 --- a/ereuse_devicehub/resources/tag/model.py +++ b/ereuse_devicehub/resources/tag/model.py @@ -30,12 +30,12 @@ class Tag(Thing): id.comment = """The ID of the tag.""" owner_id = Column(UUID(as_uuid=True), ForeignKey(User.id), + primary_key=True, nullable=False, default=lambda: g.user.id) owner = relationship(User, primaryjoin=owner_id == User.id) org_id = Column(UUID(as_uuid=True), ForeignKey(Organization.id), - primary_key=True, # If we link with the Organization object this instance # will be set as persistent and added to session # which is something we don't want to enforce by default @@ -98,8 +98,7 @@ class Tag(Thing): __table_args__ = ( UniqueConstraint(id, owner_id, name='one tag id per owner'), - # UniqueConstraint(id, org_id, name='one tag id per organization'), - # UniqueConstraint(secondary, org_id, name='one secondary tag per organization') + UniqueConstraint(secondary, org_id, name='one secondary tag per organization') ) @property