feat: add script field to ScheduledTask type and database layer
Adds optional `script` field to the ScheduledTask interface, with a migration for existing DBs and full support in createTask/updateTask. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
20
src/db.ts
20
src/db.ts
@@ -93,6 +93,15 @@ function createSchema(database: Database.Database): void {
|
|||||||
/* column already exists */
|
/* column already exists */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add script column if it doesn't exist (migration for existing DBs)
|
||||||
|
try {
|
||||||
|
database.exec(
|
||||||
|
`ALTER TABLE scheduled_tasks ADD COLUMN script TEXT`,
|
||||||
|
);
|
||||||
|
} catch {
|
||||||
|
/* column already exists */
|
||||||
|
}
|
||||||
|
|
||||||
// Add is_bot_message column if it doesn't exist (migration for existing DBs)
|
// Add is_bot_message column if it doesn't exist (migration for existing DBs)
|
||||||
try {
|
try {
|
||||||
database.exec(
|
database.exec(
|
||||||
@@ -368,14 +377,15 @@ export function createTask(
|
|||||||
): void {
|
): void {
|
||||||
db.prepare(
|
db.prepare(
|
||||||
`
|
`
|
||||||
INSERT INTO scheduled_tasks (id, group_folder, chat_jid, prompt, schedule_type, schedule_value, context_mode, next_run, status, created_at)
|
INSERT INTO scheduled_tasks (id, group_folder, chat_jid, prompt, script, schedule_type, schedule_value, context_mode, next_run, status, created_at)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
`,
|
`,
|
||||||
).run(
|
).run(
|
||||||
task.id,
|
task.id,
|
||||||
task.group_folder,
|
task.group_folder,
|
||||||
task.chat_jid,
|
task.chat_jid,
|
||||||
task.prompt,
|
task.prompt,
|
||||||
|
task.script || null,
|
||||||
task.schedule_type,
|
task.schedule_type,
|
||||||
task.schedule_value,
|
task.schedule_value,
|
||||||
task.context_mode || 'isolated',
|
task.context_mode || 'isolated',
|
||||||
@@ -410,7 +420,7 @@ export function updateTask(
|
|||||||
updates: Partial<
|
updates: Partial<
|
||||||
Pick<
|
Pick<
|
||||||
ScheduledTask,
|
ScheduledTask,
|
||||||
'prompt' | 'schedule_type' | 'schedule_value' | 'next_run' | 'status'
|
'prompt' | 'script' | 'schedule_type' | 'schedule_value' | 'next_run' | 'status'
|
||||||
>
|
>
|
||||||
>,
|
>,
|
||||||
): void {
|
): void {
|
||||||
@@ -421,6 +431,10 @@ export function updateTask(
|
|||||||
fields.push('prompt = ?');
|
fields.push('prompt = ?');
|
||||||
values.push(updates.prompt);
|
values.push(updates.prompt);
|
||||||
}
|
}
|
||||||
|
if (updates.script !== undefined) {
|
||||||
|
fields.push('script = ?');
|
||||||
|
values.push(updates.script || null);
|
||||||
|
}
|
||||||
if (updates.schedule_type !== undefined) {
|
if (updates.schedule_type !== undefined) {
|
||||||
fields.push('schedule_type = ?');
|
fields.push('schedule_type = ?');
|
||||||
values.push(updates.schedule_type);
|
values.push(updates.schedule_type);
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ export interface ScheduledTask {
|
|||||||
group_folder: string;
|
group_folder: string;
|
||||||
chat_jid: string;
|
chat_jid: string;
|
||||||
prompt: string;
|
prompt: string;
|
||||||
|
script?: string | null;
|
||||||
schedule_type: 'cron' | 'interval' | 'once';
|
schedule_type: 'cron' | 'interval' | 'once';
|
||||||
schedule_value: string;
|
schedule_value: string;
|
||||||
context_mode: 'group' | 'isolated';
|
context_mode: 'group' | 'isolated';
|
||||||
|
|||||||
Reference in New Issue
Block a user