/** * Add ItemCategoryID column to Items table */ response = { "OK": false }; try { // Check if column already exists qCheck = queryExecute(" SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'payfrit' AND TABLE_NAME = 'Items' AND COLUMN_NAME = 'ItemCategoryID' ", {}, { datasource: "payfrit" }); if (qCheck.recordCount > 0) { response["OK"] = true; response["MESSAGE"] = "ItemCategoryID column already exists"; } else { // Add the column queryExecute(" ALTER TABLE Items ADD COLUMN ItemCategoryID INT NULL DEFAULT 0 AFTER ItemParentItemID ", {}, { datasource: "payfrit" }); // Add index for performance try { queryExecute(" CREATE INDEX idx_items_categoryid ON Items(ItemCategoryID) ", {}, { datasource: "payfrit" }); } catch (any indexErr) { // Index might already exist } response["OK"] = true; response["MESSAGE"] = "ItemCategoryID column added successfully"; } } catch (any e) { response["ERROR"] = "server_error"; response["MESSAGE"] = e.message; response["DETAIL"] = e.detail; } writeOutput(serializeJSON(response));