"""add habit and habit_log

Revision ID: 507e07c62c41
Revises: 50dd872439b9
Create Date: 2026-07-04 00:52:25.442447

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '507e07c62c41'
down_revision: Union[str, Sequence[str], None] = '50dd872439b9'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    """Upgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.create_table('habit',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('name', sa.String(), nullable=False),
    sa.Column('description', sa.Text(), nullable=True),
    sa.Column('frequency', sa.Enum('daily', 'weekly', 'custom', name='habitfrequency'), nullable=False),
    sa.Column('days_of_week', sa.JSON(), nullable=True),
    sa.Column('time_of_day', sa.Time(), nullable=True),
    sa.Column('location', sa.String(), nullable=True),
    sa.Column('current_streak', sa.Integer(), nullable=False),
    sa.Column('longest_streak', sa.Integer(), nullable=False),
    sa.Column('last_completed_date', sa.Date(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_table('habit_log',
    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
    sa.Column('habit_id', sa.Integer(), nullable=False),
    sa.Column('completed_date', sa.Date(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('(CURRENT_TIMESTAMP)'), nullable=False),
    sa.ForeignKeyConstraint(['habit_id'], ['habit.id'], ),
    sa.PrimaryKeyConstraint('id')
    )
    # ### end Alembic commands ###


def downgrade() -> None:
    """Downgrade schema."""
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_table('habit_log')
    op.drop_table('habit')
    # ### end Alembic commands ###
