"""add_phase_timing_fields

Revision ID: b021phasetiming
Revises: b020jiraworklogs
Create Date: 2026-02-17 18:00:00.000000

Add red_started_at and blue_started_at columns to the tests table
so that automatic worklogs can record real elapsed time per phase.
"""

from alembic import op

revision = "b021phasetiming"
down_revision = "b020jiraworklogs"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.execute("""
        ALTER TABLE tests
            ADD COLUMN IF NOT EXISTS red_started_at      TIMESTAMP,
            ADD COLUMN IF NOT EXISTS blue_started_at     TIMESTAMP,
            ADD COLUMN IF NOT EXISTS paused_at           TIMESTAMP,
            ADD COLUMN IF NOT EXISTS red_paused_seconds  INTEGER DEFAULT 0,
            ADD COLUMN IF NOT EXISTS blue_paused_seconds INTEGER DEFAULT 0;
    """)


def downgrade() -> None:
    op.execute("""
        ALTER TABLE tests
            DROP COLUMN IF EXISTS red_started_at,
            DROP COLUMN IF EXISTS blue_started_at,
            DROP COLUMN IF EXISTS paused_at,
            DROP COLUMN IF EXISTS red_paused_seconds,
            DROP COLUMN IF EXISTS blue_paused_seconds;
    """)
