This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/migrations/versions/968b79fa7756_upgrade_confir...

52 lines
1.5 KiB
Python
Raw Permalink Normal View History

"""upgrade confirmrevoke
Revision ID: 968b79fa7756
Revises: d22d230d2850
Create Date: 2021-11-12 19:18:39.135386
"""
from alembic import op
from alembic import context
import sqlalchemy as sa
import sqlalchemy_utils
import citext
2023-03-21 16:31:43 +00:00
from ereuse_devicehub import teal
# revision identifiers, used by Alembic.
revision = '968b79fa7756'
down_revision = 'd22d230d2850'
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
2023-03-21 16:31:43 +00:00
def upgrade():
con = op.get_bind()
confirmsRevokes_sql = f"select * from {get_inv()}.action as action join {get_inv()}.confirm as confirm on action.id=confirm.id where action.type='ConfirmRevoke'"
revokes_sql = f"select confirm.id, confirm.action_id from {get_inv()}.action as action join {get_inv()}.confirm as confirm on action.id=confirm.id where action.type='Revoke'"
confirmsRevokes = [a for a in con.execute(confirmsRevokes_sql)]
revokes = {ac.id: ac.action_id for ac in con.execute(revokes_sql)}
for ac in confirmsRevokes:
ac_id = ac.id
revoke_id = ac.action_id
trade_id = revokes[revoke_id]
2021-11-12 21:24:23 +00:00
sql_action = f"update {get_inv()}.action set type='Revoke' where id='{ac_id}'"
2023-03-21 16:31:43 +00:00
sql_confirm = (
f"update {get_inv()}.confirm set action_id='{trade_id}' where id='{ac_id}'"
)
con.execute(sql_action)
con.execute(sql_confirm)
def downgrade():
pass