diff --git a/gso/migrations/versions/2025-04-10_c38adde1a18e_update_wf_in_process_table.py b/gso/migrations/versions/2025-04-10_c38adde1a18e_update_wf_in_process_table.py index d2dc29f8274715a35195c039041abf76de981916..005d1f1824cd8b6f183ef627d23e39fd41cfae73 100644 --- a/gso/migrations/versions/2025-04-10_c38adde1a18e_update_wf_in_process_table.py +++ b/gso/migrations/versions/2025-04-10_c38adde1a18e_update_wf_in_process_table.py @@ -1,4 +1,4 @@ -"""Update wf in process table and delete old workflows +"""Update workflows in process table and delete old processes and workflows Revision ID: c38adde1a18e Revises: 9fbb3c4411ea @@ -85,7 +85,49 @@ WHERE pr.pid = ps.pid for mapping in update_mappings: conn.execute(sa.text(sql_template), mapping) + # Delete input states referencing to orphaned workflows. + conn.execute( + sa.text( + """ +DELETE FROM input_states +WHERE input_states.pid IN (SELECT p.pid + FROM processes p + JOIN workflows w + ON p.workflow_id = w.workflow_id + JOIN processes_subscriptions ps + ON ps.pid = p.pid + JOIN subscriptions s + ON s.subscription_id = ps.subscription_id + JOIN products pro + ON s.product_id = pro.product_id + WHERE w."name" = 'validate_prefix_list' + AND pro."name" != 'GÉANT IP'); + """ + ) + ) + + # Delete processes refering to orphaned workflows. + conn.execute( + sa.text( + """ +DELETE FROM processes +WHERE processes.pid IN (SELECT p.pid + FROM processes p + JOIN workflows w + ON p.workflow_id = w.workflow_id + JOIN processes_subscriptions ps + ON ps.pid = p.pid + JOIN subscriptions s + ON s.subscription_id = ps.subscription_id + JOIN products pro + ON s.product_id = pro.product_id + WHERE w."name" = 'validate_prefix_list' + AND pro."name" != 'GÉANT IP'); + """ + ) + ) + # Delete workflows for products that no longer exist. conn.execute( sa.text( """ diff --git a/gso/migrations/versions/2025-04-18_fffe36624681_update_ip_trunk_descriptions.py b/gso/migrations/versions/2025-04-18_fffe36624681_update_ip_trunk_descriptions.py new file mode 100644 index 0000000000000000000000000000000000000000..4402b1ef376d441a9e093a4a466c63aeed44501d --- /dev/null +++ b/gso/migrations/versions/2025-04-18_fffe36624681_update_ip_trunk_descriptions.py @@ -0,0 +1,38 @@ +"""Update IP Trunk descriptions. + +Removes an outdated to `geant_s_sid` in IP Trunk descriptions. This field has been renamed and adds unnecessary clutter +to the description field. + +Revision ID: fffe36624681 +Revises: c38adde1a18e +Create Date: 2025-04-18 09:41:28.463681 + +""" +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision = 'fffe36624681' +down_revision = 'c38adde1a18e' +branch_labels = None +depends_on = None + + +def upgrade() -> None: + conn = op.get_bind() + conn.execute( + sa.text( + """ +UPDATE subscriptions +SET description = Replace(description, 'geant_s_sid:', '') +WHERE product_id = (SELECT product_id + FROM products p + WHERE p.tag = 'IPTRUNK'); + """ + ) + ) + + +def downgrade() -> None: + # Do nothing + pass