This repository has been archived on 2026-03-21. You can view files and clone it, but cannot push or open issues or pull requests.
payfrit-biz/api/admin/scheduledTasks/setup.cfm
John 16a3b7c9a3 Replace queryExecute with queryTimed across all endpoints for perf tracking
Converts 200+ endpoint files to use queryTimed() wrapper which tracks
DB query count and execution time. Restores perf dashboard files that
were accidentally moved to _scripts/. Includes portal UI updates.
2026-02-02 00:28:37 -08:00

69 lines
2.1 KiB
Text

<cfsetting showdebugoutput="false">
<cfsetting enablecfoutputonly="true">
<cfcontent type="application/json; charset=utf-8" reset="true">
<cfscript>
// Creates ScheduledTaskDefinitions table if not exists
// Public endpoint for setup
function apiAbort(required struct payload) {
writeOutput(serializeJSON(payload));
abort;
}
try {
// Create ScheduledTaskDefinitions table
queryTimed("
CREATE TABLE IF NOT EXISTS ScheduledTaskDefinitions (
ID INT AUTO_INCREMENT PRIMARY KEY,
BusinessID INT NOT NULL,
Name VARCHAR(100) NOT NULL,
TaskCategoryID INT NULL,
TaskTypeID INT NULL,
Title VARCHAR(255) NOT NULL,
Details TEXT NULL,
CronExpression VARCHAR(100) NOT NULL,
ScheduleType VARCHAR(20) DEFAULT 'cron',
IntervalMinutes INT NULL,
IsActive BIT(1) DEFAULT b'1',
LastRunOn DATETIME NULL,
NextRunOn DATETIME NULL,
CreatedOn DATETIME DEFAULT CURRENT_TIMESTAMP,
CreatedByUserID INT NULL,
INDEX idx_business (BusinessID),
INDEX idx_active_next (IsActive, NextRunOn)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4
", [], { datasource: "payfrit" });
// Add new columns if they don't exist (for existing tables)
try {
queryTimed("
ALTER TABLE ScheduledTaskDefinitions
ADD COLUMN ScheduleType VARCHAR(20) DEFAULT 'cron' AFTER CronExpression
", [], { datasource: "payfrit" });
} catch (any e) {
// Column likely already exists
}
try {
queryTimed("
ALTER TABLE ScheduledTaskDefinitions
ADD COLUMN IntervalMinutes INT NULL AFTER ScheduleType
", [], { datasource: "payfrit" });
} catch (any e) {
// Column likely already exists
}
apiAbort({
"OK": true,
"MESSAGE": "ScheduledTaskDefinitions table created/verified with interval support"
});
} catch (any e) {
apiAbort({
"OK": false,
"ERROR": "server_error",
"MESSAGE": e.message
});
}
</cfscript>