From a21018a2d20e457f0e2b555802322c3715004b51 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 11 Jul 2022 15:36:45 +0200 Subject: [PATCH] add binding relation --- .pre-commit-config.yaml | 4 ++-- .../versions/3e3a67f62972_placeholder_log.py | 5 +++-- .../versions/aeca9fb50cc6_add_placeholder.py | 5 ++++- ereuse_devicehub/parser/models.py | 1 - ereuse_devicehub/resources/device/models.py | 13 ++++++++++++- 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e6bc1402..35bfc9bf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: https://github.com/psf/black - rev: 22.1.0 + rev: 22.6.0 hooks: - id: black - repo: https://github.com/PyCQA/isort - rev: 5.9.3 + rev: 5.10.1 hooks: - id: isort - repo: https://github.com/PyCQA/flake8 diff --git a/ereuse_devicehub/migrations/versions/3e3a67f62972_placeholder_log.py b/ereuse_devicehub/migrations/versions/3e3a67f62972_placeholder_log.py index 1e1de004..f51b3749 100644 --- a/ereuse_devicehub/migrations/versions/3e3a67f62972_placeholder_log.py +++ b/ereuse_devicehub/migrations/versions/3e3a67f62972_placeholder_log.py @@ -49,17 +49,18 @@ def upgrade(): sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False), sa.ForeignKeyConstraint( ['placeholder_id'], - ['placeholder.id'], + [f'{get_inv()}.placeholder.id'], ), sa.ForeignKeyConstraint( ['owner_id'], ['common.user.id'], ), sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', ) op.execute("CREATE SEQUENCE placeholders_log_seq START 1;") def downgrade(): - op.drop_table('placeholders_log') + op.drop_table('placeholders_log', schema=f'{get_inv()}') op.execute("DROP SEQUENCE placeholders_log_seq;") diff --git a/ereuse_devicehub/migrations/versions/aeca9fb50cc6_add_placeholder.py b/ereuse_devicehub/migrations/versions/aeca9fb50cc6_add_placeholder.py index 9a3b8e25..84137bab 100644 --- a/ereuse_devicehub/migrations/versions/aeca9fb50cc6_add_placeholder.py +++ b/ereuse_devicehub/migrations/versions/aeca9fb50cc6_add_placeholder.py @@ -46,12 +46,15 @@ def upgrade(): sa.Column('pallet', sa.Unicode(), nullable=True), sa.Column('info', citext.CIText(), nullable=True), sa.Column('device_id', sa.BigInteger(), nullable=False), + sa.Column('binding_id', sa.BigInteger(), nullable=True), sa.ForeignKeyConstraint(['device_id'], [f'{get_inv()}.device.id']), + sa.ForeignKeyConstraint(['binding_id'], [f'{get_inv()}.device.id']), sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', ) op.execute("CREATE SEQUENCE placeholder_seq START 1;") def downgrade(): - op.drop_table('placeholder') + op.drop_table('placeholder', schema=f'{get_inv()}') op.execute("DROP SEQUENCE placeholder_seq;") diff --git a/ereuse_devicehub/parser/models.py b/ereuse_devicehub/parser/models.py index d8b4b62b..69cd574c 100644 --- a/ereuse_devicehub/parser/models.py +++ b/ereuse_devicehub/parser/models.py @@ -49,7 +49,6 @@ class SnapshotsLog(Thing): class PlaceholdersLog(Thing): """A Placeholder log.""" - __table_args__ = {'schema': ''} id = Column(BigInteger, Sequence('placeholders_log_seq'), primary_key=True) source = Column(CIText(), default='', nullable=True) type = Column(CIText(), default='', nullable=True) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 0dd308e4..7d8d570b 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -827,7 +827,6 @@ class DisplayMixin: class Placeholder(Thing): - __table_args__ = {'schema': ''} id = Column(BigInteger, Sequence('placeholder_seq'), primary_key=True) pallet = Column(Unicode(), nullable=True) phid = Column(Unicode(), nullable=False, default=create_phid) @@ -851,6 +850,18 @@ class Placeholder(Thing): ) device_id.comment = "datas of the placeholder" + binding_id = db.Column( + BigInteger, + db.ForeignKey(Device.id), + nullable=True, + ) + binding = db.relationship( + Device, + backref=backref('binding', lazy=True, uselist=False), + primaryjoin=device_id == Device.id, + ) + binding_id.comment = "binding placeholder with workbench device" + class Computer(Device): """A chassis with components inside that can be processed