<cfsetting showdebugoutput="false">
<cfcontent type="application/json; charset=utf-8" reset="true">

<cfscript>
// Add CategoryID column to tt_TaskTypes (Services) table
try {
    // Check if column exists
    qCheck = queryTimed("
        SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_SCHEMA = 'payfrit'
          AND TABLE_NAME = 'tt_TaskTypes'
          AND COLUMN_NAME = 'TaskCategoryID'
    ", [], { datasource: "payfrit" });

    if (qCheck.recordCount == 0) {
        queryTimed("
            ALTER TABLE tt_TaskTypes
            ADD COLUMN TaskCategoryID INT NULL
        ", [], { datasource: "payfrit" });

        writeOutput(serializeJSON({
            "OK": true,
            "MESSAGE": "Column TaskCategoryID added to tt_TaskTypes"
        }));
    } else {
        writeOutput(serializeJSON({
            "OK": true,
            "MESSAGE": "Column already exists"
        }));
    }
} catch (any e) {
    writeOutput(serializeJSON({
        "OK": false,
        "ERROR": e.message
    }));
}
</cfscript>
