add models

This commit is contained in:
Cayo Puigdefabregas 2022-06-28 17:38:05 +02:00
parent 35ccb33f34
commit 12d55c2d24
2 changed files with 71 additions and 12 deletions

View file

@ -0,0 +1,60 @@
"""add placeholder
Revision ID: aeca9fb50cc6
Revises: 8d4fe4b497b3
Create Date: 2022-06-27 13:09:30.497678
"""
import citext
import sqlalchemy as sa
from alembic import context, op
# revision identifiers, used by Alembic.
revision = 'aeca9fb50cc6'
down_revision = '8d4fe4b497b3'
branch_labels = None
depends_on = None
def get_inv():
INV = context.get_x_argument(as_dictionary=True).get('inventory')
if not INV:
raise ValueError("Inventory value is not specified")
return INV
def upgrade():
# creating placeholder table
# con = op.get_bind()
# sql = f"CREATE SEQUENCE {get_inv()}.placeholder_id_seq START 1;"
# con.execute(sql)
op.create_table(
'placeholder',
sa.Column(
'updated',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column(
'created',
sa.TIMESTAMP(timezone=True),
server_default=sa.text('CURRENT_TIMESTAMP'),
nullable=False,
),
sa.Column('id', sa.BigInteger(), nullable=False),
sa.Column('id_device_supplier', sa.Unicode(), nullable=True),
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()}',
)
def downgrade():
op.drop_table('placeholder', schema=f'{get_inv()}')

View file

@ -793,8 +793,7 @@ class DisplayMixin:
class Placeholder(Thing):
id = Column(BigInteger, Sequence('placeholder_seq'), primary_key=True)
phid = Column(Unicode(), check_lower('phid'), unique=False)
pallet = Column(BigInteger, nullable=True)
pallet = Column(Unicode(), nullable=True)
pallet.comment = "used for identification where from where is this placeholders"
info = db.Column(CIText())
info.comment = "more info of placeholders"
@ -803,29 +802,29 @@ class Placeholder(Thing):
"Identification used for one supplier of one placeholders"
)
placeholder_id = db.Column(
device_id = db.Column(
BigInteger,
db.ForeignKey(Device.id),
nullable=False,
)
placeholder = db.relationship(
device = db.relationship(
Device,
backref=backref('placeholder', lazy=True),
primaryjoin=placeholder_id == Device.id,
backref=backref('placeholder', lazy=True, uselist=False),
primaryjoin=device_id == Device.id,
)
placeholder_id.comment = "datas of the placeholder"
device_id.comment = "datas of the placeholder"
device_id = db.Column(
binding_id = db.Column(
BigInteger,
db.ForeignKey(Device.id),
nullable=True,
)
device = db.relationship(
binding = db.relationship(
Device,
backref=backref('binding', lazy=True),
primaryjoin=placeholder_id == Device.id,
backref=backref('binding', lazy=True, uselist=False),
primaryjoin=binding_id == Device.id,
)
device_id.comment = "device with snapshots than is linked to the placeholder"
binding_id.comment = "device with snapshots than is linked to the placeholder"
class Computer(Device):