"""create_condition_medication_table

Revision ID: ba57e3612c92
Revises: 36efa7257f0d
Create Date: 2025-07-11 08:39:42.138758

"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = 'ba57e3612c92'
down_revision = '36efa7257f0d'
branch_labels = None
depends_on = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('condition_medications',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('condition_id', sa.Integer(), nullable=False),
    sa.Column('medication_id', sa.Integer(), nullable=False),
    sa.Column('relevance_note', sa.String(), nullable=True),
    sa.Column('created_at', sa.DateTime(), nullable=False),
    sa.Column('updated_at', sa.DateTime(), nullable=False),
    sa.ForeignKeyConstraint(['condition_id'], ['conditions.id'], ),
    sa.ForeignKeyConstraint(['medication_id'], ['medications.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    op.drop_constraint('medications_condition_id_fkey', 'medications', type_='foreignkey')
    op.drop_column('medications', 'condition_id')
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('medications', sa.Column('condition_id', sa.INTEGER(), autoincrement=False, nullable=True))
    op.create_foreign_key('medications_condition_id_fkey', 'medications', 'conditions', ['condition_id'], ['id'])
    op.drop_table('condition_medications')
    # ### end Alembic commands ###
