mirror of
https://github.com/Pythagora-io/gpt-pilot.git
synced 2026-01-08 12:53:50 -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.
46 lines
1.5 KiB
Python
46 lines
1.5 KiB
Python
# DeclarativeBase enables declarative configuration of
|
|
# database models within SQLAlchemy.
|
|
#
|
|
# It also sets up a registry for the classes that inherit from it,
|
|
# so that SQLAlechemy understands how they map to database tables.
|
|
|
|
from sqlalchemy import MetaData
|
|
from sqlalchemy.ext.asyncio import AsyncAttrs
|
|
from sqlalchemy.orm import DeclarativeBase
|
|
from sqlalchemy.types import JSON
|
|
|
|
|
|
class Base(AsyncAttrs, DeclarativeBase):
|
|
"""Base class for all SQL database models."""
|
|
|
|
# Mapping of Python types to SQLAlchemy types.
|
|
type_annotation_map = {
|
|
list[dict]: JSON,
|
|
list[str]: JSON,
|
|
dict: JSON,
|
|
}
|
|
|
|
metadata = MetaData(
|
|
# Naming conventions for constraints, foreign keys, etc.
|
|
naming_convention={
|
|
"ix": "ix_%(column_0_label)s",
|
|
"uq": "uq_%(table_name)s_%(column_0_name)s",
|
|
"ck": "ck_%(table_name)s_`%(constraint_name)s`",
|
|
"fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s",
|
|
"pk": "pk_%(table_name)s",
|
|
}
|
|
)
|
|
|
|
def __eq__(self, other) -> bool:
|
|
"""
|
|
Two instances of the same model class are the same if their
|
|
IDs are the same.
|
|
|
|
This allows comparison of models bound to different sessions.
|
|
"""
|
|
return isinstance(other, self.__class__) and self.id == other.id
|
|
|
|
def __repr__(self) -> str:
|
|
"""Return a string representation of the model."""
|
|
return f"<{self.__class__.__name__}(id={self.id})>"
|