init
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
"""Repository model"""
|
||||
|
||||
from sqlalchemy import Column, Integer, String, Boolean, DateTime, JSON, Enum
|
||||
from sqlalchemy.orm import relationship
|
||||
from sqlalchemy.sql import func
|
||||
from datetime import datetime
|
||||
import enum
|
||||
|
||||
from app.database import Base
|
||||
|
||||
|
||||
class PlatformEnum(str, enum.Enum):
|
||||
"""Git platform types"""
|
||||
GITEA = "gitea"
|
||||
GITHUB = "github"
|
||||
BITBUCKET = "bitbucket"
|
||||
|
||||
|
||||
class Repository(Base):
|
||||
"""Repository model for tracking Git repositories"""
|
||||
|
||||
__tablename__ = "repositories"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
name = Column(String, nullable=False)
|
||||
platform = Column(Enum(PlatformEnum), nullable=False)
|
||||
url = Column(String, nullable=False)
|
||||
api_token = Column(String, nullable=True) # Encrypted, optional (uses master token if not set)
|
||||
webhook_secret = Column(String, nullable=False)
|
||||
config = Column(JSON, default=dict) # Review configuration
|
||||
is_active = Column(Boolean, default=True)
|
||||
created_at = Column(DateTime, default=datetime.utcnow, server_default=func.now())
|
||||
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, server_default=func.now())
|
||||
|
||||
# Relationships
|
||||
pull_requests = relationship("PullRequest", back_populates="repository", cascade="all, delete-orphan")
|
||||
|
||||
def __repr__(self):
|
||||
return f"<Repository(id={self.id}, name={self.name}, platform={self.platform})>"
|
||||
|
||||
Reference in New Issue
Block a user