From fb31ce69bc36e264c3c0cafcf3e22d8a19cdeb1c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 12 Jul 2022 13:23:24 +0200 Subject: [PATCH] fix models --- .../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 ++++++++++++- 4 files changed, 19 insertions(+), 5 deletions(-) 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..0703359d 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=binding_id == Device.id, + ) + binding_id.comment = "binding placeholder with workbench device" + class Computer(Device): """A chassis with components inside that can be processed