Prepare ERP source for Gitea deployment

This commit is contained in:
A R R R Associates
2026-06-20 15:01:44 +05:30
commit 5c75eb6bd9
450 changed files with 67698 additions and 0 deletions
View File
+9
View File
@@ -0,0 +1,9 @@
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, DeclarativeBase
from app.core.db.urls import get_common_db_url
class CommonBase(DeclarativeBase):
pass
CommonEngine = create_engine(get_common_db_url(), pool_pre_ping=True, future=True)
CommonSessionLocal = sessionmaker(bind=CommonEngine, autocommit=False, autoflush=False, future=True)
+10
View File
@@ -0,0 +1,10 @@
from typing import Generator
from sqlalchemy.orm import Session
from app.core.db.common import CommonSessionLocal
def get_common_db() -> Generator[Session, None, None]:
db = CommonSessionLocal()
try:
yield db
finally:
db.close()
+30
View File
@@ -0,0 +1,30 @@
import os
from sqlalchemy.engine import URL
from app.core.settings import get_settings
def sqlite_url(path: str) -> str:
parent = os.path.dirname(path)
if parent:
os.makedirs(parent, exist_ok=True)
return f"sqlite+pysqlite:///{path}"
def postgres_url(user: str, password: str, host: str, port: int, db: str) -> str:
return URL.create(
drivername="postgresql+psycopg",
username=user,
password=password,
host=host,
port=port,
database=db,
).render_as_string(hide_password=False)
def get_common_db_url() -> str:
s = get_settings()
if s.DB_BACKEND.lower() == "sqlite":
return sqlite_url(s.SQLITE_COMMON_PATH)
return postgres_url(s.PG_USER, s.PG_PASSWORD, s.PG_HOST, s.PG_PORT, s.PG_DB_COMMON)