DA

Database Rules

Defines mandatory rules for data access, migrations, and RLS to maintain data integrity in Supabase projects.

Install

mkdir -p .claude/skills/database-rules && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/15798" && unzip -o skill.zip -d .claude/skills/database-rules && rm skill.zip

Installs to .claude/skills/database-rules

Activation

This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.

Supabase、RLS、マイグレーション、およびデータ操作に関する絶対ルール
39 charsno explicit “when” trigger
Advanced

Key capabilities

  • Enforce `packages/shared/src/types/` as the single source of truth for schema and types.
  • Mandate the use of `packages/shared/src/dal` for all DB access logic.
  • Ensure date handling uses `YYYY-MM-DD` plain strings to avoid timezone issues.
  • Implement fractional indexing for list reordering.
  • Require Row Level Security (RLS) on all tables.

How it works

The skill enforces a set of absolute rules for Supabase, RLS, migrations, and data manipulation, ensuring consistency, security, and performance.

Inputs & outputs

You give it
A request to perform database operations, design schema, or implement migrations within a Supabase project.
You get back
Database operations and schema changes that adhere to strict architectural patterns, security rules, and data integrity principles.

When to use Database Rules

  • Implement Supabase DAL access
  • Handle timezone-safe dates
  • Apply fractional indexing for lists
  • Structure migrations for RLS

About this skill

Database Operations & Rules

※最優先遵守事項(DALの強制、Additive Changesのみ等の絶対ルール)については必ず .agent/rules/core-rules.md を参照すること。

1. SSOT (Single Source of Truth) とデータ型規約

  • 型定義の参照: スキーマ構造やEnum値は、手動コードやドキュメントを推測せず、必ず packages/shared/src/types/ 配下を参照すること。
  • 日付SSOT: 時差ズレを防ぐため、日付(date)は常にブラウザローカルタイムゾーンに基づく YYYY-MM-DD 形式のプレーン文字列としてDALへ渡し、完全一致で保存・判定すること。
  • Diaries アトミック追記仕様: 初回入力は [HH:MM]\n本文、同一日の追記時は既存本文の末尾に改行2つ(\n\n)を挟んで [HH:MM]\n本文 をアトミック結合し upsert すること。
  • Slim Fetching: ノート一覧等は本文を除いた NoteMetadata 型で軽量フェッチし、詳細・編集時に完全な Note 型へハイドレーションすること。

2. データ操作のベストプラクティス

  • Fractional Indexing: 順序管理(sort_order)は double precision を用いた Fractional Indexing を標準とし、単一レコードの update のみで完結させること(配列の一括更新禁止)。
  • N+1 クエリ排除と RPC 活用: ダッシュボード等の複雑な階層データ取得は、PostgreSQL の JSON_AGG 等を活用した単一 RPC 関数を作成して一括取得すること。
  • 楽観的UIの採番対称性: 新規作成時の仮 sort_order は、DB側の採番(最上部挿入なら Math.min(...) - 1.0)と完全に一致させ、ワープ現象を物理排除すること。

3. マイグレーション & セキュリティ (RLS)

  • マイグレーション手順: ローカルで変更テスト後、supabase/migrations にSQLを作成し、bunx supabase db dump --local > supabase/schema.sql でスキーマを最新化すること。
  • RLS (Row Level Security): 全テーブルで RLS を有効化し、auth.uid() = user_id によるアクセスポリシーを必須とすること。
  • PostgREST インジェクション対策: .or('column.eq."${val}"') などの文字列連結クエリはパースエラーや脆弱性の原因となるため禁止。複雑な OR 条件は DB 側に RPC を作成してパラメータ渡しすること。
  • PostgrestError の型判定: catch (err: unknown) 内では typeof err === 'object' && err !== null && 'message' in err のプロパティチェックでメッセージを取得すること(instanceof Error 単体判定は不可)。

When not to use it

  • When directly modifying `packages/shared/src/types/supabase.ts` manually.
  • When building Supabase queries using string concatenation for conditions.

Prerequisites

SupabasePostgreSQL

Limitations

  • Do not hardcode specific values for database structure, table names, column names, or Enum values.
  • Direct writing to `packages/shared/src/types/supabase.ts` is absolutely prohibited.
  • String concatenation for query conditions like `.or('column.eq."${value}"')` is prohibited.

How it compares

This skill provides strict, opinionated rules for Supabase development, such as mandatory DAL usage and specific date handling, which prevents common pitfalls and ensures architectural consistency.

Compared to similar skills

Database Rules side by side with the closest alternatives in the catalog.

SkillInstallsUpdatedSafetyDifficulty
Database Rules (this skill)01moNo flagsAdvanced
backend-dev16moNo flagsIntermediate
drizzle-orm322moNo flagsIntermediate
database-design66moReviewIntermediate

Try saying

Example prompts that trigger this skill in your AI assistant.

Search skills

Search the agent skills registry