refactor: remove all ForeignKey constraints for testing (variant A)

- Remove all FK constraints from models (users, teams, channels, agents)
- Keep fields as optional nullable String for testing DAARWIZZ
- Update SQL migration to remove all REFERENCES
- Fix metadata -> meta in migration
- Allows service to work without base tables for testing
This commit is contained in:
Apple
2025-11-15 12:24:45 -08:00
parent 7afcffd0bd
commit 3698a0d2a1
2 changed files with 30 additions and 26 deletions

View File

@@ -4,7 +4,7 @@ SQLAlchemy моделі для Memory Service
"""
from sqlalchemy import (
Column, String, Text, JSON, TIMESTAMP, ForeignKey,
Column, String, Text, JSON, TIMESTAMP,
CheckConstraint, Index, Boolean, Integer
)
from sqlalchemy.dialects.postgresql import UUID, JSONB
@@ -24,7 +24,7 @@ class UserFact(Base):
__tablename__ = "user_facts"
id = Column(UUID(as_uuid=False), primary_key=True, server_default=func.gen_random_uuid())
user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=False, index=True)
user_id = Column(String, nullable=False, index=True) # Без FK constraint для тестування
team_id = Column(String, nullable=True, index=True) # Без FK constraint, оскільки teams може не існувати
# Ключ факту (наприклад: "language", "is_donor", "is_validator", "top_contributor")
@@ -61,11 +61,11 @@ class DialogSummary(Base):
id = Column(UUID(as_uuid=False), primary_key=True, server_default=func.gen_random_uuid())
# Контекст діалогу
team_id = Column(String, ForeignKey("teams.id", ondelete="CASCADE"), nullable=False, index=True)
channel_id = Column(String, ForeignKey("channels.id", ondelete="CASCADE"), nullable=True, index=True)
agent_id = Column(String, ForeignKey("agents.id", ondelete="CASCADE"), nullable=True, index=True)
user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=True, index=True)
# Контекст діалогу (без FK constraints для тестування)
team_id = Column(String, nullable=False, index=True)
channel_id = Column(String, nullable=True, index=True)
agent_id = Column(String, nullable=True, index=True)
user_id = Column(String, nullable=True, index=True)
# Період, який охоплює підсумок
period_start = Column(TIMESTAMP(timezone=True), nullable=False)
@@ -103,10 +103,11 @@ class AgentMemoryEvent(Base):
id = Column(UUID(as_uuid=False), primary_key=True, server_default=func.gen_random_uuid())
agent_id = Column(String, ForeignKey("agents.id", ondelete="CASCADE"), nullable=False, index=True)
team_id = Column(String, ForeignKey("teams.id", ondelete="CASCADE"), nullable=False, index=True)
channel_id = Column(String, ForeignKey("channels.id", ondelete="CASCADE"), nullable=True, index=True)
user_id = Column(String, ForeignKey("users.id", ondelete="CASCADE"), nullable=True, index=True)
# Без FK constraints для тестування
agent_id = Column(String, nullable=False, index=True)
team_id = Column(String, nullable=False, index=True)
channel_id = Column(String, nullable=True, index=True)
user_id = Column(String, nullable=True, index=True)
# Scope: short_term, mid_term, long_term
scope = Column(String, nullable=False)
@@ -137,8 +138,9 @@ class AgentMemoryFactsVector(Base):
id = Column(UUID(as_uuid=False), primary_key=True, server_default=func.gen_random_uuid())
agent_id = Column(String, ForeignKey("agents.id", ondelete="CASCADE"), nullable=False, index=True)
team_id = Column(String, ForeignKey("teams.id", ondelete="CASCADE"), nullable=False, index=True)
# Без FK constraints для тестування
agent_id = Column(String, nullable=False, index=True)
team_id = Column(String, nullable=False, index=True)
fact_text = Column(Text, nullable=False)
embedding = Column(Vector(1536), nullable=True) # OpenAI ada-002 embedding size