Skip to content

Commit

Permalink
[Issue #1752] Small fixes to the database schema (#1788)
Browse files Browse the repository at this point in the history
## Summary
Fixes #1752

### Time to review: __3 mins__

## Changes proposed
Two minor adjustments to the db schema:
* Fixed the type of the revision number in the opportunity table (should
be an integer not a string)
* Added version_number, a missing column to the opportunity summary
table

## Additional information
Was able to load in data to the tables and run `make db-migrate` and
`make db-migrate-down` uneventfully.
  • Loading branch information
chouinar authored Apr 19, 2024
1 parent 18bf809 commit 143e3dc
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""fix column type and add version number
Revision ID: c6878bae0c60
Revises: b26ea0f40066
Create Date: 2024-04-19 13:41:34.017203
"""
import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "c6878bae0c60"
down_revision = "b26ea0f40066"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column(
"opportunity",
"revision_number",
existing_type=sa.TEXT(),
type_=sa.Integer(),
existing_nullable=True,
postgresql_using="revision_number::integer",
schema="api",
)
op.add_column(
"opportunity_summary",
sa.Column("version_number", sa.Integer(), nullable=True),
schema="api",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("opportunity_summary", "version_number", schema="api")
op.alter_column(
"opportunity",
"revision_number",
existing_type=sa.Integer(),
type_=sa.TEXT(),
existing_nullable=True,
postgresql_using="revision_number::TEXT",
schema="api",
)
# ### end Alembic commands ###
3 changes: 2 additions & 1 deletion api/src/db/models/opportunity_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Opportunity(ApiSchemaTable, TimestampMixin):

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

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

# These presumably refer to the TUSER_ACCOUNT, and TUSER_PROFILE tables
Expand Down Expand Up @@ -136,6 +136,7 @@ class OpportunitySummary(ApiSchemaTable, TimestampMixin):

is_deleted: Mapped[bool | None]

version_number: Mapped[int | None]
can_send_mail: Mapped[bool | None]
publisher_profile_id: Mapped[int | None] = mapped_column(BigInteger)
publisher_user_id: Mapped[str | None]
Expand Down
3 changes: 2 additions & 1 deletion api/tests/src/db/models/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,8 @@ class Meta:

is_deleted = False

revision_number = 1
# Generally, current summaries won't have the revision number set
revision_number = None

funding_instruments = factory.Faker(
"random_elements",
Expand Down

0 comments on commit 143e3dc

Please sign in to comment.