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)