Initial upload: Agentic Codebase Memory Manager v0.1.0
This commit is contained in:
101
src/memory_manager/db/models.py
Normal file
101
src/memory_manager/db/models.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
"""SQLAlchemy models for memory manager."""
|
||||||
|
import enum
|
||||||
|
from datetime import datetime
|
||||||
|
from typing import List, Optional
|
||||||
|
|
||||||
|
from sqlalchemy import (
|
||||||
|
Column,
|
||||||
|
DateTime,
|
||||||
|
Enum,
|
||||||
|
ForeignKey,
|
||||||
|
Integer,
|
||||||
|
String,
|
||||||
|
Text,
|
||||||
|
JSON,
|
||||||
|
Table,
|
||||||
|
)
|
||||||
|
from sqlalchemy.orm import DeclarativeBase, relationship, Mapped, mapped_column
|
||||||
|
|
||||||
|
|
||||||
|
class Base(DeclarativeBase):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryCategory(str, enum.Enum):
|
||||||
|
DECISION = "decision"
|
||||||
|
FEATURE = "feature"
|
||||||
|
REFACTORING = "refactoring"
|
||||||
|
ARCHITECTURE = "architecture"
|
||||||
|
BUG = "bug"
|
||||||
|
NOTE = "note"
|
||||||
|
|
||||||
|
|
||||||
|
memory_tags = Table(
|
||||||
|
"memory_tags",
|
||||||
|
Base.metadata,
|
||||||
|
Column("memory_entry_id", Integer, ForeignKey("memory_entries.id"), primary_key=True),
|
||||||
|
Column("tag", String(100), primary_key=True),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class MemoryEntry(Base):
|
||||||
|
__tablename__ = "memory_entries"
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
|
title: Mapped[str] = mapped_column(String(255), nullable=False)
|
||||||
|
content: Mapped[str] = mapped_column(Text, nullable=False)
|
||||||
|
category: Mapped[MemoryCategory] = mapped_column(
|
||||||
|
Enum(MemoryCategory), nullable=False
|
||||||
|
)
|
||||||
|
tags: Mapped[List[str]] = mapped_column(JSON, default=list)
|
||||||
|
agent_id: Mapped[str] = mapped_column(String(100), default="unknown")
|
||||||
|
project_path: Mapped[str] = mapped_column(String(500), default=".")
|
||||||
|
created_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime, default=datetime.utcnow
|
||||||
|
)
|
||||||
|
updated_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime, default=datetime.utcnow, onupdate=datetime.utcnow
|
||||||
|
)
|
||||||
|
parent_id: Mapped[Optional[int]] = mapped_column(
|
||||||
|
Integer, ForeignKey("memory_entries.id"), nullable=True
|
||||||
|
)
|
||||||
|
|
||||||
|
parent: Mapped[Optional["MemoryEntry"]] = relationship(
|
||||||
|
"MemoryEntry", remote_side=[id], back_populates="children"
|
||||||
|
)
|
||||||
|
children: Mapped[List["MemoryEntry"]] = relationship(
|
||||||
|
"MemoryEntry", back_populates="parent"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class Commit(Base):
|
||||||
|
__tablename__ = "commits"
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
|
hash: Mapped[str] = mapped_column(String(40), unique=True, nullable=False)
|
||||||
|
message: Mapped[str] = mapped_column(Text, nullable=False)
|
||||||
|
agent_id: Mapped[str] = mapped_column(String(100), default="unknown")
|
||||||
|
project_path: Mapped[str] = mapped_column(String(500), default=".")
|
||||||
|
created_at: Mapped[datetime] = mapped_column(
|
||||||
|
DateTime, default=datetime.utcnow
|
||||||
|
)
|
||||||
|
|
||||||
|
entries: Mapped[List["CommitEntry"]] = relationship(
|
||||||
|
"CommitEntry", back_populates="commit", cascade="all, delete-orphan"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
class CommitEntry(Base):
|
||||||
|
__tablename__ = "commit_entries"
|
||||||
|
|
||||||
|
id: Mapped[int] = mapped_column(Integer, primary_key=True)
|
||||||
|
commit_id: Mapped[int] = mapped_column(
|
||||||
|
Integer, ForeignKey("commits.id"), nullable=False
|
||||||
|
)
|
||||||
|
memory_entry_id: Mapped[int] = mapped_column(
|
||||||
|
Integer, ForeignKey("memory_entries.id"), nullable=False
|
||||||
|
)
|
||||||
|
entry_snapshot: Mapped[str] = mapped_column(JSON, nullable=False)
|
||||||
|
|
||||||
|
commit: Mapped["Commit"] = relationship("Commit", back_populates="entries")
|
||||||
|
memory_entry: Mapped["MemoryEntry"] = relationship("MemoryEntry")
|
||||||
Reference in New Issue
Block a user