Skip to main content

cron_migration_sql

Function cron_migration_sql 

Source
pub const fn cron_migration_sql() -> &'static str
Expand description

Returns the SQL DDL to create the cron state table and indexes.

The DDL uses IF NOT EXISTS for idempotency — running it multiple times is safe and produces no errors.

§Table Schema

ColumnTypeNotes
pk_cron_stateBIGINT GENERATED ALWAYS AS IDENTITYTrinity-style PK
function_nameTEXT NOT NULLFunction with the cron trigger
cron_exprTEXT NOT NULLCron expression that fired
last_fired_atTIMESTAMPTZ NOT NULLWhen the cron last fired
next_fire_atTIMESTAMPTZComputed next fire time (optional)
fire_countBIGINT NOT NULL DEFAULT 0Total number of fires
updated_atTIMESTAMPTZ NOT NULL DEFAULT now()Last row update

§Example

let sql = fraiseql_functions::migrations::cron_migration_sql();
assert!(sql.contains("_fraiseql_cron_state"));