db-migration

db-migration is a command for Claude Code from YuDefine/nuxt-supabase-starter. It costs 12 tokens per session (1,387 once invoked), scanned A, original, MIT.

A command workflow for creating Supabase database migrations, which are versioned changes to a database's tables, fields, functions, or security rules. It also describes security and testing checks for those changes.

In plain words
What is it for?
Use it when adding or changing Supabase tables, columns, functions, or RLS policies, then testing the migration and generating database types through the project's configured commands.
Why use it?
It provides a repeatable process for making database changes while following project rules for schemas, database functions, and row-level security (RLS), which controls who can access each row.

Command for Claude Code

Written for Claude Code: $ARGUMENTS substitution. Also seen: mentions CLAUDE.md.

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 commands/yudefine/nuxt-supabase-starter/db-migration
Clone the repo
git clone --depth 1 https://github.com/YuDefine/nuxt-supabase-starter

Made for: Claude Code.

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 db-migration

README.md
[![agentmods](https://agentmods.dev/badge/commands/yudefine/nuxt-supabase-starter/db-migration.svg)](https://agentmods.dev/commands/yudefine/nuxt-supabase-starter/db-migration)
Your own site
<a href="https://agentmods.dev/commands/yudefine/nuxt-supabase-starter/db-migration"><img src="https://agentmods.dev/badge/commands/yudefine/nuxt-supabase-starter/db-migration.svg" alt="Measured on agentmods" height="20"></a>
Per session 12 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,387 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. 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.1 $0.00012 $0.01387
Opus 5 $0.00006 $0.00694
Sonnet 5 $0.00002 $0.00277
Haiku 4.5 $0.00001 $0.00139

Measured 2d ago against content hash 7af1b73d0d3c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

db-migration scanned grade A with 0 findings 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 2d 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.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

template/.claude/commands/db-migration.md · 146 lines

How it starts

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

User Input

$ARGUMENTS

Outline

建立新的 Supabase migration,確保符合 CLAUDE.md 中的所有規範。

Step 1: 確認需求

詢問使用者要建立什麼樣的 migration:

  • 新增表格?
  • 修改欄位?
  • 建立函式?
  • 新增 RLS 政策?

Step 2: 建立 Migration 檔案

使用 Supabase CLI 建立 migration(禁止手動建立 .sql 檔案):

supabase migration new <description_in_snake_case>

Step 3: 撰寫 Migration 內容

根據需求撰寫 SQL,必須遵守以下規範

函式規範(CRITICAL)
-- ✅ 正確:search_path 必須是空字串
CREATE OR REPLACE FUNCTION schema_name.function_name()
RETURNS return_type
LANGUAGE plpgsql
SECURITY DEFINER
SET search_path = ''  -- 必須是空字串!
AS $$
BEGIN
  -- 使用完整路徑:schema_name.table_name
  SELECT * FROM core.users WHERE id = auth.uid();
END;
$$;
-- ❌ 禁止:任何其他 search_path 值
SET search_path = public, pg_temp  -- 絕對禁止!
SET search_path = public           -- 禁止!
Schema 規範
  • 使用正確的 schema 前綴(如 public.core.,或專案自訂業務 schema)
  • 所有表格/函式引用使用完整路徑(避免裸表名觸發 search_path resolution)

Step 4: 本地測試與類型產生(自動)

依序執行以下步驟,任何步驟失敗則停止並顯示錯誤。MUST 透過 package.json 偵測 consumer 是走遠端 wrapper(pnpm db:*,含 existing-server / self-hosted)還是本機 Docker。NEVER 看到遠端 wrapper 就改跑本機 supabase start

# 從 package.json 讀 types 路徑(若有自訂);fallback 到 conventional locations
# 避開頂層 return(Node script 不允許)— 用 if/else 與 .find()
TYPES=$(node -e "
  const fs = require('fs');
  const pkg = require('./package.json');
  const custom = pkg.config && pkg.config.dbTypesPath;
  const candidates = [
    'packages/core/app/types/database.types.ts',
    'app/types/database.types.ts',
    'shared/types/database.types.ts',
    'src/types/database.types.ts',
  ];
  const path = custom || candidates.find(function(p) { return fs.existsSync(p); }) || 'app/types/database.types.ts';
  console.log(path);
")

USE_DB_WRAPPER=$(node -e "process.exit(require('./package.json').scripts?.['db:reset'] ? 0 : 1)" 2>/dev/null && echo yes || echo no)

if [ "$USE_DB_WRAPPER" = yes ]; then
  # 遠端 / existing-server:走 pnpm db:*(wrapper 會擋本機 Docker;db:reset 內部跑 db:types 寫到 $TYPES)
  pnpm db:reset
  pnpm db:lint        # 安全檢查(必須零警告)
  pnpm typecheck
else
  # 本機 Docker(this-machine;沒有 pnpm db:reset wrapper)
  supabase db reset
  supabase db lint --level warning
  # 直接重導向到 $TYPES — 不用 tee(pipeline 會吞 supabase gen types 失敗狀態)
  supabase gen types typescript --local > "$TYPES"
  pnpm typecheck
fi

Read the full file on GitHub · 146 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. 2d ago Changed 7af1b73d0d3c
  2. 6d ago First seen · 146 lines · 12 tokens per session scan A c65b8e219708

Subscribe to this mod's changes

db-migration is a command published in the GitHub repository YuDefine/nuxt-supabase-starter (45 stars, last pushed today), licensed MIT. It adds 12 tokens to every session and 1,387 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.