See llms.txt for all machine-readable content.

Back to Templates

Sync and validate Google Sheets records with Postgres and Slack alerts

Quick overview

This workflow runs hourly to sync rows from a Google Sheets tab into a Postgres table, validating and normalizing data, only upserting new or changed records, soft-deleting records missing from the sheet with a safety cap, and sending run reports and failure alerts to Slack.

How it works

  1. Runs every hour (or manually with sample data) to start the sync.
  2. Reads rows from the Google Sheets document’s Records sheet (or generates sample rows for testing).
  3. Validates and normalizes each row (for example required IDs, unique IDs, email format, allowed statuses, and numeric amounts), and splits invalid rows into a rejects list.
  4. Fetches current external_id, row_hash, and deletion status from the Postgres records table and compares it to the cleaned sheet data to plan upserts and soft deletes.
  5. Upserts only new, changed, or previously deleted (restored) rows into Postgres and stamps them with updated_at while clearing deleted_at.
  6. Marks rows that are present in Postgres but missing from the sheet as soft-deleted by setting deleted_at, unless the missing share exceeds the configured safety threshold.
  7. Logs per-run counts to the Postgres sync_runs table and posts a Slack report when there are rejects, deletes are blocked, or reporting is forced, while any step failure posts a Slack alert.

Setup

  1. Create the Postgres tables records and sync_runs (and ensure records includes the columns used by the workflow, including external_id, row_hash, updated_at, and deleted_at).
  2. Add credentials for Google Sheets, Postgres, and Slack, and select them in the corresponding nodes.
  3. Update the Google Sheets document URL/ID and the Records sheet name if needed, and ensure your column headers match the fields expected by the validation step (id, name, email, status, amount).
  4. Set your Slack channel and validation/safety options (allowed statuses, soft_delete_missing, max_delete_share, and report_when_clean) in the workflow configuration values.