"""add tax_amount to invoices_line_items

Revision ID: adfb43108aff
Revises: hwui002c
Create Date: 2026-04-02

cost and upcharge already exist in the DB. Only tax_amount is missing.
Uses IF NOT EXISTS for all three so the migration is safe to re-run.
"""

from alembic import op
from sqlalchemy import text

revision = "adfb43108aff"
down_revision = "hwui002c"
branch_labels = None
depends_on = None


def upgrade() -> None:
    conn = op.get_bind()
    conn.execute(text(
        "ALTER TABLE invoices_line_items ADD COLUMN IF NOT EXISTS cost FLOAT DEFAULT 0.0"
    ))
    conn.execute(text(
        "ALTER TABLE invoices_line_items ADD COLUMN IF NOT EXISTS upcharge FLOAT DEFAULT 0.0"
    ))
    conn.execute(text(
        "ALTER TABLE invoices_line_items ADD COLUMN IF NOT EXISTS tax_amount FLOAT DEFAULT 0.0"
    ))


def downgrade() -> None:
    op.drop_column("invoices_line_items", "tax_amount")
