-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.py
More file actions
61 lines (47 loc) · 1.85 KB
/
database.py
File metadata and controls
61 lines (47 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""
قاعدة البيانات للذاكرة الدائمة
Database for persistent memory
"""
from sqlalchemy import create_engine, Column, Integer, String, Text, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from datetime import datetime
import os
from dotenv import load_dotenv
load_dotenv()
DATABASE_URL = os.getenv("DATABASE_URL", "sqlite:///./cometx_memory.db")
engine = create_engine(DATABASE_URL, connect_args={"check_same_thread": False})
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base()
class Conversation(Base):
"""جدول المحادثات - يحفظ كل رسالة"""
__tablename__ = "conversations"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True)
message = Column(Text)
response = Column(Text)
timestamp = Column(DateTime, default=datetime.utcnow)
context = Column(Text, nullable=True)
class Automation(Base):
"""جدول الأتمتة - يسجل كل عملية أتمتة"""
__tablename__ = "automations"
id = Column(Integer, primary_key=True, index=True)
user_id = Column(String, index=True)
trigger = Column(String)
github_issue_url = Column(String, nullable=True)
azure_pipeline_url = Column(String, nullable=True)
deploy_status = Column(String, nullable=True)
teams_notification = Column(String, nullable=True)
timestamp = Column(DateTime, default=datetime.utcnow)
status = Column(String, default="pending")
error_message = Column(Text, nullable=True)
def init_db():
"""إنشاء الجداول"""
Base.metadata.create_all(bind=engine)
def get_db():
"""الحصول على اتصال قاعدة البيانات"""
db = SessionLocal()
try:
yield db
finally:
db.close()