update alembic
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
from typing import Annotated, AsyncGenerator
|
||||
|
||||
from fastapi import Depends
|
||||
from fastapi_users_db_sqlalchemy import SQLAlchemyUserDatabase
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from src.db.database import async_session_maker
|
||||
from src.models import UsersORM
|
||||
|
||||
|
||||
async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
@@ -16,5 +14,3 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
||||
DBDep = Annotated[AsyncSession, Depends(get_db)]
|
||||
|
||||
|
||||
async def get_user_db(session: DBDep):
|
||||
yield SQLAlchemyUserDatabase(session, UsersORM)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""init
|
||||
|
||||
Revision ID: 932121e6b220
|
||||
Revision ID: a2fdd0ec4a96
|
||||
Revises:
|
||||
Create Date: 2025-06-22 11:52:49.691545
|
||||
Create Date: 2025-07-06 00:02:09.254907
|
||||
|
||||
"""
|
||||
from typing import Sequence, Union
|
||||
@@ -11,7 +11,8 @@ from alembic import op
|
||||
import sqlalchemy as sa
|
||||
|
||||
|
||||
revision: str = '932121e6b220'
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = 'a2fdd0ec4a96'
|
||||
down_revision: Union[str, None] = None
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
@@ -19,20 +20,20 @@ depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
def upgrade() -> None:
|
||||
"""Upgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.create_table('users',
|
||||
sa.Column('id', sa.Integer(), nullable=False),
|
||||
sa.Column('username', sa.String(length=30), nullable=False),
|
||||
sa.Column('hashed_password', sa.String(length=255), nullable=False),
|
||||
sa.Column('email', sa.String(length=255), nullable=True),
|
||||
sa.Column('telegram_id', sa.BigInteger(), nullable=True),
|
||||
sa.Column('avatar_path', sa.String(length=255), nullable=True),
|
||||
sa.Column('email', sa.String(length=320), nullable=False),
|
||||
sa.Column('hashed_password', sa.String(length=1024), nullable=False),
|
||||
sa.Column('is_active', sa.Boolean(), nullable=False),
|
||||
sa.Column('is_superuser', sa.Boolean(), nullable=False),
|
||||
sa.Column('is_verified', sa.Boolean(), nullable=False),
|
||||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
sa.PrimaryKeyConstraint('id'),
|
||||
sa.UniqueConstraint('email')
|
||||
)
|
||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
||||
op.create_index(op.f('ix_users_username'), 'users', ['username'], unique=True)
|
||||
op.create_table('tasks',
|
||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||
@@ -41,19 +42,19 @@ def upgrade() -> None:
|
||||
sa.Column('description', sa.Text(), nullable=True),
|
||||
sa.Column('due_date', sa.Date(), nullable=True),
|
||||
sa.Column('status', sa.Enum('open', 'closed', 'in_progress', 'todo', name='status_enum'), nullable=False),
|
||||
sa.CheckConstraint("status IN ('open', 'closed', 'in_progress', 'todo')", name="ck_status_enum"),
|
||||
sa.Column('priority', sa.Enum('low', 'medium', 'high', 'critical', name='priority_enum'), nullable=False),
|
||||
sa.CheckConstraint("priority in ('low', 'medium', 'high', 'critical')", name='ck_priority_enum'),
|
||||
sa.Column('time_spent', sa.Integer(), nullable=False),
|
||||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||
sa.PrimaryKeyConstraint('id')
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_table('tasks')
|
||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
||||
op.drop_table('users')
|
||||
# ### end Alembic commands ###
|
||||
@@ -25,4 +25,4 @@ class TasksORM(Base):
|
||||
priority: Mapped[str] = mapped_column(priority_enum, default="medium")
|
||||
time_spent: Mapped[int] = mapped_column(default=0)
|
||||
|
||||
user: Mapped["Users"] = relationship(back_populates="tasks")
|
||||
user: Mapped["UsersORM"] = relationship(back_populates="tasks")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
from typing import Optional, TYPE_CHECKING
|
||||
|
||||
from fastapi_users_db_sqlalchemy import SQLAlchemyBaseUserTable
|
||||
from sqlalchemy import String, BigInteger, Integer
|
||||
from sqlalchemy import String, BigInteger, Integer, Boolean, VARCHAR
|
||||
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
||||
|
||||
from src.db.database import Base
|
||||
@@ -10,13 +9,16 @@ if TYPE_CHECKING:
|
||||
from src.models.tasks import TasksORM
|
||||
|
||||
|
||||
class UsersORM(SQLAlchemyBaseUserTable[int], Base):
|
||||
class UsersORM(Base):
|
||||
__tablename__ = "users"
|
||||
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||
username: Mapped[Optional[str]] = mapped_column(
|
||||
username: Mapped[str] = mapped_column(
|
||||
String(30), nullable=False, unique=True, index=True
|
||||
)
|
||||
hashed_password: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||
email: Mapped[Optional[str]] = mapped_column(String(255), unique=True, nullable=True)
|
||||
telegram_id: Mapped[Optional[int]] = mapped_column(BigInteger, nullable=True)
|
||||
avatar_path: Mapped[Optional[str]] = mapped_column(String(255), nullable=True)
|
||||
|
||||
is_active: Mapped[bool] = mapped_column(Boolean, nullable=False, default=True)
|
||||
is_superuser: Mapped[bool] = mapped_column(Boolean, nullable=False, default=False)
|
||||
tasks: Mapped[list["TasksORM"]] = relationship(back_populates="user")
|
||||
|
||||
Reference in New Issue
Block a user