Create new migration to convert column type of defense_component from

string to array
This commit is contained in:
leigh-mil 2019-12-26 16:27:52 -05:00
parent d0fd7126be
commit dad54ec139
4 changed files with 41 additions and 3 deletions

View File

@ -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 ###

View File

@ -1,5 +1,6 @@
from sqlalchemy import Column, String from sqlalchemy import Column, String
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
from sqlalchemy.types import ARRAY
from itertools import chain from itertools import chain
from atst.models.base import Base from atst.models.base import Base
@ -20,7 +21,7 @@ class Portfolio(
name = Column(String, nullable=False) name = Column(String, nullable=False)
description = Column(String) description = Column(String)
defense_component = Column( defense_component = Column(
String, nullable=False ARRAY(String), nullable=False
) # Department of Defense Component ) # Department of Defense Component
applications = relationship( applications = relationship(

View File

@ -41,9 +41,9 @@
<div class='defense-row'> <div class='defense-row'>
<div> <div>
<div class='admin-title'>{{ "forms.task_order.defense_component_label" | translate }}</div> <div class='admin-title'>{{ "portfolios.admin.defense_component_label" | translate }}</div>
{% if portfolio.defense_component %} {% if portfolio.defense_component %}
<div class='admin-content'>{{ portfolio.defense_component }}</div> <div class='admin-content'>{{ "forms.portfolio.defense_component.choices.%s" | format(portfolio.defense_component) | translate }}</div>
{% else %} {% else %}
<div class='admin-content'>{{ "fragments.portfolio_admin.none" | translate }}</div> <div class='admin-content'>{{ "fragments.portfolio_admin.none" | translate }}</div>
{% endif %} {% endif %}

View File

@ -310,6 +310,7 @@ portfolios:
alert_header: Are you sure you want to delete this member? 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_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. 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. no_members: There are currently no members in this portfolio.
permissions_info: Learn more about these permissions permissions_info: Learn more about these permissions
portfolio_members_subheading: These members have different levels of access to the portfolio. portfolio_members_subheading: These members have different levels of access to the portfolio.