From dad54ec1398b15183088a28e16f2be852a6653f6 Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Thu, 26 Dec 2019 16:27:52 -0500 Subject: [PATCH] Create new migration to convert column type of defense_component from string to array --- ...6f_update_portfolios_defense_component_.py | 36 +++++++++++++++++++ atst/models/portfolio.py | 3 +- templates/portfolios/admin.html | 4 +-- translations.yaml | 1 + 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 alembic/versions/02ac8bdcf16f_update_portfolios_defense_component_.py diff --git a/alembic/versions/02ac8bdcf16f_update_portfolios_defense_component_.py b/alembic/versions/02ac8bdcf16f_update_portfolios_defense_component_.py new file mode 100644 index 00000000..8d202c57 --- /dev/null +++ b/alembic/versions/02ac8bdcf16f_update_portfolios_defense_component_.py @@ -0,0 +1,36 @@ +"""update portfolios defense component column type + +Revision ID: 02ac8bdcf16f +Revises: 08f2a640e9c2 +Create Date: 2019-12-26 16:10:54.366461 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '02ac8bdcf16f' # pragma: allowlist secret +down_revision = '08f2a640e9c2' # pragma: allowlist secret +branch_labels = None +depends_on = None + + +def upgrade(): + ### commands auto generated by Alembic - please adjust! ### + op.alter_column('portfolios', 'defense_component', + type_=postgresql.ARRAY(sa.VARCHAR()), + existing_type=sa.VARCHAR(), + postgresql_using="string_to_array(defense_component, ',')::character varying[]", + nullable=False) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.alter_column('portfolios', 'defense_component', + type_=sa.VARCHAR(), + existing_type=postgresql.ARRAY(sa.VARCHAR()), + postgresql_using="defense_component[1]::character varying", + nullable=False) + # ### end Alembic commands ### diff --git a/atst/models/portfolio.py b/atst/models/portfolio.py index 8cfc35d6..0e48745b 100644 --- a/atst/models/portfolio.py +++ b/atst/models/portfolio.py @@ -1,5 +1,6 @@ from sqlalchemy import Column, String from sqlalchemy.orm import relationship +from sqlalchemy.types import ARRAY from itertools import chain from atst.models.base import Base @@ -20,7 +21,7 @@ class Portfolio( name = Column(String, nullable=False) description = Column(String) defense_component = Column( - String, nullable=False + ARRAY(String), nullable=False ) # Department of Defense Component applications = relationship( diff --git a/templates/portfolios/admin.html b/templates/portfolios/admin.html index d1e6e353..b7796315 100644 --- a/templates/portfolios/admin.html +++ b/templates/portfolios/admin.html @@ -41,9 +41,9 @@
-
{{ "forms.task_order.defense_component_label" | translate }}
+
{{ "portfolios.admin.defense_component_label" | translate }}
{% if portfolio.defense_component %} -
{{ portfolio.defense_component }}
+
{{ "forms.portfolio.defense_component.choices.%s" | format(portfolio.defense_component) | translate }}
{% else %}
{{ "fragments.portfolio_admin.none" | translate }}
{% endif %} diff --git a/translations.yaml b/translations.yaml index e25078a6..a9407720 100644 --- a/translations.yaml +++ b/translations.yaml @@ -310,6 +310,7 @@ portfolios: alert_header: Are you sure you want to delete this member? alert_message: 'The member will be removed from the portfolio, but their log history will be retained.' alert_title: Warning! You are about to delete a member from the portfolio. + defense_component_label: Department of Defense Component no_members: There are currently no members in this portfolio. permissions_info: Learn more about these permissions portfolio_members_subheading: These members have different levels of access to the portfolio.