"""create_emergency_contacts_table

Revision ID: c78a12db4567
Revises: 49846a45b6b0
Create Date: 2025-09-25 16:00:00

"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

# revision identifiers, used by Alembic.
revision = "c78a12db4567"
down_revision = "49846a45b6b0"
branch_labels = None
depends_on = None


def upgrade():
    # Создание таблицы emergency_contacts
    op.create_table(
        "emergency_contacts",
        sa.Column("id", sa.Integer(), nullable=False),
        sa.Column(
            "uuid", postgresql.UUID(as_uuid=True), server_default=sa.text("gen_random_uuid()"), nullable=False
        ),
        sa.Column("user_id", sa.Integer(), nullable=False),
        sa.Column("name", sa.String(length=100), nullable=False),
        sa.Column("phone_number", sa.String(length=20), nullable=False),
        sa.Column("relationship", sa.String(length=50), nullable=True),
        sa.Column("notes", sa.Text(), nullable=True),
        sa.Column(
            "created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=False
        ),
        sa.Column(
            "updated_at",
            sa.DateTime(timezone=True),
            server_default=sa.text("now()"),
            nullable=False,
        ),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(
        op.f("ix_emergency_contacts_uuid"), "emergency_contacts", ["uuid"], unique=True
    )
    op.create_index(
        op.f("ix_emergency_contacts_user_id"), "emergency_contacts", ["user_id"], unique=False
    )


def downgrade():
    # Удаление таблицы emergency_contacts
    op.drop_index(op.f("ix_emergency_contacts_user_id"), table_name="emergency_contacts")
    op.drop_index(op.f("ix_emergency_contacts_uuid"), table_name="emergency_contacts")
    op.drop_table("emergency_contacts")