Skip to content

Commit

Permalink
Rename opportunity table to use our naming schema (#767)
Browse files Browse the repository at this point in the history
  • Loading branch information
chouinar authored Dec 11, 2023
1 parent 7359080 commit fff0fcf
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""rename opportunity table prior to real usage
Revision ID: dec1422eee27
Revises: fdd9312633d8
Create Date: 2023-11-27 14:43:04.227044
"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.dialects import postgresql

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


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"opportunity",
sa.Column("opportunity_id", sa.Integer(), nullable=False),
sa.Column("opportunity_number", sa.Text(), nullable=True),
sa.Column("opportunity_title", sa.Text(), nullable=True),
sa.Column("agency", sa.Text(), nullable=True),
sa.Column("category", sa.Text(), nullable=True),
sa.Column("is_draft", sa.Boolean(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.PrimaryKeyConstraint("opportunity_id", name=op.f("opportunity_pkey")),
)
op.drop_table("topportunity")
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"topportunity",
sa.Column("opportunity_id", sa.INTEGER(), autoincrement=True, nullable=False),
sa.Column("oppnumber", sa.TEXT(), autoincrement=False, nullable=True),
sa.Column("opptitle", sa.TEXT(), autoincrement=False, nullable=True),
sa.Column("owningagency", sa.TEXT(), autoincrement=False, nullable=True),
sa.Column("oppcategory", sa.TEXT(), autoincrement=False, nullable=True),
sa.Column("is_draft", sa.BOOLEAN(), autoincrement=False, nullable=False),
sa.Column(
"created_at",
postgresql.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.Column(
"updated_at",
postgresql.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
autoincrement=False,
nullable=False,
),
sa.PrimaryKeyConstraint("opportunity_id", name="topportunity_pkey"),
)
op.drop_table("opportunity")
# ### end Alembic commands ###
21 changes: 7 additions & 14 deletions api/src/db/models/opportunity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,15 @@


class Opportunity(Base, TimestampMixin):
# NOTE: Keeping all names lower-case versions of the Oracle DBs naming
# to follow the usual convention of Postgres.
# names are automatically lowercased in all queries unless you quote them.
# Once we've setup the replicated DB, we can adjust the naming here if needed.
__tablename__ = "opportunity"

__tablename__ = "topportunity"
opportunity_id: Mapped[int] = mapped_column(primary_key=True)

opportunity_id: Mapped[int] = mapped_column("opportunity_id", primary_key=True)
opportunity_number: Mapped[str | None]
opportunity_title: Mapped[str | None]

opportunity_number: Mapped[str | None] = mapped_column("oppnumber")
opportunity_title: Mapped[str | None] = mapped_column("opptitle")
agency: Mapped[str | None]

agency: Mapped[str | None] = mapped_column("owningagency")
category: Mapped[OpportunityCategory | None] = mapped_column(StrEnumColumn(OpportunityCategory))

category: Mapped[OpportunityCategory | None] = mapped_column(
"oppcategory", StrEnumColumn(OpportunityCategory)
)

is_draft: Mapped[bool] = mapped_column("is_draft")
is_draft: Mapped[bool]
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_str_enum_column_conversion(db_session, enable_factory_create, category,
# Verify what we stored in the DB is the string itself
raw_db_value = db_session.execute(
text(
f"select oppcategory from {Opportunity.get_table_name()} where opportunity_id={opportunity.opportunity_id}" # nosec
f"select category from {Opportunity.get_table_name()} where opportunity_id={opportunity.opportunity_id}" # nosec
)
).scalar()
assert raw_db_value == db_value
Expand Down

0 comments on commit fff0fcf

Please sign in to comment.