From b9f3d5976b69e09c200ae2df3e4e16ed0dd918dc Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 3 Feb 2021 22:28:04 +0100 Subject: [PATCH] drop ethereum_address of deliverynote --- .../eca457d8b2a4_change_deliverynote.py | 34 +++++++++++++++++++ .../resources/deliverynote/models.py | 1 - .../resources/deliverynote/schemas.py | 1 - .../resources/deliverynote/views.py | 3 +- 4 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py diff --git a/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py new file mode 100644 index 00000000..6cd89970 --- /dev/null +++ b/ereuse_devicehub/migrations/versions/eca457d8b2a4_change_deliverynote.py @@ -0,0 +1,34 @@ +"""change deliverynote + +Revision ID: eca457d8b2a4 +Revises: 0cbd839b09ef +Create Date: 2021-02-03 22:12:41.033661 + +""" +from alembic import context +from alembic import op +import sqlalchemy as sa +import sqlalchemy_utils +import citext +import teal + + +# revision identifiers, used by Alembic. +revision = 'eca457d8b2a4' +down_revision = '0cbd839b09ef' +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(): + op.drop_column('deliverynote', 'ethereum_address', schema=f'{get_inv()}') + + +def downgrade(): + op.add_column('deliverynote', sa.Column('ethereum_address', citext.CIText(), nullable=True), schema=f'{get_inv()}') diff --git a/ereuse_devicehub/resources/deliverynote/models.py b/ereuse_devicehub/resources/deliverynote/models.py index 9896ab50..e791f450 100644 --- a/ereuse_devicehub/resources/deliverynote/models.py +++ b/ereuse_devicehub/resources/deliverynote/models.py @@ -46,7 +46,6 @@ class Deliverynote(Thing): transferred_devices = db.Column(db.ARRAY(db.Integer, dimensions=1), nullable=True) transfer_state = db.Column(IntEnum(TransferState), default=TransferState.Initial, nullable=False) transfer_state.comment = TransferState.__doc__ - ethereum_address = db.Column(CIText(), unique=True, default=None) lot_id = db.Column(UUID(as_uuid=True), db.ForeignKey(Lot.id), nullable=False) diff --git a/ereuse_devicehub/resources/deliverynote/schemas.py b/ereuse_devicehub/resources/deliverynote/schemas.py index 58808f6d..60854991 100644 --- a/ereuse_devicehub/resources/deliverynote/schemas.py +++ b/ereuse_devicehub/resources/deliverynote/schemas.py @@ -21,7 +21,6 @@ class Deliverynote(Thing): date = f.DateTime('iso', required=True) deposit = f.Integer(validate=f.validate.Range(min=0, max=100), description=m.Deliverynote.deposit.__doc__) - ethereum_address = f.String(description='User identifier address inside the Blockchain') expected_devices = f.List(f.Dict, required=True, data_key='expectedDevices') transferred_devices = f.List(f.Integer(), required=False, data_key='transferredDevices') transfer_state = EnumField(TransferState, description=m.Lot.transfer_state.comment) diff --git a/ereuse_devicehub/resources/deliverynote/views.py b/ereuse_devicehub/resources/deliverynote/views.py index b9650b98..6d895259 100644 --- a/ereuse_devicehub/resources/deliverynote/views.py +++ b/ereuse_devicehub/resources/deliverynote/views.py @@ -28,8 +28,7 @@ class DeliverynoteView(View): return ret def patch(self, id): - patch_schema = self.resource_def.SCHEMA(only=('transfer_state', - 'ethereum_address'), partial=True) + patch_schema = self.resource_def.SCHEMA(only=('transfer_state'), partial=True) d = request.get_json(schema=patch_schema) dlvnote = Deliverynote.query.filter_by(id=id).one() # device_fields = ['transfer_state', 'deliverynote_address']