devicehubID instead of code

This commit is contained in:
Cayo Puigdefabregas 2021-03-08 19:09:12 +01:00
parent ff964bfe0a
commit 840674e83b
3 changed files with 8 additions and 7 deletions

View File

@ -33,16 +33,16 @@ def upgrade_data():
for d in devices:
id_dev = d.id
code = hashcode(d.id)
sql = f"update {get_inv()}.device set code='{code}' where id={id_dev};"
sql = f"update {get_inv()}.device set devicehub_id='{code}' where id={id_dev};"
con.execute(sql)
def upgrade():
op.add_column('device', sa.Column('code', citext.CIText(),
op.add_column('device', sa.Column('devicehub_id', citext.CIText(),
unique=True,
nullable=True), schema=f'{get_inv()}')
upgrade_data()
def downgrade():
op.drop_column('device', 'code', schema=f'{get_inv()}')
op.drop_column('device', 'devicehub_id', schema=f'{get_inv()}')

View File

@ -123,8 +123,8 @@ class Device(Thing):
owner = db.relationship(User, primaryjoin=owner_id == User.id)
allocated = db.Column(Boolean, default=False)
allocated.comment = "device is allocated or not."
code = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
code.comment = "device have a unique code."
devicehub_id = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
devicehub_id.comment = "device have a unique code."
_NON_PHYSICAL_PROPS = {
'id',
@ -148,7 +148,7 @@ class Device(Thing):
'sku',
'image',
'allocated',
'code'
'devicehub_id'
}
__table_args__ = (

View File

@ -66,7 +66,8 @@ class Device(Thing):
sku = SanitizedStr(description=m.Device.sku.comment)
image = URL(description=m.Device.image.comment)
allocated = Boolean(description=m.Device.allocated.comment)
code = SanitizedStr(description=m.Device.code.comment)
devicehub_id = SanitizedStr(data_key='devicehubID',
description=m.Device.devicehub_id.comment)
@pre_load
def from_actions_to_actions_one(self, data: dict):