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 #3291] Create database tables for saved opportunities #3325

Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""Create user saved opportunity table

Revision ID: 232a9223ed9b
Revises: 6a23520d2c3c
Create Date: 2024-12-19 22:41:02.487364

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "232a9223ed9b"
down_revision = "f8058a6c0a66"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"user_saved_opportunity",
sa.Column("user_id", sa.UUID(), nullable=False),
sa.Column("opportunity_id", sa.Integer(), 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.ForeignKeyConstraint(
["user_id"], ["api.user.user_id"], name=op.f("user_saved_opportunity_user_id_user_fkey")
),
sa.PrimaryKeyConstraint(
"user_id", "opportunity_id", name=op.f("user_saved_opportunity_pkey")
),
schema="api",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table("user_saved_opportunity", schema="api")
# ### end Alembic commands ###
9 changes: 9 additions & 0 deletions api/src/db/models/user_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,12 @@ class LoginGovState(ApiSchemaTable, TimestampMixin):

# https://openid.net/specs/openid-connect-core-1_0.html#NonceNotes
nonce: Mapped[uuid.UUID]


class UserSavedOpportunity(ApiSchemaTable, TimestampMixin):
__tablename__ = "user_saved_opportunity"

user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey(User.user_id), primary_key=True)
opportunity_id: Mapped[int] = mapped_column(primary_key=True)
mikehgrantsgov marked this conversation as resolved.
Show resolved Hide resolved

user: Mapped[User] = relationship(User)
Binary file modified documentation/api/database/erds/api-schema.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.