File size: 1,194 Bytes
fe3802f
 
 
f5faa72
fe3802f
 
 
 
 
 
 
 
 
 
 
 
9f87755
fe3802f
 
 
 
 
 
 
 
 
 
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
from sqlalchemy import Column, Integer, String, Text, ForeignKey, DateTime, Index
from sqlalchemy.orm import relationship
from sqlalchemy.sql import func
from app.core.database import Base

class CodeFile(Base):
    """Store full file contents for complete AI context"""
    __tablename__ = "code_files"
    
    id = Column(Integer, primary_key=True, index=True)
    repository_id = Column(Integer, ForeignKey("repositories.id", ondelete="CASCADE"), nullable=False)
    file_path = Column(String(500), nullable=False)
    full_content = Column(Text, nullable=False)  # Complete file chunk content
    chunk_index = Column(Integer, nullable=False)
    start_line = Column(Integer, nullable=False)
    end_line = Column(Integer, nullable=False)
    chunk_type = Column(String(50), nullable=False)  
    created_at = Column(DateTime(timezone=True), server_default=func.now())
    
    # Relationship
    repository = relationship("Repository", back_populates="code_files")
    
    # Composite index for fast lookups
    __table_args__ = (
        Index('ix_code_files_repo_file_chunk', 'repository_id', 'file_path', 'chunk_index'),
        Index('ix_code_files_repo_id', 'repository_id'),
    )