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 #3546] Add user notification table #3604

Merged
merged 2 commits into from
Jan 23, 2025
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
63 changes: 63 additions & 0 deletions api/src/db/migrations/versions/2025_01_22_notification_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"""notification table

Revision ID: fe052c05c757
Revises: 99bb8e01ad38
Create Date: 2025-01-22 13:01:54.955189

"""

import sqlalchemy as sa
from alembic import op

# revision identifiers, used by Alembic.
revision = "fe052c05c757"
down_revision = "99bb8e01ad38"
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"user_notification_log",
sa.Column("user_notification_log_id", sa.UUID(), nullable=False),
sa.Column("user_id", sa.UUID(), nullable=False),
sa.Column("notification_reason", sa.Text(), nullable=False),
sa.Column("notification_sent", 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.ForeignKeyConstraint(
["user_id"], ["api.user.user_id"], name=op.f("user_notification_log_user_id_user_fkey")
),
sa.PrimaryKeyConstraint(
"user_notification_log_id", name=op.f("user_notification_log_pkey")
),
schema="api",
)
op.create_index(
op.f("user_notification_log_user_id_idx"),
"user_notification_log",
["user_id"],
unique=False,
schema="api",
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("user_notification_log_user_id_idx"), table_name="user_notification_log", schema="api"
)
op.drop_table("user_notification_log", schema="api")
# ### end Alembic commands ###
Empty file.
12 changes: 12 additions & 0 deletions api/src/db/models/user_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,15 @@ class UserSavedSearch(ApiSchemaTable, TimestampMixin):
search_query: Mapped[dict] = mapped_column(JSONB)

name: Mapped[str]


class UserNotificationLog(ApiSchemaTable, TimestampMixin):
__tablename__ = "user_notification_log"

user_notification_log_id: Mapped[uuid.UUID] = mapped_column(UUID, primary_key=True)

user_id: Mapped[uuid.UUID] = mapped_column(ForeignKey(User.user_id), index=True)
user: Mapped[User] = relationship(User)

notification_reason: Mapped[str]
notification_sent: Mapped[bool]
13 changes: 13 additions & 0 deletions api/tests/src/db/models/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,19 @@ class Meta:
email = factory.Faker("email")


class UserNotificationLogFactory(BaseFactory):
class Meta:
model = user_models.UserNotificationLog

user_notification_log_id = Generators.UuidObj

user = factory.SubFactory(UserFactory)
user_id = factory.LazyAttribute(lambda s: s.user.user_id)

notification_reason = "test"
notification_sent = True


class LoginGovStateFactory(BaseFactory):
class Meta:
model = user_models.LoginGovState
Expand Down
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.