add
This commit is contained in:
1
app_core/db/__init__.py
Normal file
1
app_core/db/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Database Package
|
||||
BIN
app_core/db/__pycache__/__init__.cpython-312.pyc
Normal file
BIN
app_core/db/__pycache__/__init__.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app_core/db/__pycache__/database.cpython-312.pyc
Normal file
BIN
app_core/db/__pycache__/database.cpython-312.pyc
Normal file
Binary file not shown.
BIN
app_core/db/__pycache__/models.cpython-312.pyc
Normal file
BIN
app_core/db/__pycache__/models.cpython-312.pyc
Normal file
Binary file not shown.
21
app_core/db/database.py
Normal file
21
app_core/db/database.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from sqlalchemy import create_engine
|
||||
from sqlalchemy.orm import sessionmaker, declarative_base
|
||||
from app_core.config.settings import AppSettings
|
||||
|
||||
settings = AppSettings()
|
||||
|
||||
if not settings.database_url:
|
||||
raise RuntimeError(
|
||||
"Database configuration missing. Set DATABASE_URL or DB_HOST/DB_PORT/DB_NAME/DB_USER/DB_PASSWORD in a .env file at the project root."
|
||||
)
|
||||
|
||||
engine = create_engine(settings.database_url, pool_pre_ping=True, future=True, echo=settings.db_echo)
|
||||
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine, future=True)
|
||||
Base = declarative_base()
|
||||
|
||||
def get_db_session():
|
||||
db = SessionLocal()
|
||||
try:
|
||||
yield db
|
||||
finally:
|
||||
db.close()
|
||||
36
app_core/db/models.py
Normal file
36
app_core/db/models.py
Normal file
@@ -0,0 +1,36 @@
|
||||
from sqlalchemy import Column, Integer, String, DateTime, func, UniqueConstraint
|
||||
from .database import Base
|
||||
|
||||
class User(Base):
|
||||
__tablename__ = "workolik_users"
|
||||
__table_args__ = (
|
||||
UniqueConstraint("email", name="uq_workolik_users_email"),
|
||||
)
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
email = Column(String(255), nullable=False, unique=True, index=True)
|
||||
password_hash = Column(String(255), nullable=False)
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
|
||||
|
||||
class EmailLog(Base):
|
||||
__tablename__ = "email_logs"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
sent_at = Column(DateTime(timezone=True), server_default=func.now(), nullable=False)
|
||||
recipients = Column(String(1024), nullable=False)
|
||||
subject = Column(String(255), nullable=False)
|
||||
status = Column(String(50), nullable=False) # sent / failed
|
||||
error = Column(String(1024))
|
||||
date_for = Column(String(32), nullable=False)
|
||||
|
||||
class TriumphDebtorMapping(Base):
|
||||
__tablename__ = "triumph_debtor_mappings"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
code = Column(String(50))
|
||||
name = Column(String(255))
|
||||
dbmacc = Column(String(50))
|
||||
outlet = Column(String(255))
|
||||
created_at = Column(DateTime(timezone=True), server_default=func.now())
|
||||
updated_at = Column(DateTime(timezone=True), server_default=func.now(), onupdate=func.now())
|
||||
Reference in New Issue
Block a user