From 858a7e86407b4b9988b3cd86891fecc9c32f7c97 Mon Sep 17 00:00:00 2001 From: MingxuanGame Date: Wed, 13 Aug 2025 15:18:26 +0000 Subject: [PATCH] playlist_best_scores: remove foreign key to allow to remove items --- app/database/playlist_best_score.py | 2 +- ...laylist_best_scores_remove_foreign_key_.py | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 migrations/versions/9aa4f7c06824_playlist_best_scores_remove_foreign_key_.py diff --git a/app/database/playlist_best_score.py b/app/database/playlist_best_score.py index 6ecb18a..72f83ec 100644 --- a/app/database/playlist_best_score.py +++ b/app/database/playlist_best_score.py @@ -30,7 +30,7 @@ class PlaylistBestScore(SQLModel, table=True): sa_column=Column(BigInteger, ForeignKey("scores.id"), primary_key=True) ) room_id: int = Field(foreign_key="rooms.id", index=True) - playlist_id: int = Field(foreign_key="room_playlists.id", index=True) + playlist_id: int = Field(index=True) total_score: int = Field(default=0, sa_column=Column(BigInteger)) attempts: int = Field(default=0) # playlist diff --git a/migrations/versions/9aa4f7c06824_playlist_best_scores_remove_foreign_key_.py b/migrations/versions/9aa4f7c06824_playlist_best_scores_remove_foreign_key_.py new file mode 100644 index 0000000..a7381e3 --- /dev/null +++ b/migrations/versions/9aa4f7c06824_playlist_best_scores_remove_foreign_key_.py @@ -0,0 +1,41 @@ +"""playlist_best_scores: remove foreign key to allow to remove items + +Revision ID: 9aa4f7c06824 +Revises: 8bab62d764a5 +Create Date: 2025-08-13 15:17:53.921545 + +""" + +from __future__ import annotations + +from collections.abc import Sequence + +from alembic import op + +# revision identifiers, used by Alembic. +revision: str = "9aa4f7c06824" +down_revision: str | Sequence[str] | None = "8bab62d764a5" +branch_labels: str | Sequence[str] | None = None +depends_on: str | Sequence[str] | None = None + + +def upgrade() -> None: + """Upgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.drop_constraint( + op.f("playlist_best_scores_ibfk_1"), "playlist_best_scores", type_="foreignkey" + ) + # ### end Alembic commands ### + + +def downgrade() -> None: + """Downgrade schema.""" + # ### commands auto generated by Alembic - please adjust! ### + op.create_foreign_key( + op.f("playlist_best_scores_ibfk_1"), + "playlist_best_scores", + "room_playlists", + ["playlist_id"], + ["id"], + ) + # ### end Alembic commands ###