Some checks failed
CI / test (push) Failing after 18s
- add user_contacts table and migration - expose /users/contacts list/add/remove endpoints - add Contacts tab in chat list with add/remove actions
43 lines
1.8 KiB
Python
43 lines
1.8 KiB
Python
"""add user contacts table
|
|
|
|
Revision ID: 0017_user_contacts
|
|
Revises: 0016_chat_invites
|
|
Create Date: 2026-03-08 23:10:00.000000
|
|
"""
|
|
|
|
from typing import Sequence, Union
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
|
|
revision: str = "0017_user_contacts"
|
|
down_revision: Union[str, Sequence[str], None] = "0016_chat_invites"
|
|
branch_labels: Union[str, Sequence[str], None] = None
|
|
depends_on: Union[str, Sequence[str], None] = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
op.create_table(
|
|
"user_contacts",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("user_id", sa.Integer(), nullable=False),
|
|
sa.Column("contact_user_id", sa.Integer(), nullable=False),
|
|
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False),
|
|
sa.ForeignKeyConstraint(["user_id"], ["users.id"], name=op.f("fk_user_contacts_user_id_users"), ondelete="CASCADE"),
|
|
sa.ForeignKeyConstraint(["contact_user_id"], ["users.id"], name=op.f("fk_user_contacts_contact_user_id_users"), ondelete="CASCADE"),
|
|
sa.PrimaryKeyConstraint("id", name=op.f("pk_user_contacts")),
|
|
sa.UniqueConstraint("user_id", "contact_user_id", name="uq_user_contacts_pair"),
|
|
)
|
|
op.create_index(op.f("ix_user_contacts_id"), "user_contacts", ["id"], unique=False)
|
|
op.create_index(op.f("ix_user_contacts_user_id"), "user_contacts", ["user_id"], unique=False)
|
|
op.create_index(op.f("ix_user_contacts_contact_user_id"), "user_contacts", ["contact_user_id"], unique=False)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_user_contacts_contact_user_id"), table_name="user_contacts")
|
|
op.drop_index(op.f("ix_user_contacts_user_id"), table_name="user_contacts")
|
|
op.drop_index(op.f("ix_user_contacts_id"), table_name="user_contacts")
|
|
op.drop_table("user_contacts")
|
|
|