Skip to content

Commit

Permalink
Merge pull request #3501 from HHS/OPS-3500/grants-model-changes
Browse files Browse the repository at this point in the history
feat: add a few new attributes to GrantAgreement
  • Loading branch information
johndeange authored Feb 24, 2025
2 parents 72bc9a5 + 7585d0d commit 35fde62
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""add more attributes to grants
Revision ID: b5d03aa79d12
Revises: 8c9a30d8d6b4
Create Date: 2025-02-20 22:07:01.324115+00:00
"""
from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision: str = 'b5d03aa79d12'
down_revision: Union[str, None] = '8c9a30d8d6b4'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.add_column('grant_agreement', sa.Column('total_funding', sa.Numeric(precision=12, scale=2), nullable=True))
op.add_column('grant_agreement', sa.Column('number_of_years', sa.Integer(), nullable=True))
op.add_column('grant_agreement', sa.Column('number_of_grants', sa.Integer(), nullable=True))
op.alter_column('grant_agreement', 'foa',
existing_type=sa.VARCHAR(),
nullable=True)
op.add_column('grant_agreement_version', sa.Column('total_funding', sa.Numeric(precision=12, scale=2), autoincrement=False, nullable=True))
op.add_column('grant_agreement_version', sa.Column('number_of_years', sa.Integer(), autoincrement=False, nullable=True))
op.add_column('grant_agreement_version', sa.Column('number_of_grants', sa.Integer(), autoincrement=False, nullable=True))
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column('grant_agreement_version', 'number_of_grants')
op.drop_column('grant_agreement_version', 'number_of_years')
op.drop_column('grant_agreement_version', 'total_funding')
op.alter_column('grant_agreement', 'foa',
existing_type=sa.VARCHAR(),
nullable=False)
op.drop_column('grant_agreement', 'number_of_grants')
op.drop_column('grant_agreement', 'number_of_years')
op.drop_column('grant_agreement', 'total_funding')
# ### end Alembic commands ###
8 changes: 6 additions & 2 deletions backend/models/agreements.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
"""Agreement models."""

import decimal
from datetime import date
from enum import Enum, auto
from typing import List, Optional

from sqlalchemy import Boolean, Column, Date, ForeignKey, Integer, String, Table, Text, select
from sqlalchemy import Boolean, Column, Date, ForeignKey, Integer, Numeric, String, Table, Text, select
from sqlalchemy.dialects.postgresql import ENUM
from sqlalchemy.orm import Mapped, mapped_column, object_session, relationship

Expand Down Expand Up @@ -232,7 +233,10 @@ class GrantAgreement(Agreement):
__tablename__ = "grant_agreement"

id: Mapped[int] = mapped_column(ForeignKey("agreement.id"), primary_key=True)
foa: Mapped[str]
foa: Mapped[Optional[str]] = mapped_column(String)
total_funding: Mapped[Optional[decimal]] = mapped_column(Numeric(12, 2))
number_of_years: Mapped[Optional[int]] = mapped_column(Integer)
number_of_grants: Mapped[Optional[int]] = mapped_column(Integer)

__mapper_args__ = {
"polymorphic_identity": AgreementType.GRANT,
Expand Down

0 comments on commit 35fde62

Please sign in to comment.