"""auto

Revision ID: e34cff15a95e
Revises: 5c85ebc9451b
Create Date: 2025-06-06 07:34:33.699976

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

# revision identifiers, used by Alembic.
revision = 'e34cff15a95e'
down_revision = '5c85ebc9451b'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('featured_images', sa.Column('media_id', sa.Integer(), nullable=False))
    op.drop_constraint(op.f('featured_images_ibfk_1'), 'featured_images', type_='foreignkey')
    op.create_foreign_key(None, 'featured_images', 'media', ['media_id'], ['id'])
    op.drop_column('featured_images', 'submission_image_id')
    op.add_column('image_hearts', sa.Column('media_id', sa.Integer(), nullable=False))
    op.drop_constraint(op.f('image_hearts_ibfk_1'), 'image_hearts', type_='foreignkey')
    op.create_foreign_key(None, 'image_hearts', 'media', ['media_id'], ['id'])
    op.drop_column('image_hearts', 'submission_image_id')
    op.add_column('media', sa.Column('uploader_id', sa.Integer(), nullable=False))
    op.add_column('media', sa.Column('submission_id', sa.Integer(), nullable=True))
    op.drop_constraint(op.f('media_ibfk_2'), 'media', type_='foreignkey')
    op.drop_constraint(op.f('media_ibfk_3'), 'media', type_='foreignkey')
    op.create_foreign_key(None, 'media', 'users', ['uploader_id'], ['id'])
    op.create_foreign_key(None, 'media', 'submissions', ['submission_id'], ['id'])
    op.drop_column('media', 'update_id')
    op.drop_column('media', 'plant_id')
    op.add_column('submissions', sa.Column('submission_type', sa.String(length=50), nullable=False))
    op.add_column('submissions', sa.Column('price', sa.Float(), nullable=True))
    op.add_column('submissions', sa.Column('source', sa.String(length=255), nullable=True))
    op.alter_column('submissions', 'plant_name',
               existing_type=mysql.VARCHAR(length=100),
               nullable=True)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('submissions', 'plant_name',
               existing_type=mysql.VARCHAR(length=100),
               nullable=False)
    op.drop_column('submissions', 'source')
    op.drop_column('submissions', 'price')
    op.drop_column('submissions', 'submission_type')
    op.add_column('media', sa.Column('plant_id', mysql.INTEGER(), autoincrement=False, nullable=True))
    op.add_column('media', sa.Column('update_id', mysql.INTEGER(), autoincrement=False, nullable=True))
    op.drop_constraint(None, 'media', type_='foreignkey')
    op.drop_constraint(None, 'media', type_='foreignkey')
    op.create_foreign_key(op.f('media_ibfk_3'), 'media', 'plant_updates', ['update_id'], ['id'])
    op.create_foreign_key(op.f('media_ibfk_2'), 'media', 'plant', ['plant_id'], ['id'])
    op.drop_column('media', 'submission_id')
    op.drop_column('media', 'uploader_id')
    op.add_column('image_hearts', sa.Column('submission_image_id', mysql.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'image_hearts', type_='foreignkey')
    op.create_foreign_key(op.f('image_hearts_ibfk_1'), 'image_hearts', 'submission_images', ['submission_image_id'], ['id'])
    op.drop_column('image_hearts', 'media_id')
    op.add_column('featured_images', sa.Column('submission_image_id', mysql.INTEGER(), autoincrement=False, nullable=False))
    op.drop_constraint(None, 'featured_images', type_='foreignkey')
    op.create_foreign_key(op.f('featured_images_ibfk_1'), 'featured_images', 'submission_images', ['submission_image_id'], ['id'])
    op.drop_column('featured_images', 'media_id')
    # ### end Alembic commands ###
