From 9cdc826656faaec4b7d109376e2840fd7ec766d7 Mon Sep 17 00:00:00 2001 From: Alexander Song Date: Fri, 20 Dec 2024 12:10:09 -0800 Subject: [PATCH] rename tables --- .../bc8fea3c2bc8_add_prompt_tables.py | 16 +++---- src/phoenix/db/models.py | 44 +++++++++---------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/src/phoenix/db/migrations/versions/bc8fea3c2bc8_add_prompt_tables.py b/src/phoenix/db/migrations/versions/bc8fea3c2bc8_add_prompt_tables.py index 6c603e9caf..0c8a135986 100644 --- a/src/phoenix/db/migrations/versions/bc8fea3c2bc8_add_prompt_tables.py +++ b/src/phoenix/db/migrations/versions/bc8fea3c2bc8_add_prompt_tables.py @@ -46,7 +46,7 @@ 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), @@ -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, ), @@ -149,7 +149,7 @@ def upgrade() -> None: ) op.create_table( - "prompt_template_version_tags", + "prompt_tags", sa.Column("id", sa.Integer, primary_key=True), sa.Column("name", sa.String, nullable=False), sa.Column("description", sa.String, nullable=True), @@ -182,8 +182,8 @@ def upgrade() -> None: def downgrade() -> None: - op.drop_table("prompt_template_version_tags") - op.drop_table("prompt_versions") op.drop_table("prompt_tags") + op.drop_table("prompt_versions") + op.drop_table("prompts_prompt_labels") op.drop_table("prompts") - op.drop_table("prompt_tag_configs") + op.drop_table("prompt_labels") diff --git a/src/phoenix/db/models.py b/src/phoenix/db/models.py index ea45c547d5..4c2197458a 100644 --- a/src/phoenix/db/models.py +++ b/src/phoenix/db/models.py @@ -796,16 +796,16 @@ 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) 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_labels", cascade="all, delete-orphan", uselist=True, ) @@ -829,8 +829,8 @@ class Prompt(Base): 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, @@ -843,8 +843,8 @@ class Prompt(Base): uselist=True, ) - prompt_template_version_tags: Mapped[list["PromptTemplateVersionTag"]] = relationship( - "PromptTemplateVersionTag", + prompt_tags: Mapped[list["PromptTag"]] = relationship( + "PromptTag", back_populates="prompt", cascade="all, delete-orphan", uselist=True, @@ -853,12 +853,12 @@ class Prompt(Base): __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, ) @@ -868,10 +868,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): @@ -915,16 +915,16 @@ class PromptVersion(Base): prompt: Mapped["Prompt"] = relationship("Prompt", back_populates="prompt_versions") - prompt_template_version_tags: Mapped[list["PromptTemplateVersionTag"]] = relationship( - "PromptTemplateVersionTag", + prompt_tags: Mapped[list["PromptTag"]] = relationship( + "PromptTag", back_populates="prompt_version", cascade="all, delete-orphan", uselist=True, ) -class PromptTemplateVersionTag(Base): - __tablename__ = "prompt_template_version_tags" +class PromptTag(Base): + __tablename__ = "prompt_tags" id: Mapped[int] = mapped_column(primary_key=True) name: Mapped[str] = mapped_column(String, nullable=False) @@ -945,9 +945,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_tags") prompt_version: Mapped["PromptVersion"] = relationship( - "PromptVersion", back_populates="prompt_template_version_tags" + "PromptVersion", back_populates="prompt_tags" ) __table_args__ = (UniqueConstraint("name", "prompt_id"),)