Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(prompts): rename tables #5805

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def _(*args: Any, **kwargs: Any) -> str:

def upgrade() -> None:
op.create_table(
"prompt_tag_configs",
"prompt_labels",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("name", sa.String, nullable=False, unique=True),
sa.Column("description", sa.String),
sa.Column("name", sa.String, nullable=False, unique=True, index=True),
sa.Column("description", sa.String, nullable=True),
)

op.create_table(
Expand All @@ -62,8 +62,8 @@ def upgrade() -> None:
nullable=True,
index=True,
),
sa.Column("name", sa.String, unique=True, nullable=False),
sa.Column("description", sa.String),
sa.Column("name", sa.String, unique=True, index=True, nullable=False),
sa.Column("description", sa.String, nullable=True),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
Expand All @@ -80,12 +80,12 @@ def upgrade() -> None:
)

op.create_table(
"prompt_tags",
"prompts_prompt_labels",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column(
"prompt_tag_config_id",
"prompt_label_id",
sa.Integer,
sa.ForeignKey("prompt_tag_configs.id", ondelete="CASCADE"),
sa.ForeignKey("prompt_labels.id", ondelete="CASCADE"),
nullable=False,
index=True,
),
Expand Down Expand Up @@ -149,7 +149,7 @@ def upgrade() -> None:
)

op.create_table(
"prompt_template_version_tags",
"prompt_version_tags",
sa.Column("id", sa.Integer, primary_key=True),
sa.Column("name", sa.String, nullable=False),
sa.Column("description", sa.String, nullable=True),
Expand Down Expand Up @@ -182,8 +182,8 @@ def upgrade() -> None:


def downgrade() -> None:
op.drop_table("prompt_template_version_tags")
op.drop_table("prompt_version_tags")
op.drop_table("prompt_versions")
op.drop_table("prompt_tags")
op.drop_table("prompts_prompt_labels")
op.drop_table("prompts")
op.drop_table("prompt_tag_configs")
op.drop_table("prompt_labels")
58 changes: 27 additions & 31 deletions src/phoenix/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,22 +796,20 @@ class ApiKey(Base):
__table_args__ = (dict(sqlite_autoincrement=True),)


class PromptTagConfig(Base):
__tablename__ = "prompt_tag_configs"
class PromptLabel(Base):
__tablename__ = "prompt_labels"

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
name: Mapped[str] = mapped_column(String, unique=True, index=True, nullable=False)
description: Mapped[Optional[str]]

prompt_tags: Mapped[list["PromptTag"]] = relationship(
"PromptTag",
back_populates="prompt_tag_config",
prompts_prompt_labels: Mapped[list["PromptPromptLabel"]] = relationship(
"PromptPromptLabel",
back_populates="prompt_label",
cascade="all, delete-orphan",
uselist=True,
)

__table_args__ = (UniqueConstraint("name"),)


class Prompt(Base):
__tablename__ = "prompts"
Expand All @@ -822,15 +820,15 @@ class Prompt(Base):
index=True,
nullable=True,
)
name: Mapped[str] = mapped_column(String, unique=True, nullable=False)
name: Mapped[str] = mapped_column(String, unique=True, index=True, nullable=False)
description: Mapped[Optional[str]]
created_at: Mapped[datetime] = mapped_column(UtcTimeStamp, server_default=func.now())
updated_at: Mapped[datetime] = mapped_column(
UtcTimeStamp, server_default=func.now(), onupdate=func.now()
)

prompt_tags: Mapped[list["PromptTag"]] = relationship(
"PromptTag",
prompts_prompt_labels: Mapped[list["PromptPromptLabel"]] = relationship(
"PromptPromptLabel",
back_populates="prompt",
cascade="all, delete-orphan",
uselist=True,
Expand All @@ -843,22 +841,20 @@ class Prompt(Base):
uselist=True,
)

prompt_template_version_tags: Mapped[list["PromptTemplateVersionTag"]] = relationship(
"PromptTemplateVersionTag",
prompt_version_tags: Mapped[list["PromptVersionTag"]] = relationship(
"PromptVersionTag",
back_populates="prompt",
cascade="all, delete-orphan",
uselist=True,
)

__table_args__ = (UniqueConstraint("name"),)


class PromptTag(Base):
__tablename__ = "prompt_tags"
class PromptPromptLabel(Base):
__tablename__ = "prompts_prompt_labels"

id: Mapped[int] = mapped_column(primary_key=True)
prompt_tag_config_id: Mapped[int] = mapped_column(
ForeignKey("prompt_tag_configs.id", ondelete="CASCADE"),
prompt_label_id: Mapped[int] = mapped_column(
ForeignKey("prompt_labels.id", ondelete="CASCADE"),
index=True,
nullable=False,
)
Expand All @@ -868,10 +864,10 @@ class PromptTag(Base):
nullable=False,
)

prompt_tag_config: Mapped["PromptTagConfig"] = relationship(
"PromptTagConfig", back_populates="prompt_tags"
prompt_label: Mapped["PromptLabel"] = relationship(
"PromptLabel", back_populates="prompts_prompt_labels"
)
prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompt_tags")
prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompts_prompt_labels")


class PromptVersion(Base):
Expand Down Expand Up @@ -903,28 +899,28 @@ class PromptVersion(Base):
)
template: Mapped[dict[str, Any]] = mapped_column(JsonDict, nullable=False)
invocation_parameters: Mapped[Optional[dict[str, Any]]] = mapped_column(
JsonDict, default=dict, nullable=True
JsonDict, default=None, nullable=True
)
tools: Mapped[Optional[dict[str, Any]]] = mapped_column(JsonDict, default=dict, nullable=True)
tools: Mapped[Optional[dict[str, Any]]] = mapped_column(JsonDict, default=None, nullable=True)
output_schema: Mapped[Optional[dict[str, Any]]] = mapped_column(
JsonDict, default=dict, nullable=True
JsonDict, default=None, nullable=True
)
model_provider: Mapped[str]
model_name: Mapped[str]
created_at: Mapped[datetime] = mapped_column(UtcTimeStamp, server_default=func.now())

prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompt_versions")

prompt_template_version_tags: Mapped[list["PromptTemplateVersionTag"]] = relationship(
"PromptTemplateVersionTag",
prompt_version_tags: Mapped[list["PromptVersionTag"]] = relationship(
"PromptVersionTag",
back_populates="prompt_version",
cascade="all, delete-orphan",
uselist=True,
)


class PromptTemplateVersionTag(Base):
__tablename__ = "prompt_template_version_tags"
class PromptVersionTag(Base):
__tablename__ = "prompt_version_tags"

id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String, nullable=False)
Expand All @@ -945,9 +941,9 @@ class PromptTemplateVersionTag(Base):
nullable=True,
)

prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompt_template_version_tags")
prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompt_version_tags")
prompt_version: Mapped["PromptVersion"] = relationship(
"PromptVersion", back_populates="prompt_template_version_tags"
"PromptVersion", back_populates="prompt_version_tags"
)

__table_args__ = (UniqueConstraint("name", "prompt_id"),)
Loading