From 840674e83b923cbcf42aa6f4afe89f42af04dfe5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 8 Mar 2021 19:09:12 +0100 Subject: [PATCH] devicehubID instead of code --- .../migrations/versions/8cb91ad1cc40_add_code_to_device.py | 6 +++--- ereuse_devicehub/resources/device/models.py | 6 +++--- ereuse_devicehub/resources/device/schemas.py | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py b/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py index bd1e0494..3501450f 100644 --- a/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py +++ b/ereuse_devicehub/migrations/versions/8cb91ad1cc40_add_code_to_device.py @@ -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()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 77f5ae8d..2b1a7ea7 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -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__ = ( diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 4fc818ea..9a97d72d 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -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):