diff --git a/deploy/post/v2.4.0 b/deploy/post/v2.4.0 new file mode 100755 index 00000000..cc1dd6e2 --- /dev/null +++ b/deploy/post/v2.4.0 @@ -0,0 +1,24 @@ +#!/bin/bash + +set -euo pipefail + +# HACK: Garrison doesn't see these variables that were exported in main deploy +# script, which is unintuitive. NOTE that sourcing VERSION.env is not +# compatible with integration, but this script doesn't receive the environment +# as a parameter. Garrison needs some extra thought here. +source /etc/profile.d/envvars.sh +source VERSION.env + +# TODO: figure out better way +echo "Waiting 10 seconds for the new stack to come up..." +sleep 10 + +docker compose run --rm usaon-benefit-tool alembic upgrade head + +# confirm the expected migration was applied +current=$(docker compose run --rm usaon-benefit-tool alembic current 2>/dev/null) +if [ "d46c4d798847 (head)" = "${current}" ]; then + echo "Data migration successful. On expected revision ${current}." +else + echo "Data migration failed. On unexpected revision ${current}." +fi diff --git a/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py b/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py new file mode 100644 index 00000000..619c7dc3 --- /dev/null +++ b/migrations/versions/d46c4d798847_remove_sba_foreign_key_relationship.py @@ -0,0 +1,80 @@ +"""Remove SBA foreign key relationship. + +Revision ID: d46c4d798847 +Revises: b9357b81d2b0 +Create Date: 2024-10-15 22:10:15.917116 + +""" + +from collections.abc import Sequence + +import sqlalchemy as sa +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = 'd46c4d798847' +down_revision: str | None = 'b9357b81d2b0' +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + 'uq_node_subtype_societal_benefit_area_societal_benefit_area_id', + 'node_subtype_societal_benefit_area', + type_='unique', + ) + op.drop_constraint( + 'fk_node_subtype_societal_benefit_area_societal_benefit__adfa', + 'node_subtype_societal_benefit_area', + type_='foreignkey', + ) + op.drop_column('node_subtype_societal_benefit_area', 'description') + op.drop_column('node_subtype_societal_benefit_area', 'short_name') + op.drop_column('node_subtype_societal_benefit_area', 'name') + op.drop_column('node_subtype_societal_benefit_area', 'societal_benefit_area_id') + # ### end Alembic commands ### + + +def downgrade() -> None: + # ### commands auto generated by Alembic - please adjust! ### + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column( + 'societal_benefit_area_id', + sa.VARCHAR(), + autoincrement=False, + nullable=False, + ), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('name', sa.VARCHAR(length=512), autoincrement=False, nullable=True), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column( + 'short_name', + sa.VARCHAR(length=256), + autoincrement=False, + nullable=True, + ), + ) + op.add_column( + 'node_subtype_societal_benefit_area', + sa.Column('description', sa.VARCHAR(), autoincrement=False, nullable=True), + ) + op.create_foreign_key( + 'fk_node_subtype_societal_benefit_area_societal_benefit__adfa', + 'node_subtype_societal_benefit_area', + 'societal_benefit_area', + ['societal_benefit_area_id'], + ['id'], + ) + op.create_unique_constraint( + 'uq_node_subtype_societal_benefit_area_societal_benefit_area_id', + 'node_subtype_societal_benefit_area', + ['societal_benefit_area_id'], + ) + # ### end Alembic commands ###