New to Kestra?
Use blueprints to kickstart your first workflows.
Audit SQLite foreign key constraints, detect orphan records with PRAGMA foreign_key_check, and alert on referential integrity failures.
Automate referential integrity enforcement across SQLite embedded databases by running SQLite's native PRAGMA foreign_key_check;. SQLite disables foreign key constraint enforcement by default (PRAGMA foreign_keys = OFF), and bulk batch loads, schema migrations, or legacy scripts often introduce orphan child records without triggering write-time errors. This sentinel workflow periodically audits the entire database, evaluates constraint health, sends granular Slack notifications listing the exact tables and offending row IDs, and fails execution when referential integrity is compromised.
Schedule trigger periodically invokes the audit on a 12-hour cadence (shipped disabled by default).probe_foreign_key_check uses io.kestra.plugin.jdbc.sqlite.Query to connect via JDBC (jdbc:sqlite:<path>) and run PRAGMA foreign_key_check; with fetchType: FETCH. When the database has no broken foreign keys, SQLite returns zero rows. When broken references exist, it returns one row per violation containing the child table name, rowid, parent table name, and foreign key index.evaluate_integrity (io.kestra.plugin.core.flow.If) inspects the row count in {{ outputs.probe_foreign_key_check.size }}:0: Runs log_integrity_healthy to record clean referential health.0: Sends an alert to Slack via io.kestra.plugin.slack.notifications.SlackIncomingWebhook formatting the offending child tables and row IDs, followed by fail_on_violations (io.kestra.plugin.core.execution.Fail) to trigger incident workflows.log_audit_summary emits a final structured log with the total violation count.errors handler catches unexpected connection or permission failures and notifies on-call teams.Standalone cron jobs running custom Python or Bash scripts to check database integrity often fail silently, lack centralized audit logging, and require custom webhook notification code. Kestra provides declarative, version-controlled orchestration with native JDBC query execution, dynamic Pebble expressions, built-in retry handling, and error routing. With Kestra, database integrity verification becomes an observable, auditable workflow integrated directly into your deployment and monitoring pipeline.
SLACK_WEBHOOK_URL: Slack Incoming Webhook URL used to post integrity violation alerts and runtime failure notifications.SLACK_WEBHOOK_URL.sqlite_db_path input (e.g., /tmp/sqlite-data.db).periodic_foreign_key_audit trigger to establish recurring scheduled audits.PRAGMA foreign_key_check(<table_name>); to optimize audits on large databases.