fix(relationship): fix unique relationship
This commit is contained in:
@@ -22,12 +22,16 @@ class RelationshipType(str, Enum):
|
||||
|
||||
class Relationship(SQLModel, table=True):
|
||||
__tablename__ = "relationship" # pyright: ignore[reportAssignmentType]
|
||||
id: int | None = Field(
|
||||
default=None,
|
||||
sa_column=Column(BigInteger, autoincrement=True, primary_key=True),
|
||||
exclude=True,
|
||||
)
|
||||
user_id: int = Field(
|
||||
default=None,
|
||||
sa_column=Column(
|
||||
BigInteger,
|
||||
ForeignKey("lazer_users.id"),
|
||||
primary_key=True,
|
||||
index=True,
|
||||
),
|
||||
)
|
||||
@@ -36,7 +40,6 @@ class Relationship(SQLModel, table=True):
|
||||
sa_column=Column(
|
||||
BigInteger,
|
||||
ForeignKey("lazer_users.id"),
|
||||
primary_key=True,
|
||||
index=True,
|
||||
),
|
||||
)
|
||||
|
||||
@@ -0,0 +1,54 @@
|
||||
"""relationship: fix unique relationship
|
||||
|
||||
Revision ID: 58a11441d302
|
||||
Revises: 1178d0758ebf
|
||||
Create Date: 2025-08-01 04:23:02.498166
|
||||
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Sequence
|
||||
|
||||
from alembic import op
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy.dialects import mysql
|
||||
|
||||
# revision identifiers, used by Alembic.
|
||||
revision: str = "58a11441d302"
|
||||
down_revision: str | Sequence[str] | None = "1178d0758ebf"
|
||||
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.add_column(
|
||||
"relationship",
|
||||
sa.Column("id", sa.BigInteger(), autoincrement=True, nullable=False),
|
||||
)
|
||||
op.drop_constraint("PRIMARY", "relationship", type_="primary")
|
||||
op.create_primary_key("pk_relationship", "relationship", ["id"])
|
||||
op.alter_column(
|
||||
"relationship", "user_id", existing_type=mysql.BIGINT(), nullable=True
|
||||
)
|
||||
op.alter_column(
|
||||
"relationship", "target_id", existing_type=mysql.BIGINT(), nullable=True
|
||||
)
|
||||
# ### end Alembic commands ###
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
"""Downgrade schema."""
|
||||
# ### commands auto generated by Alembic - please adjust! ###
|
||||
op.drop_constraint("pk_relationship", "relationship", type_="primary")
|
||||
op.create_primary_key("PRIMARY", "relationship", ["user_id", "target_id"])
|
||||
op.alter_column(
|
||||
"relationship", "target_id", existing_type=mysql.BIGINT(), nullable=False
|
||||
)
|
||||
op.alter_column(
|
||||
"relationship", "user_id", existing_type=mysql.BIGINT(), nullable=False
|
||||
)
|
||||
op.drop_column("relationship", "id")
|
||||
# ### end Alembic commands ###
|
||||
Reference in New Issue
Block a user