add binding relation

This commit is contained in:
Cayo Puigdefabregas 2022-07-11 15:36:45 +02:00
parent 99238d69d8
commit a21018a2d2
5 changed files with 21 additions and 7 deletions

View File

@ -1,10 +1,10 @@
repos: repos:
- repo: https://github.com/psf/black - repo: https://github.com/psf/black
rev: 22.1.0 rev: 22.6.0
hooks: hooks:
- id: black - id: black
- repo: https://github.com/PyCQA/isort - repo: https://github.com/PyCQA/isort
rev: 5.9.3 rev: 5.10.1
hooks: hooks:
- id: isort - id: isort
- repo: https://github.com/PyCQA/flake8 - repo: https://github.com/PyCQA/flake8

View File

@ -49,17 +49,18 @@ def upgrade():
sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False), sa.Column('owner_id', postgresql.UUID(as_uuid=True), nullable=False),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
['placeholder_id'], ['placeholder_id'],
['placeholder.id'], [f'{get_inv()}.placeholder.id'],
), ),
sa.ForeignKeyConstraint( sa.ForeignKeyConstraint(
['owner_id'], ['owner_id'],
['common.user.id'], ['common.user.id'],
), ),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
schema=f'{get_inv()}',
) )
op.execute("CREATE SEQUENCE placeholders_log_seq START 1;") op.execute("CREATE SEQUENCE placeholders_log_seq START 1;")
def downgrade(): def downgrade():
op.drop_table('placeholders_log') op.drop_table('placeholders_log', schema=f'{get_inv()}')
op.execute("DROP SEQUENCE placeholders_log_seq;") op.execute("DROP SEQUENCE placeholders_log_seq;")

View File

@ -46,12 +46,15 @@ def upgrade():
sa.Column('pallet', sa.Unicode(), nullable=True), sa.Column('pallet', sa.Unicode(), nullable=True),
sa.Column('info', citext.CIText(), nullable=True), sa.Column('info', citext.CIText(), nullable=True),
sa.Column('device_id', sa.BigInteger(), nullable=False), 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(['device_id'], [f'{get_inv()}.device.id']),
sa.ForeignKeyConstraint(['binding_id'], [f'{get_inv()}.device.id']),
sa.PrimaryKeyConstraint('id'), sa.PrimaryKeyConstraint('id'),
schema=f'{get_inv()}',
) )
op.execute("CREATE SEQUENCE placeholder_seq START 1;") op.execute("CREATE SEQUENCE placeholder_seq START 1;")
def downgrade(): def downgrade():
op.drop_table('placeholder') op.drop_table('placeholder', schema=f'{get_inv()}')
op.execute("DROP SEQUENCE placeholder_seq;") op.execute("DROP SEQUENCE placeholder_seq;")

View File

@ -49,7 +49,6 @@ class SnapshotsLog(Thing):
class PlaceholdersLog(Thing): class PlaceholdersLog(Thing):
"""A Placeholder log.""" """A Placeholder log."""
__table_args__ = {'schema': ''}
id = Column(BigInteger, Sequence('placeholders_log_seq'), primary_key=True) id = Column(BigInteger, Sequence('placeholders_log_seq'), primary_key=True)
source = Column(CIText(), default='', nullable=True) source = Column(CIText(), default='', nullable=True)
type = Column(CIText(), default='', nullable=True) type = Column(CIText(), default='', nullable=True)

View File

@ -827,7 +827,6 @@ class DisplayMixin:
class Placeholder(Thing): class Placeholder(Thing):
__table_args__ = {'schema': ''}
id = Column(BigInteger, Sequence('placeholder_seq'), primary_key=True) id = Column(BigInteger, Sequence('placeholder_seq'), primary_key=True)
pallet = Column(Unicode(), nullable=True) pallet = Column(Unicode(), nullable=True)
phid = Column(Unicode(), nullable=False, default=create_phid) phid = Column(Unicode(), nullable=False, default=create_phid)
@ -851,6 +850,18 @@ class Placeholder(Thing):
) )
device_id.comment = "datas of the placeholder" 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): class Computer(Device):
"""A chassis with components inside that can be processed """A chassis with components inside that can be processed