"""auto

Revision ID: 761d0f8be3ff
Revises: ad9ea9d31b58
Create Date: 2025-06-05 04:18:09.403526

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

# revision identifiers, used by Alembic.
revision = '761d0f8be3ff'
down_revision = 'ad9ea9d31b58'
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('plant_lineage')
    op.add_column('plant', sa.Column('updated_at', sa.DateTime(), nullable=True))
    op.drop_column('plant', 'transferred')
    op.drop_column('plant', 'status')
    op.drop_column('plant', 'is_verified')
    op.drop_column('plant', 'graph_node_id')
    op.drop_column('plant', 'notes')
    op.add_column('plant_common_name', sa.Column('created_at', sa.DateTime(), nullable=True))
    op.alter_column('plant_common_name', 'name',
               existing_type=mysql.VARCHAR(length=255),
               type_=sa.String(length=128),
               existing_nullable=False)
    op.add_column('plant_ownership_log', sa.Column('date_acquired', sa.DateTime(), nullable=True))
    op.add_column('plant_ownership_log', sa.Column('transferred', sa.Boolean(), nullable=False))
    op.add_column('plant_ownership_log', sa.Column('graph_node_id', sa.String(length=255), nullable=True))
    op.add_column('plant_ownership_log', sa.Column('is_verified', sa.Boolean(), nullable=False))
    op.drop_column('plant_ownership_log', 'start_time')
    op.drop_column('plant_ownership_log', 'transfer_note')
    op.drop_column('plant_ownership_log', 'end_time')
    op.add_column('plant_scientific_name', sa.Column('created_at', sa.DateTime(), nullable=True))
    op.alter_column('plant_scientific_name', 'name',
               existing_type=mysql.VARCHAR(length=255),
               type_=sa.String(length=256),
               existing_nullable=False)
    op.alter_column('tag', 'name',
               existing_type=mysql.VARCHAR(length=255),
               type_=sa.String(length=128),
               existing_nullable=False)
    # ### end Alembic commands ###


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column('tag', 'name',
               existing_type=sa.String(length=128),
               type_=mysql.VARCHAR(length=255),
               existing_nullable=False)
    op.alter_column('plant_scientific_name', 'name',
               existing_type=sa.String(length=256),
               type_=mysql.VARCHAR(length=255),
               existing_nullable=False)
    op.drop_column('plant_scientific_name', 'created_at')
    op.add_column('plant_ownership_log', sa.Column('end_time', mysql.DATETIME(), nullable=True))
    op.add_column('plant_ownership_log', sa.Column('transfer_note', mysql.TEXT(), nullable=True))
    op.add_column('plant_ownership_log', sa.Column('start_time', mysql.DATETIME(), nullable=False))
    op.drop_column('plant_ownership_log', 'is_verified')
    op.drop_column('plant_ownership_log', 'graph_node_id')
    op.drop_column('plant_ownership_log', 'transferred')
    op.drop_column('plant_ownership_log', 'date_acquired')
    op.alter_column('plant_common_name', 'name',
               existing_type=sa.String(length=128),
               type_=mysql.VARCHAR(length=255),
               existing_nullable=False)
    op.drop_column('plant_common_name', 'created_at')
    op.add_column('plant', sa.Column('notes', mysql.TEXT(), nullable=True))
    op.add_column('plant', sa.Column('graph_node_id', mysql.VARCHAR(length=255), nullable=True))
    op.add_column('plant', sa.Column('is_verified', mysql.TINYINT(display_width=1), autoincrement=False, nullable=False))
    op.add_column('plant', sa.Column('status', mysql.VARCHAR(length=50), nullable=False))
    op.add_column('plant', sa.Column('transferred', mysql.TINYINT(display_width=1), autoincrement=False, nullable=True))
    op.drop_column('plant', 'updated_at')
    op.create_table('plant_lineage',
    sa.Column('id', mysql.INTEGER(), autoincrement=True, nullable=False),
    sa.Column('child_plant_id', mysql.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('parent_plant_id', mysql.INTEGER(), autoincrement=False, nullable=False),
    sa.Column('type', mysql.VARCHAR(length=50), nullable=False),
    sa.ForeignKeyConstraint(['child_plant_id'], ['plant.id'], name=op.f('plant_lineage_ibfk_1')),
    sa.ForeignKeyConstraint(['parent_plant_id'], ['plant.id'], name=op.f('plant_lineage_ibfk_2')),
    sa.PrimaryKeyConstraint('id'),
    mysql_collate='utf8mb4_0900_ai_ci',
    mysql_default_charset='utf8mb4',
    mysql_engine='InnoDB'
    )
    # ### end Alembic commands ###
