"""Add is_public field to trees

Revision ID: 004
Revises: 003
Create Date: 2026-02-01

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '004'
down_revision: Union[str, None] = '003'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # Add is_public column with default False (private by default)
    op.add_column('trees', sa.Column('is_public', sa.Boolean(), nullable=False, server_default='false'))
    op.create_index('ix_trees_is_public', 'trees', ['is_public'])

    # Make existing default trees public
    op.execute("UPDATE trees SET is_public = true WHERE is_default = true")


def downgrade() -> None:
    op.drop_index('ix_trees_is_public', table_name='trees')
    op.drop_column('trees', 'is_public')
