Compare commits

...

2 Commits

Author SHA1 Message Date
Yuhong Sun
2129e77bdf k 2026-01-17 18:23:09 -08:00
Yuhong Sun
40dec09e35 k 2026-01-17 18:11:34 -08:00
2 changed files with 43 additions and 1 deletions

View File

@@ -0,0 +1,42 @@
"""Add SET NULL cascade to chat_session.persona_id foreign key
Revision ID: ac9c7b76419b
Revises: 73e9983e5091
Create Date: 2026-01-17 18:10:00.000000
"""
from alembic import op
# revision identifiers, used by Alembic.
revision = "ac9c7b76419b"
down_revision = "73e9983e5091"
branch_labels = None
depends_on = None
def upgrade() -> None:
# Drop the existing foreign key constraint (no cascade behavior)
op.drop_constraint("fk_chat_session_persona_id", "chat_session", type_="foreignkey")
# Recreate with SET NULL on delete, so deleting a persona sets
# chat_session.persona_id to NULL instead of blocking the delete
op.create_foreign_key(
"fk_chat_session_persona_id",
"chat_session",
"persona",
["persona_id"],
["id"],
ondelete="SET NULL",
)
def downgrade() -> None:
# Revert to original constraint without cascade behavior
op.drop_constraint("fk_chat_session_persona_id", "chat_session", type_="foreignkey")
op.create_foreign_key(
"fk_chat_session_persona_id",
"chat_session",
"persona",
["persona_id"],
["id"],
)

View File

@@ -2045,7 +2045,7 @@ class ChatSession(Base):
ForeignKey("user.id", ondelete="CASCADE"), nullable=True
)
persona_id: Mapped[int | None] = mapped_column(
ForeignKey("persona.id"), nullable=True
ForeignKey("persona.id", ondelete="SET NULL"), nullable=True
)
description: Mapped[str | None] = mapped_column(Text, nullable=True)
# This chat created by OnyxBot