Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Issue 698] Add rest of opportunity table columns #863

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-erd-diagrams.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ concurrency:


jobs:
update-openapi-docs:
update-database-erd:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
"""add rest of opportunity table

Revision ID: 83964e6715a1
Revises: dec1422eee27
Create Date: 2023-12-11 13:13:33.446941

"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "83964e6715a1"
down_revision = "dec1422eee27"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.add_column("opportunity", sa.Column("category_explanation", sa.Text(), nullable=True))
op.add_column("opportunity", sa.Column("revision_number", sa.Integer(), nullable=True))
op.add_column("opportunity", sa.Column("modified_comments", sa.Text(), nullable=True))
op.add_column("opportunity", sa.Column("publisher_user_id", sa.Integer(), nullable=True))
op.add_column("opportunity", sa.Column("publisher_profile_id", sa.Integer(), nullable=True))
op.create_index(op.f("opportunity_category_idx"), "opportunity", ["category"], unique=False)
op.create_index(op.f("opportunity_is_draft_idx"), "opportunity", ["is_draft"], unique=False)
op.create_index(
op.f("opportunity_opportunity_title_idx"),
"opportunity",
["opportunity_title"],
unique=False,
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("opportunity_opportunity_title_idx"), table_name="opportunity")
op.drop_index(op.f("opportunity_is_draft_idx"), table_name="opportunity")
op.drop_index(op.f("opportunity_category_idx"), table_name="opportunity")
op.drop_column("opportunity", "publisher_profile_id")
op.drop_column("opportunity", "publisher_user_id")
op.drop_column("opportunity", "modified_comments")
op.drop_column("opportunity", "revision_number")
op.drop_column("opportunity", "category_explanation")
# ### end Alembic commands ###
25 changes: 22 additions & 3 deletions api/src/db/models/opportunity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,29 @@ class Opportunity(Base, TimestampMixin):
opportunity_id: Mapped[int] = mapped_column(primary_key=True)

opportunity_number: Mapped[str | None]
opportunity_title: Mapped[str | None]
opportunity_title: Mapped[str | None] = mapped_column(index=True)

agency: Mapped[str | None]

category: Mapped[OpportunityCategory | None] = mapped_column(StrEnumColumn(OpportunityCategory))
category: Mapped[OpportunityCategory | None] = mapped_column(
StrEnumColumn(OpportunityCategory), index=True
)
category_explanation: Mapped[str | None]

is_draft: Mapped[bool]
is_draft: Mapped[bool] = mapped_column(index=True)

revision_number: Mapped[int | None]
modified_comments: Mapped[str | None]

# These presumably refer to the TUSER_ACCOUNT, and TUSER_PROFILE tables
# although the legacy DB does not have them setup as foreign keys
publisher_user_id: Mapped[int | None]
publisher_profile_id: Mapped[int | None]

"""
Not ported over from legacy system

listed CHAR(1) - everything in the existing system is set to "L" for listed, so not any value
initial_opportunity_id NUMBER(20) - existing docs say this field isn't used
flag_2006 CHAR(1) (boolean) - a flag for presumably a prior migration, no use to us
"""
6 changes: 6 additions & 0 deletions api/tests/src/db/models/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ class Meta:

opportunity_number = factory.Sequence(lambda n: f"ABC-{n}-XYZ-001")
opportunity_title = factory.LazyFunction(lambda: f"Research into {fake.job()} industry")

agency = factory.Iterator(["US-ABC", "US-XYZ", "US-123"])

category = factory.fuzzy.FuzzyChoice(OpportunityCategory)
category_explanation = factory.Sequence(lambda n: f"Category as chosen by order #{n * n - 1}")

is_draft = False # Because we filter out drafts, just default these to False

revision_number = 0 # We'll want to consider how we handle this when we add history
Binary file modified documentation/api/database/erds/full-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.