mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-09 13:17:55 -05:00
This is a complete rewrite of the GPT Pilot core, from the ground up, making the agentic architecture front and center, and also fixing some long-standing problems with the database architecture that weren't feasible to solve without breaking compatibility. As the database structure and config file syntax have changed, we have automatic imports for projects and current configs, see the README.md file for details. This also relicenses the project to FSL-1.1-MIT license.
44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from typing import TYPE_CHECKING, Optional
|
|
from uuid import UUID
|
|
|
|
from sqlalchemy import ForeignKey, UniqueConstraint
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
|
|
from core.db.models import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from core.db.models import FileContent, ProjectState
|
|
|
|
|
|
class File(Base):
|
|
__tablename__ = "files"
|
|
__table_args__ = (UniqueConstraint("project_state_id", "path"),)
|
|
|
|
# ID and parent FKs
|
|
id: Mapped[int] = mapped_column(primary_key=True)
|
|
project_state_id: Mapped[UUID] = mapped_column(ForeignKey("project_states.id", ondelete="CASCADE"))
|
|
content_id: Mapped[str] = mapped_column(ForeignKey("file_contents.id", ondelete="RESTRICT"))
|
|
|
|
# Attributes
|
|
path: Mapped[str] = mapped_column()
|
|
meta: Mapped[dict] = mapped_column(default=dict, server_default="{}")
|
|
|
|
# Relationships
|
|
project_state: Mapped[Optional["ProjectState"]] = relationship(back_populates="files")
|
|
content: Mapped["FileContent"] = relationship(back_populates="files", lazy="selectin")
|
|
|
|
def clone(self) -> "File":
|
|
"""
|
|
Clone the file object, to be used in a new project state.
|
|
|
|
The clone references the same file content object as the original.
|
|
|
|
:return: The cloned file object.
|
|
"""
|
|
return File(
|
|
project_state=None,
|
|
content_id=self.content_id,
|
|
path=self.path,
|
|
meta=self.meta,
|
|
)
|