Files
yingfungsolar/migrations/AGENTS.md
T
philip-cat fdee1aabd7 Add Zod validation layer and AI blog generation
Introduce a schema-first validation layer and an AI blog generation
feature, plus one-command Cloudflare provisioning.

- src/schemas/ holds Zod input schemas for post, content, case,
  settings, AI, and keywords; parseForm() in src/lib/form.ts validates
  FormData and returns per-field errors.
- Migrate all admin POST handlers to parseForm, showing field-level
  errors and only redirecting once validation passes.
- Add blog_keywords table and posts.focus_keyword (migration 0002);
  uniqueSlug() centralised in src/data/content.ts.
- Add src/lib/ai.ts (OpenAI-compatible chat completions + optional
  Tavily research) and /admin/ai for AI settings, keyword queue, and
  draft generation.
- Add scripts/setup.mjs (npm run setup) to provision D1/KV, set
  secrets, and optionally migrate, seed, and deploy.
- Document AI secrets, Workers Builds deploy flow, and new schemas
  across README and AGENTS docs.
2026-09-11 23:49:18 +08:00

37 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# migrations/AGENTS.md
## Purpose
Cloudflare D1 的 schema migration 同種子資料。
## Ownership
- 擁有 `migrations/` 全部 SQL、`migrations/meta/``seed.sql`
- Drizzle schema 定義喺 `src/db/schema.ts`(見 `src/db/AGENTS.md`)。
## Local Contracts
- **Migration 由工具產生**`0000_*.sql``0001_*.sql``0002_*.sql``npm run db:generate`drizzle-kit)依 `schema.ts` 產生;`migrations/meta/` 係產生檔。**唔好手改**呢啲檔或 meta。`0002_*.sql` 加咗 `posts.focus_keyword``blog_keywords` 表。
- **`seed.sql` 係手寫、獨立於 migration**:全部用 `INSERT OR REPLACE`,可重複執行。`db:migrate` **唔會**執行 seed。
- **Migration 唔會喺 CI 執行**Cloudflare Workers Builds 只跑 build + deploy;改 schema 後要手動 `npm run db:migrate`(雲端)。
- **指令**(本機用 `:local`,雲端省略):
- `npm run db:generate` — 由 schema 產生 migration
- `npm run db:migrate:local` / `npm run db:migrate` — 套用 migration
- `npm run db:seed:local` / `npm run db:seed` — 匯入種子
- **Seed 內容**:公司資料(`site_settings`)、首頁內容(`content_items`service/feature/step/faq)、`cases`、一篇示範 `posts`、三個示範 `blog_keywords``pending`);另有 7 個 `ai_*` AI 設定 keys(獨立 seed block)。
- DB 名稱 `yingfung-solar-db`binding 喺 `wrangler.jsonc``database_id` 仍係佔位,部署前要填)。
## Work Guidance
- 改 schema → 先 `db:generate`,再 `db:migrate:local`;改 seed → 直接 `db:seed:local`
- 新增 setting key 時同步更新 `src/data/settings-fields.ts`
## Verification
- `npm run db:migrate:local && npm run db:seed:local`,再用 `npm run db:studio` 或 SQL 查證。
- `npm run build`
## Child DOX Index
無。