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
6 changes: 2 additions & 4 deletions {{cookiecutter.repo_name}}/migrations/env.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from logging.config import fileConfig

from sqlalchemy import engine_from_config
from sqlalchemy import pool

from alembic import context
from sqlalchemy import engine_from_config, pool
from {{cookiecutter.module_name}}.models.base import Base
from {{cookiecutter.module_name}}.settings import get_settings

Expand Down Expand Up @@ -61,7 +59,7 @@ def run_migrations_online():

"""
configuration = config.get_section(config.config_ini_section)
configuration['sqlalchemy.url'] = settings.DB_DSN
configuration['sqlalchemy.url'] = str(settings.DB_DSN)
connectable = engine_from_config(
configuration,
prefix="sqlalchemy.",
Expand Down
1 change: 1 addition & 0 deletions {{cookiecutter.repo_name}}/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ gunicorn
logging-profcomff
psycopg2-binary
pydantic[dotenv]
pydantic-settings
SQLAlchemy
uvicorn
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import os

__version__ = os.getenv('APP_VERSION', 'dev')
__version__ = os.getenv("APP_VERSION", "dev")
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import uvicorn

from {{cookiecutter.module_name}}.routes.base import app


if __name__ == '__main__':
uvicorn.run(app)
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ def __repr__(self) -> str:
attrs = []
for c in self.__table__.columns:
attrs.append(f"{c.name}={getattr(self, c.name)}")
return "{}({})".format(self.__class__.__name__, ', '.join(attrs))
return "{}({})".format(self.__class__.__name__, ", ".join(attrs))
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

app.add_middleware(
DBSessionMiddleware,
db_url=settings.DB_DSN,
db_url=str(settings.DB_DSN),
engine_args={"pool_pre_ping": True, "isolation_level": "AUTOCOMMIT"},
)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict


class Base(BaseModel):
def __repr__(self) -> str:
attrs = []
for k, v in self.__class__.schema().items():
attrs.append(f"{k}={v}")
return "{}({})".format(self.__class__.__name__, ', '.join(attrs))
return "{}({})".format(self.__class__.__name__, ", ".join(attrs))

class Config:
orm_mode = True
model_config = ConfigDict(from_attributes=True, extra="ignore")
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
import os
from functools import lru_cache

from pydantic import BaseSettings, PostgresDsn
from pydantic import ConfigDict, PostgresDsn
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
"""Application settings"""

DB_DSN: PostgresDsn = 'postgresql://postgres@localhost:5432/postgres'
ROOT_PATH: str = '/' + os.getenv("APP_NAME", "")
DB_DSN: PostgresDsn = "postgresql://postgres@localhost:5432/postgres"
ROOT_PATH: str = "/" + os.getenv("APP_NAME", "")

CORS_ALLOW_ORIGINS: list[str] = ['*']
CORS_ALLOW_ORIGINS: list[str] = ["*"]
CORS_ALLOW_CREDENTIALS: bool = True
CORS_ALLOW_METHODS: list[str] = ['*']
CORS_ALLOW_HEADERS: list[str] = ['*']
CORS_ALLOW_METHODS: list[str] = ["*"]
CORS_ALLOW_HEADERS: list[str] = ["*"]

class Config:
"""Pydantic BaseSettings config"""

case_sensitive = True
env_file = ".env"
model_config = ConfigDict(case_sensitive=True, env_file=".env", extra="ignore")


@lru_cache
Expand Down