diff --git a/api/src/db/migrations/versions/2023_11_27_rename_opportunity_table_prior_to_real_.py b/api/src/db/migrations/versions/2023_11_27_rename_opportunity_table_prior_to_real_.py new file mode 100644 index 000000000..4fd4f6d67 --- /dev/null +++ b/api/src/db/migrations/versions/2023_11_27_rename_opportunity_table_prior_to_real_.py @@ -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 ### diff --git a/api/src/db/models/opportunity_models.py b/api/src/db/models/opportunity_models.py index 828ae4552..a403058c3 100644 --- a/api/src/db/models/opportunity_models.py +++ b/api/src/db/models/opportunity_models.py @@ -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] diff --git a/api/tests/src/adapters/db/type_decorators/test_postgres_type_decorators.py b/api/tests/src/adapters/db/type_decorators/test_postgres_type_decorators.py index 0893ea683..1b7f3c059 100644 --- a/api/tests/src/adapters/db/type_decorators/test_postgres_type_decorators.py +++ b/api/tests/src/adapters/db/type_decorators/test_postgres_type_decorators.py @@ -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