用 Claude 多 Agent 自动生成完整数据库 Schema(n8n 模板)
用户在 n8n 表单提交需求 → 4 个 AI Agent 依次设计、评审、优化评分、生成 SQL → 可选自动执行
- 给谁
- 有 n8n 经验的数据库开发者、技术顾问或 SaaS 团队,想用 AI 快速产出可交付的数据库架构
- 你会得到
- 一份包含 JSON Schema、评审反馈、评分卡(A-F)与生产级 SQL migration 脚本的完整数据库设计
- 你需要
- n8n
硬约束
需要 n8n 1.0+ 实例并启用 LangChain 节点;Anthropic API key(Claude Sonnet 4.5);可选 PostgreSQL/MySQL 沙箱数据库用于自动执行。每次运行约 $0.15–0.30,重试会增加成本。
他们做了什么
作者 evervise 在 n8n.io 发布了一个多 Agent 工作流模板。用户通过 n8n 表单提交数据库需求后,工作流依次调用 4 个 Claude Sonnet 4.5 AI Agent:Architect 设计 JSON Schema、Reviewer 执行分级评审、Optimizer 优化并输出 A-F 评分卡、SQL Generator 生成生产级 migration 脚本。质量门节点检查评分等级,低于 B 时自动将反馈注入重试循环(最多 3 次)。若数据库为 PostgreSQL,可选择自动执行 SQL;否则直接返回脚本与完整设计文档。
效果如何
作者报告该工作流平均执行时间 60–90 秒,首次成功率约 85%,每次运行 API 成本约 $0.15–0.30(作者自述,未经验证)。模板支持 PostgreSQL、MySQL、MSSQL、MariaDB,输出包括 JSON Schema、评分卡、分级评审反馈与 SQL 脚本。
值得知道
1. 本站未实际导入运行,reproduction=not_tested;上述性能与成本数据为作者自述,不构成平台验证结论。 2. 自动执行节点仅针对 PostgreSQL(节点名虽为 'If User Is Using Excel',实际逻辑检测 postgres 字符串),MySQL/MSSQL/MariaDB 用户需手动执行生成的 SQL。 3. 重试循环虽提升质量,但会直接增加 API 调用费用;公开表单建议加速率限制。 4. 节点提示词中的变量名(如 $json.form_data['Database Technology'])依赖 n8n 表单字段标签,修改表单字段时需同步更新对应提示词,否则 Agent 接收空值。 5. 作者建议始终使用 TEST/SANDBOX 数据库进行自动执行,避免在生产环境直接运行生成的 SQL。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- Architect Model 节点:绑定Anthropic API 凭证。
- Reviewer Model 节点:绑定Anthropic API 凭证。
- Optimizer Model 节点:绑定Anthropic API 凭证。
- SQL Generator Model 节点:绑定Anthropic API 凭证。
- Execute SQL in PostgreSQL 节点:绑定Postgres 凭证。
需要替换的配置
- 源模板来自 n8n 公开库 #9544(约 32 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-24
步骤
通过表单提交数据库需求
访问 n8n Form Trigger 生成的表单地址,填写:要构建的系统、数据库技术(PostgreSQL/MySQL/MSSQL/MariaDB)、行业/细分、需追踪的数据、团队规模、预期规模、关键工作流、集成需求、特殊要求,以及接收结果的邮箱。提交后,Initialize Variables 节点将表单数据与迭代计数器写入工作流上下文。
Agent 1:数据库架构师设计初始 Schema
AI Agent 接收表单数据与历史反馈(如有),调用 Claude Sonnet 4.5(temperature=0.3)生成完整的数据库 Schema。输出为结构化 JSON,包含表、列、约束、索引、外键、枚举、扩展、关系说明与设计理由。若存在 previous_feedback(来自重试循环),提示词会要求优先处理 CRITICAL 和 HIGH 优先级问题。
运行提示词 · 来源原文。Agent 1: Database Architect 节点的 User Prompt(text)字段
=Database Requirements: - What they're building: {{ $json.form_data['What are you building?'] }} - Database Technology: {{ $json.form_data['Database Technology'] }} - Industry: {{ $json.form_data['Industry/Niche'] }} - Data to track: {{ $json.form_data['What data do you need to track?'] }} - Team size: {{ $json.form_data['Team Size'] }} - Expected scale: {{ $json.form_data['Expected Scale'] }} - Key workflows: {{ $json.form_data['Key Workflows'] }} - Integrations: {{ $json.form_data['Any integrations needed?'] }} - Special requirements: {{ $json.form_data['Special Requirements'] }} {{ $json.previous_feedback ? '⚠️ PREVIOUS DESIGN HAD ISSUES - ITERATION ' + ($json.iteration_count + 1) + '/3:\n\nPrevious Feedback:\n' + $json.previous_feedback + '\n\nPlease redesign the schema addressing ALL the concerns mentioned above. Focus especially on CRITICAL and HIGH priority items.\n\n' : '' }} Please design a complete {{ $json.form_data['Database Technology'] }} database schema for this use case. Output your design as structured JSON.运行提示词 · 来源原文。Agent 1: Database Architect 节点的 System Message(options.systemMessage)字段
=You are a senior {{ $json.form_data['Database Technology'] }} database architect with 15+ years experience. You design production-grade schemas that are scalable, normalized, and follow best practices. You consider performance, indexing, and future growth. Output your design as structured JSON with: - tables: Array of table objects with: - name: string - columns: Array of {name, type, constraints, description} - primary_key: string or array - indexes: Array of {name, columns, type} - foreign_keys: Array of {column, references_table, references_column} - enums: Array of {name, values} - extensions: Array of extension names needed - relationships: Description of how tables relate - reasoning: Explanation for key design decisions Be thorough and production-ready. Consider the scale and requirements carefully.Agent 2:Schema 评审员质量检查
AI Agent 接收原始需求与 Agent 1 的 Schema 输出,调用 Claude Sonnet 4.5(temperature=0.1)执行严格评审。检查范围:规范化、索引策略、数据类型、约束、性能、可扩展性、安全性、常见字段缺失、关系定义。输出按 CRITICAL / HIGH / MEDIUM / LOW 分级的问题列表,并列出优点。
运行提示词 · 来源原文。Agent 2: Schema Reviewer 节点的 User Prompt(text)字段
=Original Requirements: {{ JSON.stringify($('Initialize Variables').item.json.form_data, null, 2) }} Proposed Schema from Agent 1: {{ $('Agent 1: Database Architect').item.json.output }} Please conduct a thorough review of this database schema design. Check for issues in normalization, indexing, data types, constraints, performance, scalability, and security. Output structured feedback with severity levels: CRITICAL, HIGH, MEDIUM, LOW运行提示词 · 来源原文。Agent 2: Schema Reviewer 节点的 System Message(options.systemMessage)字段
You are a {{ $('Initialize Variables').item.json.form_data['Database Technology'] }} code reviewer and database optimization expert. Your job is to find issues, enforce best practices, and ensure production-readiness. Review checklist: - Normalization (3NF minimum, appropriate denormalization) - Indexing strategy (missing indexes? over-indexing?) - Data types (appropriate choices for the database type) - Constraints (missing NOT NULL? need CHECK constraints?) - Performance (N+1 query risks? missing composite indexes?) - Scalability (will this work at 10x, 100x scale?) - Security (sensitive data? need encryption? row-level security?) - Missing common fields (created_at, updated_at, soft deletes) - Relationships properly defined Output structured feedback in this format: CRITICAL Issues: - [Issue 1] - [Issue 2] HIGH Priority: - [Issue 1] MEDIUM Priority: - [Issue 1] LOW Priority / Suggestions: - [Issue 1] Positive Aspects: - [Good thing 1] Be thorough but fair. If the design is solid, say so.Agent 3:优化师评分与最终打磨
AI Agent 综合原始需求、Schema 与评审反馈,调用 Claude Sonnet 4.5(temperature=0.5)进行最终优化。添加物化视图、覆盖索引、分区、辅助函数、监控建议、迁移策略与灾备考虑。输出包含各维度 0-10 分的评分卡,整体等级 A+ 至 F,并附优势、改进建议与后续步骤。
运行提示词 · 来源原文。Agent 3: Optimizer & Scorer 节点的 User Prompt(text)字段
=Original Requirements: {{ JSON.stringify($('Initialize Variables').item.json.form_data, null, 2) }} Proposed Schema: {{ $('Agent 1: Database Architect').item.json.output }} Review Feedback: {{ $('Agent 2: Schema Reviewer').item.json.output }} Please: 1. Apply final polish and optimizations to the schema 2. Add advanced features (materialized views, helper functions, useful views) 3. Provide monitoring recommendations 4. Create a comprehensive score card 5. Generate implementation guidance Score each dimension 0-10 with justification. Be honest but constructive.运行提示词 · 来源原文。Agent 3: Optimizer & Scorer 节点的 System Message(options.systemMessage)字段
You are a {{ $('Initialize Variables').item.json.form_data['Database Technology'] }} performance optimizer and database strategist. Apply final polish, add advanced features, and score the design holistically. Add: - Performance optimizations (materialized views, covering indexes, partitioning if needed) - Developer experience improvements (useful views, helper functions) - Monitoring recommendations (what to track in production) - Migration strategy (how to deploy safely) - Backup and disaster recovery considerations Create a comprehensive score card: 📊 DATABASE ARCHITECTURE SCORE Overall Grade: [A+, A, A-, B+, B, B-, C+, C, C-, D, F] ([score]/100) Detailed Scores: ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Schema Design: [X]/10 [Brief justification] Performance: [X]/10 [Brief justification] Scalability: [X]/10 [Brief justification] Developer Experience: [X]/10 [Brief justification] Production Readiness: [X]/10 [Brief justification] Security: [X]/10 [Brief justification] ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 💪 Key Strengths: • [Strength 1] • [Strength 2] • [Strength 3] ⚠️ Recommended Improvements: • [Improvement 1] • [Improvement 2] 🚀 Next Steps: 1. [Step 1] 2. [Step 2] 3. [Step 3] Score fairly but be honest. Grade A/B means production-ready, C means needs work, D/F means major issues.质量门:评分检查与重试循环
Is Score A or B? 节点用正则匹配 Optimizer 输出中的 Overall Grade。若为 A/B 则进入 SQL 生成;若为 C/D/F 且迭代次数 ≤3,Track Iteration 节点将反馈写入 previous_feedback 并递增计数器,经 Can Retry? 节点返回 Agent 1 重新设计。最多重试 3 次;若仍不达标,Max Iterations Reached 节点放行当前最优设计继续下游。
Agent 4:生成 SQL Migration 脚本
AI Agent 接收最终 Schema 与优化建议,调用 Claude Sonnet 4.5(temperature=0.2)生成生产级 SQL migration 脚本。要求包含事务包裹、扩展安装、按依赖顺序建表、索引与约束、幂等性(IF NOT EXISTS)及注释掉的回滚脚本。输出纯 SQL,无 Markdown 代码块。
运行提示词 · 来源原文。Agent 4: Generate SQL Script 节点的 User Prompt(text)字段
=Database Technology: {{ $('Initialize Variables').item.json.form_data['Database Technology'] }} Final Approved Schema: {{ $('Agent 1: Database Architect').item.json.output }} Optimizations and Enhancements: {{ $('Agent 3: Optimizer & Scorer').item.json.output }} Please generate a complete, production-ready SQL migration script for {{ $('Initialize Variables').item.json.form_data['Database Technology'] }}. Output ONLY the SQL script, no markdown formatting, no additional commentary.运行提示词 · 来源原文。Agent 4: Generate SQL Script 节点的 System Message(options.systemMessage)字段
=You are a {{ $('Initialize Variables').item.json.form_data['Database Technology'] }} SQL script generator. Take the database schema design and convert it into a complete, production-ready SQL migration script. Your output must: - Start with proper transaction handling (BEGIN; ... COMMIT;) - Include all necessary extensions (for PostgreSQL) - Create ENUMs before tables that use them - Create tables in correct dependency order (referenced tables first) - Add all indexes after table creation - Add all constraints and triggers - Include helpful comments explaining complex parts - Be idempotent where possible (IF NOT EXISTS clauses) - End with a commented-out rollback script Format: -- ============================================ -- Database Migration Script -- Generated: [timestamp] -- Database: {{ $('Initialize Variables').item.json.form_data['Database Technology'] }} -- ============================================ BEGIN; [Your SQL here] COMMIT; -- ============================================ -- ROLLBACK SCRIPT (commented out) -- ============================================ -- BEGIN; -- [DROP statements in reverse order] -- COMMIT; Output ONLY the SQL script. No markdown code blocks, no explanations.可选执行与结果返回
若数据库技术为 PostgreSQL,If User Is Using Excel 节点(实际检测 postgres)将 SQL 脚本传入 Execute SQL in PostgreSQL 节点执行;执行失败时走 Error Response 分支,仍返回生成的脚本与错误详情供人工处理。非 PostgreSQL 或禁用执行时,直接通过 Form End Without Execute 返回结果。最终表单展示:执行状态、消息、SQL 脚本、Schema 设计、评审反馈、评分卡、迭代次数、数据库技术。
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,协助用户按来源模板完成导入、凭证配置与测试
这一段是提示词,页面不会在这里插入广告。
你是一个 n8n 工作流搭建助手。用户想复现「AI Database Architect」多 Agent 模板。请按以下顺序协助: 1. 确认用户已有 n8n 1.0+ 实例且启用了 LangChain 节点; 2. 指导从 https://n8n.io/workflows/9544/ 获取 workflow JSON 并导入; 3. 提醒在 n8n Credentials 中配置 Anthropic API key,并将 4 个 AI Model 节点(Architect/Reviewer/Optimizer/SQL Generator)绑定到该凭证; 4. 若需自动执行,指导在 Execute SQL in PostgreSQL 节点配置 TEST/SANDBOX 数据库凭证,或建议禁用该节点改为手动执行; 5. 建议先用模板默认表单提交一次测试请求,验证 4 个 Agent 正常响应与总耗时; 6. 若测试通过,再讨论自定义表单字段、调整 Agent 提示词或评分阈值。 注意:每次运行约 $0.15–0.30,重试会增加费用;请在安全环境中测试。
复制上方提示词到 AI 聊天助手,按步骤确认环境、导入模板、配置凭证并测试。
来源
Generate Complete Database Schemas with Claude for SQL Databases · evervise · n8n.io · 2025-10-13
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。