Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ jobs:
working-directory: server/api
run: bunx tsc --noEmit

drizzle-migration-check:
name: Drizzle Migration Check
# Drizzle TS スキーマを変更したら必ずマイグレーション SQL を追加するルールの強制。
# PR #728 のように TS スキーマだけ更新して `server/api/drizzle/*.sql` を忘れると、
# 本番 DB がスキーマに追いつかず 500 エラーになるため、PR 段階で検出する。
# PR 限定(push にはマージベースの計算対象が無い)。
#
# Enforce: any change under `server/api/src/schema/**` must come with a new
# migration SQL file and an updated `_journal.json`. Detects PR #728-style
# regressions where production drifts from the application schema.
if: github.event_name == 'pull_request' && !github.event.pull_request.draft
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6.0.2
with:
# PR ベースとの diff を取るため履歴を全部取得する。
# Need full history so the script can diff against the PR base.
fetch-depth: 0

- uses: actions/setup-node@v6
with:
node-version-file: ".nvmrc"

- name: Run drizzle migration consistency check
env:
DRIZZLE_DIFF_BASE: origin/${{ github.base_ref }}
PR_TITLE: ${{ github.event.pull_request.title }}
PR_BODY: ${{ github.event.pull_request.body }}
run: node scripts/check-drizzle-migrations.mjs

mcp-test:
name: MCP Server Tests
if: github.event_name != 'pull_request' || !github.event.pull_request.draft
Expand Down
16 changes: 16 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@ bun run test:run # Vitest 単体テスト
- 既存のディレクトリ構成・命名規則に合わせる。
- Conventional Commits 形式でコミット(`feat:`, `fix:`, `docs:` 等)。

## DB スキーマ変更(必読) / Database schema changes (must read)

- **TS スキーマと SQL マイグレーションは常に対で更新する**。`server/api/src/schema/**/*.ts` を編集したら、必ず `server/api/drizzle/NNNN_*.sql` を新規追加し、`server/api/drizzle/meta/_journal.json` にエントリを追記する。
_Always pair TS schema edits with a SQL migration: add a new `server/api/drizzle/NNNN_\*.sql`and append an entry to`server/api/drizzle/meta/_journal.json`. Skipping this caused PR #728 → production 500s on `/api/onboarding/status`and`/api/pages`._
- **正本のマイグレーション置き場は `server/api/drizzle/` のみ**。CI (`deploy-{dev,prod}.yml`) は `bunx drizzle-kit migrate` だけを実行するため、ここ以外に SQL を置いても本番には適用されない。
_Source of truth is `server/api/drizzle/`. CI runs only `bunx drizzle-kit migrate`; SQL placed elsewhere is dead code._
- **マイグレーションの書き方**:
- 既存の手書き例(`0017_add_link_type.sql` など)の体裁に合わせ、ステートメント間に `--> statement-breakpoint` を入れる。
- 既存環境で重複適用されても安全になるよう、原則として `IF NOT EXISTS` / `ON CONFLICT DO NOTHING` を使う。
- 必要であればバックフィル(既存行への初期値投入)も同じファイル内で行う。
- `bunx drizzle-kit generate` で雛形を作るときは、過去スナップショットが欠落しているため巨大な diff が出ることがある。その場合は `--name` 指定の出力を手で削減し、既存マイグレーション間で重複しない形に整えてから commit する(snapshot ファイルは生成物のみ、当面コミットしない方針)。
- **CI ガード**: `.github/workflows/ci.yml` の `drizzle-migration-check` ジョブが PR で `server/api/src/schema/**` の変更と新規 `server/api/drizzle/*.sql` がペアになっているかを検証する。例外的に SQL 不要な場合(コメント/JSDoc 修正のみなど)は PR 本文かコミットメッセージに `[skip drizzle-check]` を入れる。
_CI guard `drizzle-migration-check` enforces the schema/migration pairing. Use the `[skip drizzle-check]` marker only for non-DDL edits (comments, JSDoc, type aliases that do not affect SQL)._
- **環境別の自動適用**: `develop` への push → `deploy-dev.yml` が development DB へ migrate。`main` への push → `deploy-prod.yml` が production DB へ migrate。スキーマ追従はこの 2 本だけ。
_Auto-apply: push to `develop` migrates dev DB; push to `main` migrates prod DB. No other path applies migrations._

## ブランチ・PR の命名規則

- **ブランチ**: `feature/説明`、`fix/説明`、`hotfix/説明`、`chore/説明` など(例: `feature/ai-models-ui`, `fix/search-crash`)。Issue 番号から作る場合は `feature/123`。
Expand Down
5 changes: 5 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
- エラーハンドリングとログが適切か。
- 日本語・英語のコメント・ドキュメントがプロジェクトのトーンに合っているか。

## DB スキーマ変更

- TS スキーマ (`server/api/src/schema/**`) を変更した PR では必ず `server/api/drizzle/NNNN_*.sql` を新規追加し、`server/api/drizzle/meta/_journal.json` にもエントリを追記する。詳細は [AGENTS.md §「DB スキーマ変更」](./AGENTS.md#db-スキーマ変更必読--database-schema-changes-must-read) を参照。
- CI の `drizzle-migration-check` ジョブが PR でスキーマ変更と SQL 追加のペアを強制する。

## その他

- 変更が大きい場合は小さな PR に分けることを推奨する。
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ VITE_REALTIME_URL=ws://localhost:1234 # 本番は wss://realtime.zedi-note.app
| **Visualization** | Recharts / `@xyflow/react` (React Flow) / Mermaid / KaTeX / Tesseract.js (OCR) |
| **Auth** | [Better Auth](https://better-auth.com/) (OAuth / セッション cookie) |
| **API** | `server/api` — Hono on Bun + Drizzle ORM (PostgreSQL) |
| **Database** | PostgreSQL (Drizzle migrations: `db/migrations`, `server/api/drizzle`) / IndexedDB (local・ブラウザ) |
| **Database** | PostgreSQL (Drizzle migrations: `server/api/drizzle/`) / IndexedDB (local・ブラウザ) |
| **Realtime** | `server/hocuspocus` — Hocuspocus (Y.js) によるリアルタイム共同編集 |
| **MCP** | `server/mcp` — Claude Code 連携(stdio / HTTP、詳細は [server/mcp/README.md](server/mcp/README.md)) |
| **Storage** | AWS S3(API 経由でアップロード、`@aws-sdk/client-s3`) |
Expand Down Expand Up @@ -337,7 +337,7 @@ packages/ # Bun workspaces(共有ライブラリ)

admin/ # 管理画面アプリ(別 Vite + React + Tailwind / `@zedi/ui` 利用)
extension/ # ブラウザ拡張(Manifest v3、Web Clipper)
db/migrations/ # PostgreSQL マイグレーション SQL
server/api/drizzle/ # PostgreSQL マイグレーション(drizzle-kit が読む正本 / source of truth)
terraform/cloudflare/ # Cloudflare 関連インフラ定義
e2e/ # Playwright E2E テスト
scripts/ # セットアップ / sidecar ビルド / Stryker / 拡張ビルド等のスクリプト
Expand Down
49 changes: 0 additions & 49 deletions db/migrations/001_add_notes_tables.sql

This file was deleted.

19 changes: 0 additions & 19 deletions db/migrations/002_add_page_snapshots.sql

This file was deleted.

33 changes: 0 additions & 33 deletions db/migrations/003_add_invitation_tokens.sql

This file was deleted.

18 changes: 0 additions & 18 deletions db/migrations/004_add_invitation_locale_tracking.sql

This file was deleted.

69 changes: 0 additions & 69 deletions db/migrations/005_add_onboarding_and_page_kind.sql

This file was deleted.

Loading
Loading