Command Palette

Search for a command to run...

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

backend-worktree-rules

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

Rules for remote sync worktrees in the app DB. Covers which tables get `worktree_id`, its foreign and unique keys, the `:hook/worktree-id` model trait…

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

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

Remote sync worktrees

A worktree is a checkout of a remote sync branch whose content lives in the same tables as the main app, told apart by worktree_id → remote_sync_worktree (id). Worktree 1, mdb/default-worktree-id, is the main app. The schema is the same on H2, PostgreSQL and MySQL/MariaDB.

Which tables get worktree_id

metabase.app-db.worktree-test decides every app DB table, each test with its own list:

  1. the tables of synced models (remote-sync/synced-models) have worktree_id and their models derive :hook/worktree-id;
  2. every other table that reaches one of them through a chain of foreign keys does too, but for its allowlist (metabot, metabot_prompt, permissions, sandboxes and tenant, which are of the main app only, shared across worktrees like data permissions);
  3. every remaining table has an explicit decision: :scoped (column and hook, e.g. logs and polymorphic references to content such as revision or view_log), :unscoped (neither, e.g. warehouse metadata, users, groups, settings, Metabot, transform jobs), or :worktree-reference (the column without the hook, remote_sync_worktree_user, where it is the user's checkout).

A new table fails the test until it lands in one of these, so decide in the same change.

Adding the column

Follow resources/migrations/2026/20261128_remote_sync_worktrees.yaml, which works on every app DB:

  • worktree_id INTEGER DEFAULT 1 NOT NULL;
  • idx_<table>_worktree_id, created before the foreign key so that MySQL makes no index of its own;
  • fk_<table>_worktree_id → remote_sync_worktree (id) ON DELETE CASCADE, logs included, which a deleted worktree takes with it; a job that sweeps such rows by age, a cleanup or a run timeout, takes :worktree-scope :each;
  • every constraint and index named explicitly (uq_, fk_, idx_), at most 63 characters.

Keys

A reference between two worktree tables is a plain foreign key, with no composite one on worktree_id, which could not hold the same way for nullable references; an index on (worktree_id, <column>) serves the queries that keep to a worktree. That a row references only rows of its own worktree is the write function's check: it reads the referenced rows through its db.clj, in the worktree it writes in, before the statement.

Every unique key but the primary key ends with worktree_id, since a worktree's copy repeats entity_id, names and paths. Every app DB constraint has a name, on H2 too. On H2, dropping a unique key hands its index to a foreign key on the same leading column, which keeps the old uniqueness: drop that foreign key first and add it again after the new key. metabase.app-db.schema-worktrees-test checks these rules, and that v_worktree_table/v_worktree_field have the columns of their tables plus worktree_id.

Models and upserts

A model of a table with worktree_id derives :hook/worktree-id (metabase.models.interface), which marks the table for the sandbox and leaves worktree_id out of the rows read through the model, so no model or API schema lists it. The sandbox writes worktree_id into every inserted row (callers never pass it) and throws when a write sets another value. A table with worktree_id and no model gets one in <module>/models/<table>.clj.

A raw upsert lists worktree_id among its key columns, since ON CONFLICT names the whole unique key; the sandbox writes its value.

Scope and sandbox

metabase.app-db.worktree/*scope* is the worktree a thread works in: the default one by default, another one, or every worktree at once. Bind it with mdb/with-worktree-scope and a worktree id, mdb/with-default-worktree-scope or mdb/with-all-worktrees-scope; requests bind it from remote_sync_worktree_user or the X-Metabase-Worktree-Id header, and every worktree while no worktree but the default one exists. Setup, migrations and the app DB copy run in every worktree.

Every Quartz job (task/defjob) names its :worktree-scope: :main runs it in the default worktree, the main app, and :each runs it once in each worktree, the default one first, for a sweep of rows every worktree keeps for itself (log cleanups, run timeouts and reapers, dependency analysis). No job runs in the worktree that scheduled it, so a feature a worktree can't run on its own schedule, such as alerts, subscriptions, model indexes or transforms, is refused there, or ignored, as model persistence is.

Every Honey SQL query a model compiles goes through sandbox-worktree-query (metabase.app-db.query), which never queries: it gives funnysql/sandbox-query a worktree_id row filter for each hooked table, plus, in a worktree other than the default one, v_worktree_table/v_worktree_field in place of metabase_table/metabase_field. The sandbox filters reads (FROM, joins, subqueries, CTEs, unions), UPDATE and DELETE, and MERGE ON/KEY, and writes the value into inserted rows. It throws for [:param ...] value

Полный SKILL.md на GitHub

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

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

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

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

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

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

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

FAQ

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

Rules for remote sync worktrees in the app DB. Covers which tables get `worktree_id`, its foreign and unique keys, the `:hook/worktree-id` model trait, upserts, and the coverage test. Use when adding or changing an app DB table, column, foreign key, unique key or upsert, or a model of a table with `worktree_id`. Preloaded by every `*-backend-expert` agent.

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

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

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

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

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

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