tina-schema-sync
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTinaCMS Schema Sync
TinaCMS Schema 同步
Regenerate TinaCMS artifacts locally and commit them after schema changes. This handles the hybrid deployment strategy where is skipped on Vercel and artifacts are pre-committed.
tinacms build通过重新生成本地TinaCMS工件并提交,来处理schema变更后的同步操作。这适用于混合部署策略,即在Vercel上跳过,预先提交工件。
tinacms buildWhen to Use
适用场景
- After editing (adding fields, blocks, collections)
tina/config.ts - After upgrading
@tinacms/cli - When fails with "Unable to seed" (content references unknown block types)
pnpm tina:build - When Vercel deploys succeed but new blocks don't render
- 编辑之后(添加字段、块、集合)
tina/config.ts - 升级之后
@tinacms/cli - 当因“Unable to seed”失败时(内容引用了未知的块类型)
pnpm tina:build - 当Vercel部署成功但新块无法渲染时
Prerequisites
前提条件
- TinaCloud credentials in :
.env.localNEXT_PUBLIC_TINA_CLIENT_ID="..." TINA_TOKEN="..." - If doesn't exist, run
.env.localor copy from./scripts/pull-secrets.shand fill in values from TinaCloud dashboard..env.example
- 中需包含TinaCloud凭证:
.env.localNEXT_PUBLIC_TINA_CLIENT_ID="..." TINA_TOKEN="..." - 如果不存在,运行
.env.local,或从./scripts/pull-secrets.sh复制并填写TinaCloud控制台中的值。.env.example
Procedure
操作步骤
Step 1: Source credentials
步骤1:加载凭证
bash
source .env.localVerify they're set:
bash
echo $NEXT_PUBLIC_TINA_CLIENT_ID | head -c 10
echo $TINA_TOKEN | head -c 10bash
source .env.local验证凭证已设置:
bash
echo $NEXT_PUBLIC_TINA_CLIENT_ID | head -c 10
echo $TINA_TOKEN | head -c 10Step 2: Run the dev server to regenerate artifacts
步骤2:运行开发服务器以重新生成工件
bash
NEXT_PUBLIC_TINA_CLIENT_ID="$NEXT_PUBLIC_TINA_CLIENT_ID" \
TINA_TOKEN="$TINA_TOKEN" \
npx tinacms dev --noWatch --noTelemetryWait for "TinaCMS Dev Server is active" message, then stop the server (Ctrl+C or kill the process).
Why instead of ? The build command connects to TinaCloud for indexing. If the content already references new block types that TinaCloud's schema doesn't know about, the build fails with "Unable to seed." The dev server generates artifacts locally without requiring TinaCloud to re-index first.
tinacms devtinacms buildbash
NEXT_PUBLIC_TINA_CLIENT_ID="$NEXT_PUBLIC_TINA_CLIENT_ID" \
TINA_TOKEN="$TINA_TOKEN" \
npx tinacms dev --noWatch --noTelemetry等待出现“TinaCMS Dev Server is active”消息后,停止服务器(Ctrl+C或终止进程)。
为什么使用而非? build命令会连接到TinaCloud进行索引。如果内容已经引用了TinaCloud schema未知的新块类型,build会因“Unable to seed”失败。开发服务器会在本地生成工件,无需TinaCloud先重新索引。
tinacms devtinacms buildStep 3: Verify artifacts were regenerated
步骤3:验证工件已重新生成
bash
git status tina/You should see changes in:
tina/__generated__/client.tstina/__generated__/types.tstina/tina-lock.json
Also check for changes.
public/admin/bash
git status tina/你应该看到以下内容的变更:
tina/__generated__/client.tstina/__generated__/types.tstina/tina-lock.json
同时检查是否有变更。
public/admin/Step 4: Verify new types exist
步骤4:验证新类型已生成
If you added a new block type (e.g., ):
ContentTypesbash
grep "ContentTypes" tina/__generated__/types.ts如果你添加了新的块类型(例如):
ContentTypesbash
grep "ContentTypes" tina/__generated__/types.tsStep 5: Commit all three artifact groups
步骤5:提交所有三类工件
bash
git add tina/__generated__/ tina/tina-lock.json public/admin/
git commit -m "chore(tina): regenerate artifacts for [describe schema change]"Critical: is the file TinaCloud reads to understand the schema on deploy. If you commit generated types but forget the lock file, deploys will fail or new block types will not render.
tina/tina-lock.jsonbash
git add tina/__generated__/ tina/tina-lock.json public/admin/
git commit -m "chore(tina): regenerate artifacts for [describe schema change]"关键注意事项: 是TinaCloud在部署时读取的schema文件。如果只提交了生成的类型但忘记提交锁文件,部署会失败或新块类型无法渲染。
tina/tina-lock.jsonStep 6: Push
步骤6:推送代码
bash
git pushTinaCloud picks up the lock file from the pushed commit and indexes the schema correctly.
bash
git pushTinaCloud会从推送的提交中获取锁文件,并正确索引schema。
Agentic Workflow & Vibe Coding
智能工作流与氛围编码
- Iterative Syncing: Do not expect the schema to sync perfectly on the first try if there are complex field dependencies. If the dev server throws an error or artifacts don't generate, isolate the specific schema error, fix exactly one collection or field definition, and rerun the sync process until successful.
- Vibe Coding: Create local, semantic commits for your working changes before running the sync process, and then commit the generated artifacts separately once the sync succeeds. This ensures you can easily roll back if the generation fails.
tina/config.ts
- 迭代同步: 如果存在复杂的字段依赖,不要期望schema一次就能完美同步。如果开发服务器抛出错误或工件未生成,隔离具体的schema错误,仅修复一个集合或字段定义,然后重新运行同步过程直至成功。
- 氛围编码: 在运行同步过程之前,为你正在编辑的变更创建本地语义化提交,然后在同步成功后单独提交生成的工件。这样如果生成失败,你可以轻松回滚。
tina/config.ts
Troubleshooting
故障排除
"Unable to seed content/pages/home.mdx"
"Unable to seed content/pages/home.mdx"
The content file references a block type the cloud schema doesn't know about. This is the exact scenario this skill handles. Use (Step 2), not .
tinacms devtinacms build内容文件引用了云schema未知的块类型。这正是本技能要处理的场景。使用(步骤2),而非。
tinacms devtinacms buildDev server won't start
开发服务器无法启动
- Check credentials are set (Step 1)
- Check port 4001 isn't in use:
lsof -i :4001 - Check port 6970 isn't in use:
lsof -i :6970
- 检查凭证是否已设置(步骤1)
- 检查端口4001是否被占用:
lsof -i :4001 - 检查端口6970是否被占用:
lsof -i :6970
Types generated but lock file unchanged
类型已生成但锁文件未变更
The schema change may not have been saved. Verify was written before running the dev server.
tina/config.ts可能schema变更未保存。在运行开发服务器之前,确认已保存。
tina/config.tsChecklist
检查清单
Before pushing, verify:
- has changes
tina/__generated__/client.ts - has new type definitions
tina/__generated__/types.ts - has changes
tina/tina-lock.json - updated (if applicable)
public/admin/ - All four are staged and committed together
推送前,请验证:
- 有变更
tina/__generated__/client.ts - 有新的类型定义
tina/__generated__/types.ts - 有变更
tina/tina-lock.json - 已更新(如适用)
public/admin/ - 以上四类文件均已暂存并一起提交