From d5e93f3a52d76251cbce6767c74184646b9e422b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 Jul 2023 09:36:33 +0200 Subject: [PATCH] add solar panel module and migration --- .../versions/8ccba3cb37c2_add_solar_panel.py | 41 +++++++++++++++++++ ereuse_devicehub/resources/device/models.py | 11 ++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py diff --git a/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py b/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py new file mode 100644 index 00000000..f5dc87df --- /dev/null +++ b/ereuse_devicehub/migrations/versions/8ccba3cb37c2_add_solar_panel.py @@ -0,0 +1,41 @@ +"""add solar panel + +Revision ID: 8ccba3cb37c2 +Revises: 5169765e2653 +Create Date: 2023-07-26 09:23:21.326465 + +""" +import sqlalchemy as sa +from alembic import context, op + +# revision identifiers, used by Alembic. +revision = '8ccba3cb37c2' +down_revision = '5169765e2653' +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 Solar panel device. + + op.create_table( + 'solar_panel', + sa.Column('id', sa.BigInteger(), nullable=False), + sa.ForeignKeyConstraint( + ['id'], + [f'{get_inv()}.device.id'], + ), + sa.PrimaryKeyConstraint('id'), + schema=f'{get_inv()}', + ) + + +def downgrade(): + op.drop_table('solar_panel', schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index ca7ea9be..593ce4e3 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -476,7 +476,8 @@ class Device(Thing): """The trading state, or None if no Trade action has ever been performed to this device. This extract the posibilities for to do. This method is performed for show in the web. - If you need to do one simple and generic response you can put simple=True for that.""" + If you need to do one simple and generic response you can put simple=True for that. + """ if not hasattr(lot, 'trade'): return @@ -1986,3 +1987,11 @@ class Other(Device): """ id = Column(BigInteger, ForeignKey(Device.id), primary_key=True) + + +class SolarPanel(Device): + """ + Used solar panels devices. + """ + + id = Column(BigInteger, ForeignKey(Device.id), primary_key=True)