mirror of
https://github.com/marcogll/telegram_new_socias.git
synced 2026-01-13 13:15:16 +00:00
This commit introduces a three-database architecture to the application, as specified in the `db_logic.md` file. The changes include: - A SQL initialization script (`db/init/init.sql`) to create the `USERS_ALMA`, `vanity_hr`, and `vanity_attendance` databases and their respective tables. - SQLAlchemy models for all tables, organized into separate files within the `models` directory. - Refactoring of the database connection logic in `modules/database.py` to support connections to all three databases. - Creation of a `modules/logger.py` to handle request logging to the `USERS_ALMA` database. - Updates to `docker-compose.yml` to mount the initialization script and build the bot image locally. - Updates to `.env.example` to include the new database environment variables. - Restoration of the data dictionary to `db_tasks.md`.
32 lines
1.2 KiB
Python
32 lines
1.2 KiB
Python
from sqlalchemy import create_engine, Column, Integer, String, Enum, TIMESTAMP
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.sql import func
|
|
from datetime import datetime
|
|
|
|
Base = declarative_base()
|
|
|
|
class RequestLog(Base):
|
|
__tablename__ = 'request_logs'
|
|
__table_args__ = {'schema': 'USERS_ALMA'}
|
|
id = Column(Integer, primary_key=True)
|
|
telegram_id = Column(String(50))
|
|
username = Column(String(100))
|
|
command = Column(String(100))
|
|
message = Column(String(500))
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|
|
|
class User(Base):
|
|
__tablename__ = 'users'
|
|
__table_args__ = {'schema': 'USERS_ALMA'}
|
|
|
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
|
username = Column(String(50), unique=True)
|
|
role = Column(Enum('admin', 'manager', 'user'))
|
|
first_name = Column(String(100))
|
|
last_name = Column(String(100))
|
|
email = Column(String(100), unique=True)
|
|
cell_phone = Column(String(20))
|
|
telegram_id = Column(String(50), unique=True)
|
|
created_at = Column(TIMESTAMP, server_default=func.now())
|
|
updated_at = Column(TIMESTAMP, server_default=func.now(), onupdate=func.now())
|