diff --git a/packages/drizzle-pkg/lib/schema/scheduler.ts b/packages/drizzle-pkg/lib/schema/scheduler.ts new file mode 100644 index 0000000..b90ccf2 --- /dev/null +++ b/packages/drizzle-pkg/lib/schema/scheduler.ts @@ -0,0 +1,42 @@ +import { sqliteTable, text, integer } from "drizzle-orm/sqlite-core"; + +export const scheduledTasks = sqliteTable("scheduled_tasks", { + id: text("id").primaryKey(), + name: text("name").notNull(), + cronExpression: text("cron_expression").notNull(), + type: text("type").notNull(), // "function" | "http" + + // function type fields + functionName: text("function_name"), + functionPayload: text("function_payload"), + + // http type fields + httpMethod: text("http_method"), + httpUrl: text("http_url"), + httpHeaders: text("http_headers"), + httpBody: text("http_body"), + + catchUp: integer("catch_up").default(0).notNull(), + enabled: integer("enabled").default(1).notNull(), + maxRetries: integer("max_retries").default(0).notNull(), + retryDelaySeconds: integer("retry_delay_seconds").default(60).notNull(), + timeoutSeconds: integer("timeout_seconds").default(300).notNull(), + + createdAt: integer("created_at", { mode: "timestamp_ms" }).defaultNow().notNull(), + updatedAt: integer("updated_at", { mode: "timestamp_ms" }) + .defaultNow() + .$onUpdate(() => new Date()) + .notNull(), +}); + +export const taskExecutionLogs = sqliteTable("task_execution_logs", { + id: text("id").primaryKey(), + taskId: text("task_id") + .notNull() + .references(() => scheduledTasks.id), + status: text("status").notNull(), // "running" | "success" | "failed" + startedAt: integer("started_at", { mode: "timestamp_ms" }).defaultNow().notNull(), + finishedAt: integer("finished_at", { mode: "timestamp_ms" }), + errorMessage: text("error_message"), + resultSummary: text("result_summary"), +});