#!/usr/bin/env python3
"""
Direct database migration: add opening_balance column to customers table
"""
from app.core.database import engine
from sqlalchemy import text


def migrate():
    with engine.connect() as conn:
        result = conn.execute(text(
            "SELECT column_name FROM information_schema.columns "
            "WHERE table_name='customers' AND column_name='opening_balance'"
        ))
        exists = result.fetchone()
        if exists:
            print("opening_balance column already exists — nothing to do.")
        else:
            conn.execute(text(
                "ALTER TABLE customers ADD COLUMN opening_balance NUMERIC(15,2) NULL DEFAULT 0.0"
            ))
            conn.commit()
            print("opening_balance column added successfully.")


if __name__ == "__main__":
    migrate()
