custom-sql-to-data-model

custom-sql-to-data-model is a cursor rule for coding agents from twells89/sigma-migration-skills. It costs 65 tokens per session (6,709 once invoked), scanned A, original, MIT.

A migration rule that finds custom SQL inside Sigma workbooks and promotes each unique query into a reusable Sigma data model.

In plain words
What is it for?
Use it to scan workbooks, reuse or create data models, replace their SQL sources, and audit the resulting formulas.
Why use it?
It removes repeated ad-hoc SQL and updates workbooks to use shared models instead, while checking for formula references that need repair.

Cursor rule

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/twells89/sigma-migration-skills/custom-sql-to-data-model
Clone the repo
git clone --depth 1 https://github.com/twells89/sigma-migration-skills

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for custom-sql-to-data-model

README.md
[![agentmods](https://agentmods.dev/badge/rules/twells89/sigma-migration-skills/custom-sql-to-data-model.svg)](https://agentmods.dev/rules/twells89/sigma-migration-skills/custom-sql-to-data-model)
Your own site
<a href="https://agentmods.dev/rules/twells89/sigma-migration-skills/custom-sql-to-data-model"><img src="https://agentmods.dev/badge/rules/twells89/sigma-migration-skills/custom-sql-to-data-model.svg" alt="Measured on agentmods" height="20"></a>
Per session 65 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 6,709 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00065 $0.06709
Opus 5 $0.00032 $0.03354
Sonnet 5 $0.00013 $0.01342
Haiku 4.5 $0.00006 $0.00671

Measured 5d ago against content hash f235f76cda06, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

custom-sql-to-data-model scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 5d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

curl -s -X POST \
plugins/sigma-authoring/skills/custom-sql-to-data-model/generated/cursor/rules/custom-sql-to-data-model.mdc · 601 lines

How it starts

The opening of the file, as written. The whole thing — 601 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Scan Sigma workbooks for custom SQL elements, dedupe across workbooks, build or reuse Sigma data models, then repoint the workbooks via the v3alpha :swapSources endpoint. Use when you want to find ad-hoc SQL in workbooks and promote it to one reusable data model per unique query.

Custom SQL → Data Model

End-to-end flow:

  1. Scan workbooks for source.kind: "sql" elements (Phase 1).
  2. Scan data models to index every existing SQL or warehouse-table source (Phase 1.5).
  3. Group manifest entries by normalized SQL; for each group, decide reuse an existing DM element or build a new one (Phase 1.5 → plan).
  4. Build DMs only for the to-build groups (Phase 2 / 3 / 4).
  5. Drive :swapSources from the plan, one workbook at a time (Phase 5).
  6. Audit and repair residual [Prefix/SNAKE_CASE] formulas left behind by Sigma's auto-match (Phase 6).

The key win versus the legacy GET/mutate/PUT approach: one workbook with N SQL elements is one API call with N entries in sourceMapping, and the auto-match handles formula rewrites — except for the rough edges Phase 6 catches.


Prerequisites

Required env vars: SIGMA_BASE_URL, SIGMA_CLIENT_ID, SIGMA_CLIENT_SECRET

Default (shell-neutral, works in bash/zsh/PowerShell/cmd): mint a token with the stdlib-only Python script and let scripts/lib/sigma_rest.rb pick it up automatically from auth.json — no eval, no shell-specific syntax:

python3 scripts/get_token.py --workdir /tmp/custom-sql-run

This writes /tmp/custom-sql-run/auth.json (mode 0600). Every Ruby script in this skill checks $SIGMA_WORKDIR/auth.json (or ./auth.json) before falling back to a fresh client-credentials exchange, so point SIGMA_WORKDIR at the same directory (or run from inside it) and every subsequent ruby scripts/*.rb invocation authenticates without any shell-specific token plumbing:

Read the full file on GitHub · 601 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 5d ago First seen · 601 lines · 65 tokens per session scan A f235f76cda06

Subscribe to this mod's changes

custom-sql-to-data-model is a cursor rule published in the GitHub repository twells89/sigma-migration-skills (14 stars, last pushed yesterday), licensed MIT. It adds 65 tokens to every session and 6,709 once invoked, about $0.0003 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.