Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

backend-model-rules

БесплатноБез исполняемых скриптовНе проверен

Where a rule about a Toucan 2 model lives and how to write it. Hooks hold defaults, derived columns and what the row and its stored version answer, and never…

metabaseот metabase★ 50 742 звезды на GitHub

Об этом скилле

Model rules

Every writer of a :model/X row calls the model's write functions: REST endpoints, MCP and Metabot tools, the Agent API, revision revert, SerDes import, remote-sync pull, sync, the loaders, scheduled tasks. A write function takes a list and runs a number of statements that does not grow with it. Hooks run no statement, so a write of many rows never becomes a query per row.

Where a rule lives

Three layers, and a rule goes to the lowest one that can hold it:

  1. Column transforms and hooks: they hold for every writer, a plain t2/update! included.
  2. <module>/db.clj: the statements, where per-row and per-app-DB work goes.
  3. Write functions: orchestration, checks that need other rows, external calls, events.
The rule Home
Default value, also one read from a setting (a Table's humanized display_name) hook
Derived column (a Segment's table_id from its definition, updated_at) hook
Invalid combination of columns of one row, from the row and its stored version hook
Per-row state transition that is not allowed; a frozen column (no update may change it) hook, only where the rule already existed
Whether one value is valid (valid MBQL, enum, length) boundary schema: API request schema, SerDes spec :schema, revisions spec :schema; never a hook
Needs other rows or the database (parent archived, allowed Collection, cycle, uniqueness) a private check-<what> function the write function calls before the statement (see Checks)
A referenced row exists, and a FOREIGN KEY or PRIMARY KEY says so nothing: the constraint error is the outcome, and it is never caught
Depends on who is acting mi/can-*? (see Permissions)
  • A hook never calls the app DB or anything external (a warehouse, the network); a cached setting read is neither. It does not check single values: every write would repeat the boundary's work (query validation per Card write).

  • A combination check stays in the hook for every writer. Card has two: check-model-query (the type with the query: a model's native query has no variable or field filter) and check-not-native-audit-db-query (the database with the query type: no native query on the audit database).

  • A before-update hook returns the same changes for every row of one update. Toucan runs an update of a model with such a hook in three steps: one SELECT of the matching rows; the hook once per row, in memory; then one UPDATE only if every row ended with the same change map, and otherwise one UPDATE ... WHERE id = ? per row, for all rows, even those that share a change map. So a hook that runs no statement can still multiply statements:

    (t2/define-before-update :model/Channel [channel]          ; WRONG: the name differs per row
      (cond-> channel
        (false? (:active (t2/changes channel)))
        (assoc :name (format "DEACTIVATED_%d %s" (:id channel) (:name channel)))))
    ;; (t2/update! :model/Channel :id [:in ids] {:active false}) -> 1 SELECT + one UPDATE per Channel
    

    The change map Toucan compares is each row's DIFF against its stored values, so two rules follow.

    1. What the hook adds to the changes is the same for every row: a value computed from the incoming changes and constants, or ONE HoneySQL expression the database evaluates per row. It breaks with a Clojure value built from the stored row (its id, its name) and with a value added only for some rows ((when-not (:published_at stored) ...)). A hook still READS the stored row to refuse a write (frozen column, invalid combination, state transition): a guard throws or leaves the changes alone, and adds no statement.
      • A value that depends on the stored row or on another row is an expression, and this is the default: a stamp kept once set (COALESCE(initially_published_at, now())), a CASE over stored columns (a Channel's deactivated name, a Field's coercion strategy and effective type through app-db/isa), a scalar subquery on the parent (archived_directly from the Collection, a Pulse's collection_id from its Dashboard, the next position).
      • The expression is built by a function of the model's <module>/db.clj whose name ends in -clause (channel.db/deactivated-name-clause); the hook calls it and assocs the result. No HoneySQL in a model file. A building block several models share lives in metabase.models.interface.
      • SQL that differs per app DB is a case on (mdb/db-type) inside the -clause function. MySQL assigns SET left to right, so an expression never reads a column the same statement assigns before it; MySQL refuses a subquery on the table being written, so read it through a derived table. Mark a deliberate subquery ^:allow-subquery.
      • Events, returned rows and Revisions carry real values: read the rows once after the statement when the changes held an expression.
      • What stay
Полный SKILL.md на GitHub

Установить backend-model-rules в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл backend-model-rules?

Where a rule about a Toucan 2 model lives and how to write it. Hooks hold defaults, derived columns and what the row and its stored version answer, and never call the app DB; boundary schemas (API request, SerDes and revisions spec `:schema`) check single values; the write functions in the model file's Writes section take lists, hold everything that needs other rows, and publish the lifecycle events by hand; a parent's file is the only entry point to its children; `mi/can-*?` methods hold per-user rules; no read or write path runs a number of statements that grows with its rows, and `db.clj` functions partition the id lists they take. Use when adding or changing a model, a column, a hook, a write function, a schema, a permission check, an endpoint or tool that reads or writes a list of a model, a `db.clj` function that takes a list, a cascade, archiving, events, a per-model spec, or a test of any of these. Preloaded by every `*-backend-expert` agent.

Как установить скилл backend-model-rules?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл backend-model-rules запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить backend-model-rules с