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

<cfscript>
// Add TaskTypeID column to QuickTaskTemplates table if it doesn't exist
try {
    // Check if column exists
    qCheck = queryExecute("
        SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS
        WHERE TABLE_SCHEMA = 'payfrit'
          AND TABLE_NAME = 'QuickTaskTemplates'
          AND COLUMN_NAME = 'TaskTypeID'
    ", [], { datasource: "payfrit" });

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

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