Изменения БД
This commit is contained in:
parent
e6d6421f01
commit
f13e18a27e
6 changed files with 58 additions and 17 deletions
|
@ -1,8 +1,8 @@
|
|||
"""Убрал обязательность авы
|
||||
"""Изменение models.py
|
||||
|
||||
Revision ID: 6d13086c9c2d
|
||||
Revises: 2913a8a70afb
|
||||
Create Date: 2024-02-03 13:12:24.466115
|
||||
Revision ID: 8b2764a42ee6
|
||||
Revises: dd610307d6a0
|
||||
Create Date: 2024-02-09 12:59:20.127130
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
@ -12,19 +12,19 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '6d13086c9c2d'
|
||||
down_revision: Union[str, None] = '2913a8a70afb'
|
||||
revision: str = '8b2764a42ee6'
|
||||
down_revision: Union[str, None] = 'dd610307d6a0'
|
||||
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! ###
|
||||
pass
|
||||
op.add_column('users', sa.Column('date_of_registration', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
pass
|
||||
op.drop_column('users', 'date_of_registration')
|
||||
# ### end Alembic commands ###
|
|
@ -0,0 +1,38 @@
|
|||
"""Изменение models.py
|
||||
|
||||
Revision ID: ae1bfb8ea886
|
||||
Revises: 8b2764a42ee6
|
||||
Create Date: 2024-02-09 13:18:35.765055
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'ae1bfb8ea886'
|
||||
down_revision: Union[str, None] = '8b2764a42ee6'
|
||||
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.alter_column('users', 'date_of_registration',
|
||||
existing_type=postgresql.TIMESTAMP(timezone=True),
|
||||
type_=sa.Date(),
|
||||
existing_nullable=False,
|
||||
existing_server_default=sa.text('now()'))
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.alter_column('users', 'date_of_registration',
|
||||
existing_type=sa.Date(),
|
||||
type_=postgresql.TIMESTAMP(timezone=True),
|
||||
existing_nullable=False,
|
||||
existing_server_default=sa.text('now()'))
|
||||
# ### end Alembic commands ###
|
|
@ -1,8 +1,8 @@
|
|||
"""Изменение models.py
|
||||
|
||||
Revision ID: 2913a8a70afb
|
||||
Revision ID: dd610307d6a0
|
||||
Revises:
|
||||
Create Date: 2024-02-01 14:31:04.662656
|
||||
Create Date: 2024-02-09 12:49:56.643283
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
|
@ -12,7 +12,7 @@ import sqlalchemy as sa
|
|||
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = '2913a8a70afb'
|
||||
revision: str = 'dd610307d6a0'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
@ -26,8 +26,8 @@ def upgrade() -> None:
|
|||
sa.Column('username', sa.String(), nullable=False),
|
||||
sa.Column('hashed_password', sa.String(), nullable=False),
|
||||
sa.Column('role', sa.Integer(), nullable=False),
|
||||
sa.Column('black_phoenix', sa.Integer(), nullable=False),
|
||||
sa.Column('avatar_image', sa.String(), server_default='app/static/images/ту уже пешка BP.png', nullable=True),
|
||||
sa.Column('black_phoenix', sa.Boolean(), nullable=False),
|
||||
sa.Column('avatar_image', sa.String(), server_default='app/static/images/ты уже пешка BP.png', nullable=True),
|
||||
sa.Column('date_of_birth', sa.Date(), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
|
@ -1,6 +1,7 @@
|
|||
from datetime import date
|
||||
from datetime import date, datetime
|
||||
from typing import Optional
|
||||
|
||||
from sqlalchemy import DateTime, func
|
||||
from sqlalchemy.orm import mapped_column, Mapped, relationship
|
||||
|
||||
from app.database import Base
|
||||
|
@ -14,9 +15,10 @@ class Users(Base):
|
|||
username: Mapped[str]
|
||||
hashed_password: Mapped[str]
|
||||
role: Mapped[int]
|
||||
black_phoenix: Mapped[int] # Заменить на bool
|
||||
black_phoenix: Mapped[bool]
|
||||
avatar_image: Mapped[Optional[str]] = mapped_column(server_default='app/static/images/ты уже пешка BP.png')
|
||||
date_of_birth: Mapped[date]
|
||||
date_of_registration: Mapped[date] = mapped_column(server_default=func.now())
|
||||
|
||||
message = relationship("Messages", back_populates="user")
|
||||
usersxchats = relationship("UsersXChats", back_populates="user")
|
||||
|
|
|
@ -43,7 +43,7 @@ async def register_user(response: Response, user_data: SUserRegister):
|
|||
username=user_data.username,
|
||||
date_of_birth=user_data.date_of_birth,
|
||||
role=0,
|
||||
black_phoenix=0
|
||||
black_phoenix=False
|
||||
)
|
||||
user = await authenticate_user_by_email(user_data.email, user_data.password)
|
||||
access_token = create_access_token({"sub": str(user.id)})
|
||||
|
|
|
@ -21,8 +21,9 @@ class SUser(BaseModel):
|
|||
id: int
|
||||
username: str
|
||||
avatar_image: str
|
||||
black_phoenix: int
|
||||
black_phoenix: bool
|
||||
date_of_birth: date
|
||||
date_of_registration: date
|
||||
|
||||
class Config:
|
||||
from_attributes = True
|
||||
|
|
Loading…
Add table
Reference in a new issue