-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
968 add flagged message table and endpoints (#1325)
* Added flagged message table * Added alembic migration and updated imports to match style * Added GET endpoint to query all flagged messages * Updates from linter * Added POST endpoint for processing flagged messages * Added pydantic interface model and fixed limit update bug * fixed session in admin endpoint and added require session refresh for returned update * removed unused import
- Loading branch information
1 parent
1153734
commit 66b7ed2
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
41 changes: 41 additions & 0 deletions
41
...end/alembic/versions/2023_02_07_1922-caee1e8ee0bc_added_new_table_for_flagged_messages.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Added new table for flagged messages | ||
Revision ID: caee1e8ee0bc | ||
Revises: 8c8241d1f973 | ||
Create Date: 2023-02-07 19:22:12.696257 | ||
""" | ||
import sqlalchemy as sa | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "caee1e8ee0bc" | ||
down_revision = "8c8241d1f973" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"flagged_message", | ||
sa.Column("message_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column( | ||
"created_date", sa.DateTime(timezone=True), server_default=sa.text("CURRENT_TIMESTAMP"), nullable=False | ||
), | ||
sa.Column("processed", sa.Boolean(), nullable=False), | ||
sa.ForeignKeyConstraint(["message_id"], ["message.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("message_id"), | ||
) | ||
op.create_index(op.f("ix_flagged_message_created_date"), "flagged_message", ["created_date"], unique=False) | ||
op.create_index(op.f("ix_flagged_message_processed"), "flagged_message", ["processed"], unique=False) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_index(op.f("ix_flagged_message_processed"), table_name="flagged_message") | ||
op.drop_index(op.f("ix_flagged_message_created_date"), table_name="flagged_message") | ||
op.drop_table("flagged_message") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
from uuid import UUID | ||
|
||
import sqlalchemy as sa | ||
import sqlalchemy.dialects.postgresql as pg | ||
from sqlmodel import Field, SQLModel | ||
|
||
|
||
class FlaggedMessage(SQLModel, table=True): | ||
__tablename__ = "flagged_message" | ||
|
||
message_id: Optional[UUID] = Field( | ||
sa_column=sa.Column( | ||
pg.UUID(as_uuid=True), sa.ForeignKey("message.id", ondelete="CASCADE"), nullable=False, primary_key=True | ||
) | ||
) | ||
processed: bool = Field(nullable=False, index=True) | ||
created_date: Optional[datetime] = Field( | ||
sa_column=sa.Column( | ||
sa.DateTime(timezone=True), nullable=False, server_default=sa.func.current_timestamp(), index=True | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters