"""add dynamic section

Revision ID: 6d56cc05dc0d
Revises: 6d424d93a992
Create Date: 2025-08-14 12:59:05.670127

"""

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = "6d56cc05dc0d"
down_revision = "6d424d93a992"
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table(
        "dynamic_section",
        sa.Column("default_amount", sa.Integer(), nullable=False),
        sa.Column("id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["id"],
            ["public.composite_field.id"],
            name=op.f("fk_dynamic_section_id_composite_field"),
            ondelete="CASCADE",
        ),
        sa.PrimaryKeyConstraint("id", name=op.f("pk_dynamic_section")),
        schema="public",
    )
    op.create_table(
        "association_table_dynamic_section",
        sa.Column("parent_id", sa.Integer(), nullable=False),
        sa.Column("child_id", sa.Integer(), nullable=False),
        sa.ForeignKeyConstraint(
            ["child_id"],
            ["public.form_field.id"],
            name=op.f("fk_association_table_dynamic_section_child_id_form_field"),
        ),
        sa.ForeignKeyConstraint(
            ["parent_id"],
            ["public.dynamic_section.id"],
            name=op.f("fk_association_table_dynamic_section_parent_id_dynamic_section"),
        ),
        sa.PrimaryKeyConstraint("parent_id", "child_id", name=op.f("pk_association_table_dynamic_section")),
        schema="public",
    )
    op.add_column("number_input", sa.Column("placeholder", sa.Float(), nullable=True), schema="public")
    op.drop_constraint("fk_number_input_placeholder_id_text", "number_input", schema="public", type_="foreignkey")
    op.drop_column("number_input", "placeholder_id", schema="public")
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column(
        "number_input", sa.Column("placeholder_id", sa.INTEGER(), autoincrement=False, nullable=True), schema="public"
    )
    op.create_foreign_key(
        "fk_number_input_placeholder_id_text",
        "number_input",
        "text",
        ["placeholder_id"],
        ["id"],
        source_schema="public",
        referent_schema="public",
    )
    op.drop_column("number_input", "placeholder", schema="public")
    op.drop_table("association_table_dynamic_section", schema="public")
    op.drop_table("dynamic_section", schema="public")
    # ### end Alembic commands ###
