"""add notes table and remove note from activity_interval

Revision ID: j3456kl7890
Revises: i2345jk6789
Create Date: 2025-12-24 12:13:00.000000

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

# revision identifiers, used by Alembic.
revision = 'j3456kl7890'
down_revision = 'i2345jk6789'
branch_labels = None
depends_on = None


def upgrade():
    """
    Create notes table and remove note column from activity_interval.
    """
    # Create notes table
    op.create_table(
        'notes',
        sa.Column('id', sa.Integer(), nullable=False),
        sa.Column('activity_interval_id', sa.JSON(), nullable=False),
        sa.Column('note', sa.String(), nullable=False),
        sa.Column('timestamp', sa.DateTime(), nullable=False),
        sa.PrimaryKeyConstraint('id')
    )
    
    # Remove note column from activity_interval
    # SQLite doesn't support DROP COLUMN directly, so we use batch_alter_table
    with op.batch_alter_table('activity_interval', schema=None) as batch_op:
        batch_op.drop_column('note')


def downgrade():
    """
    Rollback: Add note column back to activity_interval and drop notes table.
    """
    # Add note column back to activity_interval
    with op.batch_alter_table('activity_interval', schema=None) as batch_op:
        batch_op.add_column(sa.Column('note', sa.String(), nullable=True))
    
    # Drop notes table
    op.drop_table('notes')
