fix models

This commit is contained in:
Cayo Puigdefabregas 2022-07-12 13:23:24 +02:00
parent 0253eda736
commit fb31ce69bc
4 changed files with 19 additions and 5 deletions

View File

@ -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;")

View File

@ -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;")

View File

@ -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)

View File

@ -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