ruff formatter
This commit is contained in:
@@ -18,14 +18,12 @@ async def get_db() -> AsyncGenerator[AsyncSession, None]:
|
|||||||
DBDep = Annotated[AsyncSession, Depends(get_db)]
|
DBDep = Annotated[AsyncSession, Depends(get_db)]
|
||||||
|
|
||||||
|
|
||||||
async def get_user_db(
|
async def get_user_db(session: DBDep):
|
||||||
session: DBDep
|
|
||||||
):
|
|
||||||
yield SQLAlchemyUserDatabase(session, UsersORM)
|
yield SQLAlchemyUserDatabase(session, UsersORM)
|
||||||
|
|
||||||
|
|
||||||
async def get_access_token_db(
|
async def get_access_token_db(
|
||||||
session: DBDep,
|
session: DBDep,
|
||||||
):
|
):
|
||||||
yield SQLAlchemyAccessTokenDatabase(session, AccessToken)
|
yield SQLAlchemyAccessTokenDatabase(session, AccessToken)
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ from src.settings import settings
|
|||||||
|
|
||||||
|
|
||||||
def get_database_strategy(
|
def get_database_strategy(
|
||||||
access_token_db: AccessTokenDatabase[AccessToken] = Depends(get_access_token_db),
|
access_token_db: AccessTokenDatabase[AccessToken] = Depends(get_access_token_db),
|
||||||
) -> DatabaseStrategy:
|
) -> DatabaseStrategy:
|
||||||
return DatabaseStrategy(access_token_db, lifetime_seconds=settings.lifetime)
|
return DatabaseStrategy(access_token_db, lifetime_seconds=settings.lifetime)
|
||||||
|
|
||||||
@@ -18,4 +18,4 @@ auth_backend = AuthenticationBackend(
|
|||||||
name="database",
|
name="database",
|
||||||
transport=bearer_transport,
|
transport=bearer_transport,
|
||||||
get_strategy=get_database_strategy,
|
get_strategy=get_database_strategy,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from sqlalchemy import pool
|
|||||||
from alembic import context
|
from alembic import context
|
||||||
|
|
||||||
from src.db.database import Base
|
from src.db.database import Base
|
||||||
from src.models import * # noqa
|
from src.models import * # noqa
|
||||||
|
|
||||||
# this is the Alembic Config object, which provides
|
# this is the Alembic Config object, which provides
|
||||||
# access to the values within the .ini file in use.
|
# access to the values within the .ini file in use.
|
||||||
@@ -68,9 +68,7 @@ def run_migrations_online() -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
with connectable.connect() as connection:
|
with connectable.connect() as connection:
|
||||||
context.configure(
|
context.configure(connection=connection, target_metadata=target_metadata)
|
||||||
connection=connection, target_metadata=target_metadata
|
|
||||||
)
|
|
||||||
|
|
||||||
with context.begin_transaction():
|
with context.begin_transaction():
|
||||||
context.run_migrations()
|
context.run_migrations()
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
"""init
|
"""init
|
||||||
|
|
||||||
Revision ID: 932121e6b220
|
Revision ID: 932121e6b220
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2025-06-22 11:52:49.691545
|
Create Date: 2025-06-22 11:52:49.691545
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
|
||||||
from alembic import op
|
from alembic import op
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
revision: str = '932121e6b220'
|
revision: str = "932121e6b220"
|
||||||
down_revision: Union[str, None] = None
|
down_revision: Union[str, None] = None
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
@@ -19,41 +20,68 @@ depends_on: Union[str, Sequence[str], None] = None
|
|||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema."""
|
"""Upgrade schema."""
|
||||||
op.create_table('users',
|
op.create_table(
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
"users",
|
||||||
sa.Column('username', sa.String(length=30), nullable=False),
|
sa.Column("id", sa.Integer(), nullable=False),
|
||||||
sa.Column('telegram_id', sa.BigInteger(), nullable=True),
|
sa.Column("username", sa.String(length=30), nullable=False),
|
||||||
sa.Column('avatar_path', sa.String(length=255), nullable=True),
|
sa.Column("telegram_id", sa.BigInteger(), nullable=True),
|
||||||
sa.Column('email', sa.String(length=320), nullable=False),
|
sa.Column("avatar_path", sa.String(length=255), nullable=True),
|
||||||
sa.Column('hashed_password', sa.String(length=1024), nullable=False),
|
sa.Column("email", sa.String(length=320), nullable=False),
|
||||||
sa.Column('is_active', sa.Boolean(), nullable=False),
|
sa.Column("hashed_password", sa.String(length=1024), nullable=False),
|
||||||
sa.Column('is_superuser', sa.Boolean(), nullable=False),
|
sa.Column("is_active", sa.Boolean(), nullable=False),
|
||||||
sa.Column('is_verified', sa.Boolean(), nullable=False),
|
sa.Column("is_superuser", sa.Boolean(), nullable=False),
|
||||||
sa.Column('created_at', sa.TIMESTAMP(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
|
sa.Column("is_verified", sa.Boolean(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.Column(
|
||||||
|
"created_at",
|
||||||
|
sa.TIMESTAMP(timezone=True),
|
||||||
|
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
sa.PrimaryKeyConstraint("id"),
|
||||||
)
|
)
|
||||||
op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
|
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_index(op.f("ix_users_username"), "users", ["username"], unique=True)
|
||||||
op.create_table('tasks',
|
op.create_table(
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
"tasks",
|
||||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.Column('title', sa.String(length=100), nullable=False),
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
sa.Column('description', sa.Text(), nullable=True),
|
sa.Column("title", sa.String(length=100), nullable=False),
|
||||||
sa.Column('due_date', sa.Date(), nullable=True),
|
sa.Column("description", sa.Text(), nullable=True),
|
||||||
sa.Column('status', sa.Enum('open', 'closed', 'in_progress', 'todo', name='status_enum'), nullable=False),
|
sa.Column("due_date", sa.Date(), nullable=True),
|
||||||
sa.CheckConstraint("status IN ('open', 'closed', 'in_progress', 'todo')", name="ck_status_enum"),
|
sa.Column(
|
||||||
sa.Column('priority', sa.Enum('low', 'medium', 'high', 'critical', name='priority_enum'), nullable=False),
|
"status",
|
||||||
sa.CheckConstraint("priority in ('low', 'medium', 'high', 'critical')", name='ck_priority_enum'),
|
sa.Enum("open", "closed", "in_progress", "todo", name="status_enum"),
|
||||||
sa.Column('time_spent', sa.Integer(), nullable=False),
|
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.CheckConstraint(
|
||||||
sa.PrimaryKeyConstraint('id')
|
"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"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema."""
|
"""Downgrade schema."""
|
||||||
op.drop_table('tasks')
|
op.drop_table("tasks")
|
||||||
op.drop_index(op.f('ix_users_username'), table_name='users')
|
op.drop_index(op.f("ix_users_username"), table_name="users")
|
||||||
op.drop_index(op.f('ix_users_email'), table_name='users')
|
op.drop_index(op.f("ix_users_email"), table_name="users")
|
||||||
op.drop_table('users')
|
op.drop_table("users")
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ Revises: 932121e6b220
|
|||||||
Create Date: 2025-06-22 12:11:19.223212
|
Create Date: 2025-06-22 12:11:19.223212
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from typing import Sequence, Union
|
from typing import Sequence, Union
|
||||||
|
|
||||||
import fastapi_users_db_sqlalchemy
|
import fastapi_users_db_sqlalchemy
|
||||||
@@ -12,25 +13,32 @@ from alembic import op
|
|||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
revision: str = 'bc0bdd74718c'
|
revision: str = "bc0bdd74718c"
|
||||||
down_revision: Union[str, None] = '932121e6b220'
|
down_revision: Union[str, None] = "932121e6b220"
|
||||||
branch_labels: Union[str, Sequence[str], None] = None
|
branch_labels: Union[str, Sequence[str], None] = None
|
||||||
depends_on: Union[str, Sequence[str], None] = None
|
depends_on: Union[str, Sequence[str], None] = None
|
||||||
|
|
||||||
|
|
||||||
def upgrade() -> None:
|
def upgrade() -> None:
|
||||||
"""Upgrade schema."""
|
"""Upgrade schema."""
|
||||||
op.create_table('accesstoken',
|
op.create_table(
|
||||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
"accesstoken",
|
||||||
sa.Column('token', sa.String(length=43), nullable=False),
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
||||||
sa.Column('created_at', fastapi_users_db_sqlalchemy.generics.TIMESTAMPAware(timezone=True), nullable=False),
|
sa.Column("token", sa.String(length=43), nullable=False),
|
||||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ondelete='cascade'),
|
sa.Column(
|
||||||
sa.PrimaryKeyConstraint('token')
|
"created_at",
|
||||||
|
fastapi_users_db_sqlalchemy.generics.TIMESTAMPAware(timezone=True),
|
||||||
|
nullable=False,
|
||||||
|
),
|
||||||
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="cascade"),
|
||||||
|
sa.PrimaryKeyConstraint("token"),
|
||||||
|
)
|
||||||
|
op.create_index(
|
||||||
|
op.f("ix_accesstoken_created_at"), "accesstoken", ["created_at"], unique=False
|
||||||
)
|
)
|
||||||
op.create_index(op.f('ix_accesstoken_created_at'), 'accesstoken', ['created_at'], unique=False)
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade() -> None:
|
def downgrade() -> None:
|
||||||
"""Downgrade schema."""
|
"""Downgrade schema."""
|
||||||
op.drop_index(op.f('ix_accesstoken_created_at'), table_name='accesstoken')
|
op.drop_index(op.f("ix_accesstoken_created_at"), table_name="accesstoken")
|
||||||
op.drop_table('accesstoken')
|
op.drop_table("accesstoken")
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ priority_enum = Enum("low", "medium", "high", "critical", name="priority_enum")
|
|||||||
|
|
||||||
|
|
||||||
class TasksORM(Base):
|
class TasksORM(Base):
|
||||||
|
|
||||||
__tablename__ = "tasks"
|
__tablename__ = "tasks"
|
||||||
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
||||||
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
user_id: Mapped[int] = mapped_column(ForeignKey("users.id"))
|
||||||
@@ -25,4 +24,4 @@ class TasksORM(Base):
|
|||||||
priority: Mapped[str] = mapped_column(priority_enum, default="medium")
|
priority: Mapped[str] = mapped_column(priority_enum, default="medium")
|
||||||
time_spent: Mapped[int] = mapped_column(default=0)
|
time_spent: Mapped[int] = mapped_column(default=0)
|
||||||
|
|
||||||
user: Mapped["Users"] = relationship(back_populates="tasks")
|
user: Mapped["UsersORM"] = relationship(back_populates="tasks")
|
||||||
|
|||||||
@@ -8,4 +8,6 @@ from src.db.database import Base
|
|||||||
class AccessToken(SQLAlchemyBaseAccessTokenTable[int], Base):
|
class AccessToken(SQLAlchemyBaseAccessTokenTable[int], Base):
|
||||||
@declared_attr
|
@declared_attr
|
||||||
def user_id(cls) -> Mapped[int]:
|
def user_id(cls) -> Mapped[int]:
|
||||||
return mapped_column(Integer, ForeignKey("users.id", ondelete="cascade"), nullable=False)
|
return mapped_column(
|
||||||
|
Integer, ForeignKey("users.id", ondelete="cascade"), nullable=False
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ from pydantic_settings import BaseSettings, SettingsConfigDict
|
|||||||
|
|
||||||
|
|
||||||
class Settings(BaseSettings):
|
class Settings(BaseSettings):
|
||||||
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
|
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
|
||||||
LIFETIME: int
|
LIFETIME: int
|
||||||
SECRET: str
|
SECRET: str
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user