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
11 changes: 2 additions & 9 deletions src/fastapi/core_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ fn create_core_utils_file() -> String {

from collections.abc import Callable
from typing import Any
from uuid import uuid4

from fastapi import APIRouter as FastAPIRouter
from fastapi.types import DecoratedCallable
Expand Down Expand Up @@ -200,10 +199,6 @@ class APIRouter(FastAPIRouter):
return add_path(func)

return decorator


def create_db_primary_key() -> str:
return str(uuid4())
"#
.to_string()
}
Expand All @@ -229,7 +224,6 @@ from loguru import logger

from {module}.core.config import settings
from {module}.core.security import get_password_hash
from {module}.core.utils import create_db_primary_key
from {module}.exceptions import NoDbPoolError
from {module}.services.db.user_services import get_user_by_email

Expand Down Expand Up @@ -290,17 +284,16 @@ class Database:
logger.debug(f"User with email {{settings.FIRST_SUPERUSER_EMAIL}} not found, adding")
query = """
INSERT INTO users (
id, email, full_name, hashed_password, is_active, is_superuser
email, full_name, hashed_password, is_active, is_superuser
)
VALUES ($1, $2, $3, $4, $5, $6)
VALUES ($1, $2, $3, $4, $5)
"""

hashed_password = get_password_hash(settings.FIRST_SUPERUSER_PASSWORD.get_secret_value())
async with self.db_pool.acquire() as conn:
try:
await conn.execute(
query,
create_db_primary_key(),
settings.FIRST_SUPERUSER_EMAIL,
settings.FIRST_SUPERUSER_NAME,
hashed_password,
Expand Down
3 changes: 1 addition & 2 deletions src/fastapi/docker_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn create_dockercompose_file(project_info: &ProjectInfo) -> String {
- traefik.http.routers.${{STACK_NAME?Variable not set}}-backend-https.middlewares=${{STACK_NAME?Variable not set}}-api-rate-limit,${{STACK_NAME?Variable not set}}-security-headers

db:
image: postgres:17-alpine
image: postgres:18-alpine
restart: unless-stopped
container_name: {base_name}-db
healthcheck:
Expand All @@ -84,7 +84,6 @@ fn create_dockercompose_file(project_info: &ProjectInfo) -> String {
env_file:
- .env
environment:
- PGDATA=/var/lib/postgresql/data/pgdata
- POSTGRES_PASSWORD=${{POSTGRES_PASSWORD?Variable not set}}
- POSTGRES_USER=${{POSTGRES_USER?Variable not set}}
- POSTGRES_DB=${{POSTGRES_DB?Variable not set}}
Expand Down
2 changes: 1 addition & 1 deletion src/fastapi/migration_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::{file_manager::save_file_with_content, project_info::ProjectInfo};

fn create_initial_up_migration() -> String {
r#"CREATE TABLE IF NOT EXISTS users (
id TEXT PRIMARY KEY,
id UUID DEFAULT uuidv7() PRIMARY KEY,
email TEXT NOT NULL UNIQUE,
full_name TEXT NOT NULL,
hashed_password TEXT NOT NULL,
Expand Down
25 changes: 11 additions & 14 deletions src/fastapi/service_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ from typing import TYPE_CHECKING
from loguru import logger

from {module}.core.security import get_password_hash, verify_password
from {module}.core.utils import create_db_primary_key
from {module}.exceptions import DbInsertError, DbUpdateError, UserNotFoundError
from {module}.models.users import (
UpdatePassword,
Expand Down Expand Up @@ -127,16 +126,15 @@ async def authenticate(*, pool: Pool, email: str, password: str) -> UserInDb | N
async def create_user(*, pool: Pool, cache_client: Valkey, user: UserCreate) -> UserInDb:
query = """
INSERT INTO users (
id,
email,
full_name,
hashed_password,
is_active,
is_superuser
)
VALUES ($1, $2, $3, $4, $5, $6)
VALUES ($1, $2, $3, $4, $5)
RETURNING
id,
id::text,
email,
full_name,
hashed_password,
Expand All @@ -148,7 +146,6 @@ async def create_user(*, pool: Pool, cache_client: Valkey, user: UserCreate) ->
async with pool.acquire() as conn:
result = await conn.fetchrow(
query,
create_db_primary_key(),
user.email,
user.full_name,
get_password_hash(user.password),
Expand All @@ -167,7 +164,7 @@ async def create_user(*, pool: Pool, cache_client: Valkey, user: UserCreate) ->


async def delete_user(*, pool: Pool, cache_client: Valkey, user_id: str) -> None:
query = "DELETE FROM users WHERE id = $1"
query = "DELETE FROM users WHERE id::text = $1"
async with pool.acquire() as conn:
async with asyncio.TaskGroup() as tg:
db_task = tg.create_task(conn.execute(query, user_id))
Expand All @@ -183,7 +180,7 @@ async def delete_user(*, pool: Pool, cache_client: Valkey, user_id: str) -> None

async def get_users(*, pool: Pool, offset: int = 0, limit: int = 100) -> list[UserInDb] | None:
query = """
SELECT id,
SELECT id::text,
email,
full_name,
hashed_password,
Expand Down Expand Up @@ -241,7 +238,7 @@ async def get_users_public(

async def get_user_by_email(*, pool: Pool, email: str) -> UserInDb | None:
query = """
SELECT id,
SELECT id::text,
email,
full_name,
hashed_password,
Expand Down Expand Up @@ -278,15 +275,15 @@ async def get_user_by_id(*, pool: Pool, cache_client: Valkey, user_id: str) -> U
return cached_user

query = """
SELECT id,
SELECT id::text,
email,
full_name,
hashed_password,
is_active,
is_superuser,
last_login
FROM users
WHERE id = $1
WHERE id::text = $1
"""

async with pool.acquire() as conn:
Expand Down Expand Up @@ -341,9 +338,9 @@ async def update_user(
query = """
UPDATE users
SET hashed_password=$1
WHERE id = $2
WHERE id::text = $2
RETURNING
id,
id::text,
email,
full_name,
hashed_password,
Expand Down Expand Up @@ -373,9 +370,9 @@ async def update_user(
query = f"""
UPDATE users
SET {{set_clause}}
WHERE id = $1
WHERE id::text = $1
RETURNING
id,
id::text,
email,
full_name,
hashed_password,
Expand Down