# auto generation of things [auto_generation] [auto_generation.assets] field = "asset_numeric_id" type = "numeric" length = 8 range_min = 10000000 range_max = 99999999 max_attempts = 10 # on what event seckel api schould try to generate auto gen value incaase client send empty value on_action = "insert" [scheduled_queries] # Single idempotent task that sets the correct state atomically to avoid double-trigger inserts [[scheduled_queries.tasks]] name = "sync_overdue_and_stolen" description = "Atomically set lending_status to Overdue (1-13 days late) or Stolen (>=14 days late) only if it changed" query = """ -- Use max lateness per asset to avoid flip-flopping due to multiple open lending rows -- Removed issue_tracker check from WHERE clause to avoid MySQL trigger conflict UPDATE assets a INNER JOIN ( SELECT lh.asset_id, MAX(DATEDIFF(CURDATE(), lh.due_date)) AS days_late FROM lending_history lh WHERE lh.return_date IS NULL AND lh.due_date IS NOT NULL GROUP BY lh.asset_id ) late ON a.id = late.asset_id SET a.lending_status = CASE WHEN a.asset_type IN ('N','B') AND late.days_late >= 14 THEN 'Stolen' WHEN a.asset_type IN ('N','B') AND late.days_late BETWEEN 1 AND 13 THEN 'Overdue' ELSE a.lending_status END WHERE a.asset_type IN ('N','B') AND ( (late.days_late >= 14 AND a.lending_status <> 'Stolen') OR (late.days_late BETWEEN 1 AND 13 AND a.lending_status <> 'Overdue') ) """ interval_minutes = 2 run_on_startup = true enabled = true