Skip to content

Commit

Permalink
Migration
Browse files Browse the repository at this point in the history
  • Loading branch information
rmarow committed Oct 15, 2024
1 parent bb74b2d commit ce44834
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
24 changes: 24 additions & 0 deletions deploy/post/v2.4.0
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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 ###

0 comments on commit ce44834

Please sign in to comment.