57 lines
1.7 KiB
Python
57 lines
1.7 KiB
Python
from sqlalchemy import create_engine, Column, Integer, String, Text, ForeignKey
|
|
from sqlalchemy.ext.declarative import declarative_base
|
|
from sqlalchemy.orm import sessionmaker
|
|
from sqlalchemy.sql.functions import func
|
|
from sqlalchemy.sql.sqltypes import DateTime
|
|
from sqlalchemy.types import Boolean
|
|
|
|
# Initialize the database
|
|
DATABASE_URL = "sqlite:///./project_monitor.db"
|
|
|
|
# SQLAlchemy setup
|
|
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
|
|
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
|
|
Base = declarative_base()
|
|
|
|
|
|
# Define the table model
|
|
|
|
|
|
class Script(Base):
|
|
__tablename__ = "scripts"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
name = Column(String, nullable=False)
|
|
script_content = Column(Text, nullable=True)
|
|
enabled = Column(Boolean, default=False)
|
|
created_at = Column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|
|
|
|
|
|
class Log(Base):
|
|
__tablename__ = "logs"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
message = Column(String, nullable=False)
|
|
error_code = Column(Integer, nullable=False, default=0)
|
|
error_message = Column(String, nullable=True)
|
|
created_at = Column(
|
|
DateTime(timezone=True), nullable=False, server_default=func.now()
|
|
)
|
|
|
|
script_id = Column(Integer, ForeignKey("scripts.id"), nullable=False)
|
|
|
|
|
|
class Settings(Base):
|
|
__tablename__ = "user_settings"
|
|
|
|
id = Column(Integer, primary_key=True, index=True)
|
|
requirements = Column(String, nullable=False)
|
|
environment = Column(String, nullable=False)
|
|
user = Column(String, nullable=False)
|
|
|
|
|
|
# Create the database tables
|
|
Base.metadata.create_all(bind=engine)
|