diff --git a/src/fastapi/core_files.rs b/src/fastapi/core_files.rs index 210b7398..f2fc5a15 100644 --- a/src/fastapi/core_files.rs +++ b/src/fastapi/core_files.rs @@ -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 @@ -200,10 +199,6 @@ class APIRouter(FastAPIRouter): return add_path(func) return decorator - - -def create_db_primary_key() -> str: - return str(uuid4()) "# .to_string() } @@ -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 @@ -290,9 +284,9 @@ 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()) @@ -300,7 +294,6 @@ class Database: try: await conn.execute( query, - create_db_primary_key(), settings.FIRST_SUPERUSER_EMAIL, settings.FIRST_SUPERUSER_NAME, hashed_password, diff --git a/src/fastapi/docker_files.rs b/src/fastapi/docker_files.rs index d7b35065..920662b4 100644 --- a/src/fastapi/docker_files.rs +++ b/src/fastapi/docker_files.rs @@ -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: @@ -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}} diff --git a/src/fastapi/migration_files.rs b/src/fastapi/migration_files.rs index d79b1fe4..ece1a7f6 100644 --- a/src/fastapi/migration_files.rs +++ b/src/fastapi/migration_files.rs @@ -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, diff --git a/src/fastapi/service_files.rs b/src/fastapi/service_files.rs index 96328f4e..ea61667f 100644 --- a/src/fastapi/service_files.rs +++ b/src/fastapi/service_files.rs @@ -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, @@ -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, @@ -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), @@ -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)) @@ -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, @@ -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, @@ -278,7 +275,7 @@ 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, @@ -286,7 +283,7 @@ async def get_user_by_id(*, pool: Pool, cache_client: Valkey, user_id: str) -> U is_superuser, last_login FROM users - WHERE id = $1 + WHERE id::text = $1 """ async with pool.acquire() as conn: @@ -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, @@ -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,