Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions fastapi_template/template/hooks/post_gen_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def run_cmd(cmd: str, ignore_error: bool = False):
cprint(out.stdout.decode(errors="replace"), "red")
if out.stderr:
cprint(out.stderr.decode(errors="replace"), "red")
exit(1)
raise ValueError()


def init_repo():
Expand All @@ -102,4 +102,7 @@ def init_repo():
if __name__ == "__main__":
delete_resources_for_disabled_features()
replace_resources()
init_repo()
try:
init_repo()
except ValueError:
pass
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ name = "User models"
enabled = "{{cookiecutter.add_users}}"
resources = [
"{{cookiecutter.project_name}}/web/api/users",
"{{cookiecutter.project_name}}/db_sa/models/users.py"
"{{cookiecutter.project_name}}/db_sa/models/users.py",
"{{cookiecutter.project_name}}/db_sa/migrations/versions/2026-05-05-14-37_8caca4abd7b4.py",
]

[[features]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ lint.ignore = [
"ANN401", # typing.Any are disallowed in `**kwargs
"PLR0913", # Too many arguments for function call
"D106", # Missing docstring in public nested class
"UP043", # Unnecessary default argument specified (conflicts with mypy).
]
exclude = [
{%- if cookiecutter.orm in ["ormar", "sqlalchemy", "piccolo", "tortoise"] %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@ Create Date: ${create_date}
"""
from alembic import op
import sqlalchemy as sa
import fastapi_users_db_sqlalchemy.generics
import fastapi_users_db_sqlalchemy
${imports if imports else ""}


# revision identifiers, used by Alembic.
revision = ${repr(up_revision)}
down_revision = ${repr(down_revision)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def upgrade() -> None:
op.create_table(
"dummy_model",
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
sa.Column("name", sa.String(length=200), nullable=True),
sa.Column("name", sa.String(length=200), nullable=False),
sa.PrimaryKeyConstraint("id"),
)
# ### end Alembic commands ###
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""Added users models.

Revision ID: 8caca4abd7b4
{%- if cookiecutter.add_dummy == 'True' %}
Revises: 2b7380507a71
{%- else %}
Revises: 819cbf6e030b
{%- endif %}
Create Date: 2026-05-05 14:37:30.629187

"""

import sqlalchemy as sa
from alembic import op
import fastapi_users_db_sqlalchemy.generics
import fastapi_users_db_sqlalchemy

# revision identifiers, used by Alembic.
revision = "8caca4abd7b4"
down_revision = "2b7380507a71"
{%- if cookiecutter.add_dummy == 'True' %}
down_revision = "2b7380507a71"
{%- else %}
down_revision = "819cbf6e030b"
{%- endif %}
branch_labels = None
depends_on = None


def upgrade() -> None:
"""Run the migration."""
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"user",
sa.Column("id", fastapi_users_db_sqlalchemy.generics.GUID(), nullable=False),
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.PrimaryKeyConstraint("id"),
)
op.create_index(op.f("ix_user_email"), "user", ["email"], unique=True)
# ### end Alembic commands ###


def downgrade() -> None:
"""Undo the migration."""
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(op.f("ix_user_email"), table_name="user")
op.drop_table("user")
# ### end Alembic commands ###
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# type: ignore
from typing import AsyncGenerator
import uuid

from fastapi import Depends
Expand Down Expand Up @@ -40,7 +40,7 @@ class UserManager(UUIDIDMixin, BaseUserManager[User, uuid.UUID]):
verification_token_secret = settings.users_secret


async def get_user_db(session: AsyncSession = Depends(get_db_session)) -> SQLAlchemyUserDatabase:
async def get_user_db(session: AsyncSession = Depends(get_db_session)) -> AsyncGenerator[SQLAlchemyUserDatabase[User, uuid.UUID], None]:
"""
Yield a SQLAlchemyUserDatabase instance.

Expand All @@ -50,7 +50,7 @@ async def get_user_db(session: AsyncSession = Depends(get_db_session)) -> SQLAlc
yield SQLAlchemyUserDatabase(session, User)


async def get_user_manager(user_db: SQLAlchemyUserDatabase = Depends(get_user_db)) -> UserManager:
async def get_user_manager(user_db: SQLAlchemyUserDatabase[User, uuid.UUID] = Depends(get_user_db)) -> AsyncGenerator[UserManager, None]:
"""
Yield a UserManager instance.

Expand All @@ -60,7 +60,7 @@ async def get_user_manager(user_db: SQLAlchemyUserDatabase = Depends(get_user_db
yield UserManager(user_db)


def get_jwt_strategy() -> JWTStrategy:
def get_jwt_strategy() -> JWTStrategy[User, uuid.UUID]:
"""
Return a JWTStrategy in order to instantiate it dynamically.

Expand Down
Loading