From 0d7a098ac56f5cc047acdbe7d9a92dd910dccf4c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 5 Mar 2021 11:31:47 +0100 Subject: [PATCH] adding sequence internal_id --- .../versions/6a2a939d5668_drop_unique_org_for_tag.py | 6 ++++++ ereuse_devicehub/resources/tag/model.py | 6 +++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 435cce5d..50a803a9 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 @@ -6,6 +6,7 @@ Create Date: 2021-02-25 18:47:47.441195 """ from alembic import op +import sqlalchemy as sa from alembic import context @@ -27,6 +28,8 @@ def upgrade(): op.drop_constraint('one secondary tag per organization', 'tag', schema=f'{get_inv()}') op.create_primary_key('one tag id per owner', 'tag', ['id', 'owner_id'], schema=f'{get_inv()}'), op.create_unique_constraint('one secondary tag per owner', 'tag', ['secondary', 'owner_id'], schema=f'{get_inv()}'), + op.add_column('tag', sa.Column('internal_id', sa.BigInteger(), nullable=False, + comment='The identifier of the tag for this database. Used only\n internally for software; users should not use this.\n'), schema=f'{get_inv()}') def downgrade(): @@ -34,3 +37,6 @@ def downgrade(): op.drop_constraint('one secondary tag per owner', 'tag', schema=f'{get_inv()}') op.create_primary_key('one tag id per organization', 'tag', ['id', 'org_id'], schema=f'{get_inv()}'), op.create_unique_constraint('one secondary tag per organization', 'tag', ['secondary', 'org_id'], schema=f'{get_inv()}'), + op.drop_column('tag', 'internal_id', schema=f'{get_inv()}') + op.drop_column('tag', 'internal_id', schema=f'{get_inv()}') + op.execute(f"DROP SEQUENCE {get_inv()}.tag_internal_id_seq;") diff --git a/ereuse_devicehub/resources/tag/model.py b/ereuse_devicehub/resources/tag/model.py index 9a5231d7..757f02ae 100644 --- a/ereuse_devicehub/resources/tag/model.py +++ b/ereuse_devicehub/resources/tag/model.py @@ -3,7 +3,7 @@ from typing import Set from boltons import urlutils from flask import g -from sqlalchemy import BigInteger, Column, ForeignKey, UniqueConstraint +from sqlalchemy import BigInteger, Column, ForeignKey, UniqueConstraint, Sequence from sqlalchemy.dialects.postgresql import UUID from sqlalchemy.orm import backref, relationship, validates from teal.db import DB_CASCADE_SET_NULL, Query, URL @@ -26,6 +26,10 @@ class Tags(Set['Tag']): class Tag(Thing): + internal_id = Column(BigInteger, Sequence('tag_internal_id_seq'), unique=True, nulable=False) + internal_id.comment = """The identifier of the tag for this database. Used only + internally for software; users should not use this. + """ id = Column(db.CIText(), primary_key=True) id.comment = """The ID of the tag.""" owner_id = Column(UUID(as_uuid=True),