-
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.
Add /messages/{message_id}/emoji endpoint to toggle, add, remove mess…
…age emojis (#925) * add endpoint to set message emojis * make refresh result optional in db utils
- Loading branch information
1 parent
4146930
commit 558b207
Showing
10 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
backend/alembic/versions/2023_01_24_2256-40ed93df0ed5_add_message_emoji.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,44 @@ | ||
"""add message_emoji | ||
Revision ID: 40ed93df0ed5 | ||
Revises: 8ba17b5f467a | ||
Create Date: 2023-01-24 22:56:28.229408 | ||
""" | ||
import sqlalchemy as sa | ||
import sqlmodel | ||
from alembic import op | ||
from sqlalchemy.dialects import postgresql | ||
|
||
# revision identifiers, used by Alembic. | ||
revision = "40ed93df0ed5" | ||
down_revision = "8ba17b5f467a" | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table( | ||
"message_emoji", | ||
sa.Column("message_id", postgresql.UUID(as_uuid=True), nullable=False), | ||
sa.Column("user_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("emoji", sqlmodel.sql.sqltypes.AutoString(length=128), nullable=False), | ||
sa.ForeignKeyConstraint(["message_id"], ["message.id"], ondelete="CASCADE"), | ||
sa.ForeignKeyConstraint(["user_id"], ["user.id"], ondelete="CASCADE"), | ||
sa.PrimaryKeyConstraint("message_id", "user_id", "emoji"), | ||
) | ||
op.create_index("ix_message_emoji__user_id__message_id", "message_emoji", ["user_id", "message_id"], unique=False) | ||
op.add_column("message", sa.Column("emojis", postgresql.JSONB(astext_type=sa.Text()), nullable=True)) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_column("message", "emojis") | ||
op.drop_index("ix_message_emoji__user_id__message_id", table_name="message_emoji") | ||
op.drop_table("message_emoji") | ||
# ### 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
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,27 @@ | ||
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, Index, SQLModel | ||
|
||
|
||
class MessageEmoji(SQLModel, table=True): | ||
__tablename__ = "message_emoji" | ||
__table_args__ = (Index("ix_message_emoji__user_id__message_id", "user_id", "message_id", unique=False),) | ||
|
||
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 | ||
) | ||
) | ||
user_id: UUID = Field( | ||
sa_column=sa.Column( | ||
pg.UUID(as_uuid=True), sa.ForeignKey("user.id", ondelete="CASCADE"), nullable=False, primary_key=True | ||
) | ||
) | ||
emoji: str = Field(nullable=False, max_length=128, primary_key=True) | ||
created_date: Optional[datetime] = Field( | ||
sa_column=sa.Column(sa.DateTime(timezone=True), nullable=False, server_default=sa.func.current_timestamp()) | ||
) |
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
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