Add backend
This commit is contained in:
43
backend/model.py
Normal file
43
backend/model.py
Normal file
@@ -0,0 +1,43 @@
|
||||
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
|
||||
|
||||
# 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)
|
||||
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)
|
||||
created_at = Column(
|
||||
DateTime(timezone=True), nullable=False, server_default=func.now()
|
||||
)
|
||||
|
||||
script_id = Column(Integer, ForeignKey("scripts.id"), nullable=False)
|
||||
|
||||
|
||||
# Create the database tables
|
||||
Base.metadata.create_all(bind=engine)
|
||||
Reference in New Issue
Block a user