Skip to content

Commit

Permalink
Merge pull request #341 from nsidc/SBA-update
Browse files Browse the repository at this point in the history
Sba update
  • Loading branch information
rmarow authored Oct 15, 2024
2 parents 8665772 + 13eaa0f commit bbb4fbf
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 508 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## v2.4.0 (2024-10-11)

* Update SBA framework
* Multiple DB migrations (final migration (ce8e6e308e5c))
* No longer prefill information
* Add fields for framework information
* Allow linking between observation system and application nodes

## v2.3.0 (2024-10-02)
Expand Down
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 [ "ce8e6e308e5c (head)" = "${current}" ]; then
echo "Data migration successful. On expected revision ${current}."
else
echo "Data migration failed. On unexpected revision ${current}."
fi
53 changes: 53 additions & 0 deletions migrations/versions/b9357b81d2b0_add_new_sba_related_fields.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
"""Add new SBA related fields.
Revision ID: b9357b81d2b0
Revises: ea1181510e10
Create Date: 2024-10-14 22:37:03.652801
"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'b9357b81d2b0'
down_revision: str | None = 'ea1181510e10'
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.add_column(
'node_subtype_societal_benefit_area',
sa.Column('name', sa.String(length=512), nullable=True),
)
op.add_column(
'node_subtype_societal_benefit_area',
sa.Column('short_name', sa.String(length=256), nullable=True),
)
op.add_column(
'node_subtype_societal_benefit_area',
sa.Column('description', sa.String(), nullable=True),
)
op.add_column(
'node_subtype_societal_benefit_area',
sa.Column('framework_name', sa.String(length=256), nullable=True),
)
op.add_column(
'node_subtype_societal_benefit_area',
sa.Column('framework_url', sa.String(length=512), nullable=True),
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('node_subtype_societal_benefit_area', 'framework_url')
op.drop_column('node_subtype_societal_benefit_area', 'framework_name')
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')
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""remove prefilled sba reference tables.
Revision ID: ce8e6e308e5c
Revises: d46c4d798847
Create Date: 2024-10-15 23:03:00.302098
"""

from collections.abc import Sequence

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'ce8e6e308e5c'
down_revision: str | None = 'd46c4d798847'
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_table('societal_benefit_key_objective')
op.drop_table('societal_benefit_subarea')
op.drop_table('societal_benefit_area')
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
'societal_benefit_area',
sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False),
sa.PrimaryKeyConstraint('id', name='pk_societal_benefit_area'),
postgresql_ignore_search_path=False,
)
op.create_table(
'societal_benefit_subarea',
sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False),
sa.Column(
'societal_benefit_area_id',
sa.VARCHAR(length=256),
autoincrement=False,
nullable=False,
),
sa.ForeignKeyConstraint(
['societal_benefit_area_id'],
['societal_benefit_area.id'],
name='fk_societal_benefit_subarea_societal_benefit_area_id_so_0d93',
),
sa.PrimaryKeyConstraint('id', name='pk_societal_benefit_subarea'),
postgresql_ignore_search_path=False,
)
op.create_table(
'societal_benefit_key_objective',
sa.Column('id', sa.VARCHAR(length=256), autoincrement=False, nullable=False),
sa.Column(
'societal_benefit_subarea_id',
sa.VARCHAR(length=256),
autoincrement=False,
nullable=False,
),
sa.ForeignKeyConstraint(
['societal_benefit_subarea_id'],
['societal_benefit_subarea.id'],
name='fk_societal_benefit_key_objective_societal_benefit_suba_8857',
),
sa.PrimaryKeyConstraint(
'id',
'societal_benefit_subarea_id',
name='pk_societal_benefit_key_objective',
),
)
# ### end Alembic commands ###
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 ###
Loading

0 comments on commit bbb4fbf

Please sign in to comment.