devicehubID instead of code
This commit is contained in:
parent
ff964bfe0a
commit
840674e83b
|
@ -33,16 +33,16 @@ def upgrade_data():
|
||||||
for d in devices:
|
for d in devices:
|
||||||
id_dev = d.id
|
id_dev = d.id
|
||||||
code = hashcode(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)
|
con.execute(sql)
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
op.add_column('device', sa.Column('code', citext.CIText(),
|
op.add_column('device', sa.Column('devicehub_id', citext.CIText(),
|
||||||
unique=True,
|
unique=True,
|
||||||
nullable=True), schema=f'{get_inv()}')
|
nullable=True), schema=f'{get_inv()}')
|
||||||
|
|
||||||
upgrade_data()
|
upgrade_data()
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
op.drop_column('device', 'code', schema=f'{get_inv()}')
|
op.drop_column('device', 'devicehub_id', schema=f'{get_inv()}')
|
||||||
|
|
|
@ -123,8 +123,8 @@ class Device(Thing):
|
||||||
owner = db.relationship(User, primaryjoin=owner_id == User.id)
|
owner = db.relationship(User, primaryjoin=owner_id == User.id)
|
||||||
allocated = db.Column(Boolean, default=False)
|
allocated = db.Column(Boolean, default=False)
|
||||||
allocated.comment = "device is allocated or not."
|
allocated.comment = "device is allocated or not."
|
||||||
code = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
|
devicehub_id = db.Column(db.CIText(), nullable=True, unique=True, default=create_code)
|
||||||
code.comment = "device have a unique code."
|
devicehub_id.comment = "device have a unique code."
|
||||||
|
|
||||||
_NON_PHYSICAL_PROPS = {
|
_NON_PHYSICAL_PROPS = {
|
||||||
'id',
|
'id',
|
||||||
|
@ -148,7 +148,7 @@ class Device(Thing):
|
||||||
'sku',
|
'sku',
|
||||||
'image',
|
'image',
|
||||||
'allocated',
|
'allocated',
|
||||||
'code'
|
'devicehub_id'
|
||||||
}
|
}
|
||||||
|
|
||||||
__table_args__ = (
|
__table_args__ = (
|
||||||
|
|
|
@ -66,7 +66,8 @@ class Device(Thing):
|
||||||
sku = SanitizedStr(description=m.Device.sku.comment)
|
sku = SanitizedStr(description=m.Device.sku.comment)
|
||||||
image = URL(description=m.Device.image.comment)
|
image = URL(description=m.Device.image.comment)
|
||||||
allocated = Boolean(description=m.Device.allocated.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
|
@pre_load
|
||||||
def from_actions_to_actions_one(self, data: dict):
|
def from_actions_to_actions_one(self, data: dict):
|
||||||
|
|
Reference in New Issue