Добавил две таблицы для закрепов
This commit is contained in:
parent
89e66af6cc
commit
b30cf1bae7
3 changed files with 62 additions and 2 deletions
|
@ -9,7 +9,7 @@ sys.path.insert(0, dirname(dirname(abspath(__file__))))
|
|||
|
||||
from app.database import DATABASE_URL, Base
|
||||
from app.users.models import Users, UsersVerificationCodes # noqa
|
||||
from app.users.chat.models import Chats, Messages, UsersXChats # noqa
|
||||
from app.users.chat.models import Chats, Messages, UsersXChats, PinnedMessages, PinnedChats # noqa
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
"""Изменение добавил две таблицы
|
||||
|
||||
Revision ID: 825cf3b8e105
|
||||
Revises: a281bae5bb3f
|
||||
Create Date: 2024-02-27 18:17:26.142169
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '825cf3b8e105'
|
||||
down_revision: Union[str, None] = 'a281bae5bb3f'
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('pinnedchats',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('chat_id', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
op.create_table('pinnedmessages',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||
sa.Column('chat_id', sa.Integer(), nullable=False),
|
||||
sa.Column('message_id', sa.Integer(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('pinnedmessages')
|
||||
op.drop_table('pinnedchats')
|
||||
# ### end Alembic commands ###
|
|
@ -11,10 +11,10 @@ class Chats(Base):
|
|||
__tablename__ = "chats"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
||||
chat_for = mapped_column(ForeignKey("users.id"))
|
||||
chat_name: Mapped[str]
|
||||
visibility: Mapped[bool] = mapped_column(server_default='true')
|
||||
created_by: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
||||
|
||||
message = relationship("Messages", back_populates="chat")
|
||||
usersxchats = relationship("UsersXChats", back_populates="chat")
|
||||
|
@ -55,3 +55,20 @@ class UsersXChats(Base):
|
|||
|
||||
def __str__(self):
|
||||
return f"Юзер #{self.user_id} допущен к чату {self.chat_id}"
|
||||
|
||||
|
||||
class PinnedMessages(Base):
|
||||
__tablename__ = "pinnedmessages"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int]
|
||||
chat_id: Mapped[int]
|
||||
message_id: Mapped[int]
|
||||
|
||||
|
||||
class PinnedChats(Base):
|
||||
__tablename__ = "pinnedchats"
|
||||
|
||||
id: Mapped[int] = mapped_column(primary_key=True)
|
||||
user_id: Mapped[int]
|
||||
chat_id: Mapped[int]
|
||||
|
|
Loading…
Add table
Reference in a new issue