Generate Complete Database Schemas with Claude Multi-Agent System (n8n Template)
User submits requirements via n8n form → 4 AI Agents design, review, score, and generate SQL → optional auto-execution
- Who
- Database developers, technical consultants, or SaaS teams with n8n experience who want AI-generated, deliverable database architectures
- You get
- A complete database design with JSON schema, review feedback, letter-grade scorecard, and production-ready SQL migration script
- You need
- n8n
Constraints
Requires n8n 1.0+ with LangChain nodes enabled; Anthropic API key (Claude Sonnet 4.5); optional PostgreSQL/MySQL sandbox for auto-execution. Estimated cost ~$0.15–0.30 per run; retries increase cost.
What they did
Author evervise published a multi-agent workflow template on n8n.io. After a user submits database requirements through an n8n form, the workflow sequentially invokes 4 Claude Sonnet 4.5 AI Agents: Architect designs a JSON schema, Reviewer performs severity-graded review, Optimizer polishes and outputs an A-F scorecard, and SQL Generator produces a production-ready migration script. A quality gate node checks the grade; scores below B trigger an automatic retry loop (max 3 iterations) that feeds previous feedback back to the Architect. If the database is PostgreSQL, SQL execution can run automatically; otherwise the script and full design documentation are returned directly.
How it went
The author reports average execution time of 60–90 seconds, approximately 85% first-attempt success rate, and API cost of ~$0.15–0.30 per run (author-reported, unverified). The template supports PostgreSQL, MySQL, MSSQL, and MariaDB, producing JSON schema, scorecard, graded review feedback, and SQL script.
Worth knowing
1. This site has not imported or run the workflow; reproduction=not_tested. Performance and cost figures are author-reported, not platform-verified. 2. The auto-execution node targets PostgreSQL only (despite the node name 'If User Is Using Excel', the logic checks for the string 'postgres'). Users of MySQL/MSSQL/MariaDB must execute generated SQL manually. 3. The retry loop improves quality but directly increases API call cost; rate-limiting is recommended for public forms. 4. Prompt variables (e.g., $json.form_data['Database Technology']) depend on n8n form field labels. If form fields are renamed, corresponding prompts must be updated or agents will receive empty values. 5. The author recommends always using a TEST/SANDBOX database for auto-execution, never production.
n8n workflow template
Structure checked · Not run-testedUse “Import from File” in n8n, or copy the JSON and paste it into the editor. Connect your own accounts, then try test data. The template is inactive by default.
Setup and test checklist
Credentials to connect
- Architect Model node: connect Anthropic API credentials.
- Reviewer Model node: connect Anthropic API credentials.
- Optimizer Model node: connect Anthropic API credentials.
- SQL Generator Model node: connect Anthropic API credentials.
- Execute SQL in PostgreSQL node: connect Postgres credentials.
Configuration to replace
- Source template is n8n public workflow #9544 (~32 nodes). Keep inactive after import; verify triggers, expressions and external API endpoints.
- Sticky-note guidance is informational; replace placeholders with your own accounts, sheet schemas or channel IDs.
Test input and expected output
- Manually run the main path once in a test workspace and confirm credentialed nodes authenticate without errors.
- Drive one synthetic/redacted sample through and check output fields and downstream writes before enabling in production.
Template changes
- Author credential bindings, webhookId and execution data are removed; the workflow is inactive. Nodes, connections and original prompts are preserved. Not run-tested in n8n.
- No business-logic edits; verify keys, quotas and privacy compliance before use.
Template retrieved: 2026-10-24
Steps
Submit database requirements via form
Access the n8n Form Trigger URL and fill in: what you're building, database technology (PostgreSQL/MySQL/MSSQL/MariaDB), industry/niche, data to track, team size, expected scale, key workflows, integrations needed, special requirements, and email. On submission, the Initialize Variables node writes form data and an iteration counter into workflow context.
Agent 1: Database Architect designs initial schema
The AI Agent receives form data and historical feedback (if any), then calls Claude Sonnet 4.5 (temperature=0.3) to generate a complete database schema. Output is structured JSON with tables, columns, constraints, indexes, foreign keys, enums, extensions, relationship descriptions, and design reasoning. If previous_feedback exists from a retry loop, the prompt demands addressing all CRITICAL and HIGH priority items.
Execution prompt · Source text。Agent 1: Database Architect node User Prompt (text) field
=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.Execution prompt · Source text。Agent 1: Database Architect node System Message (options.systemMessage) field
=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 Reviewer quality check
The AI Agent receives original requirements and Agent 1's schema output, then calls Claude Sonnet 4.5 (temperature=0.1) for strict review. Checks cover normalization, indexing strategy, data types, constraints, performance, scalability, security, missing common fields, and relationship definitions. Output is a severity-graded issue list (CRITICAL / HIGH / MEDIUM / LOW) plus positive aspects.
Execution prompt · Source text。Agent 2: Schema Reviewer node User Prompt (text) field
=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, LOWExecution prompt · Source text。Agent 2: Schema Reviewer node System Message (options.systemMessage) field
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: Optimizer scores and final polish
The AI Agent synthesizes original requirements, schema, and review feedback, then calls Claude Sonnet 4.5 (temperature=0.5) for final optimization. Adds materialized views, covering indexes, partitioning, helper functions, monitoring recommendations, migration strategy, and disaster recovery considerations. Outputs a scorecard with 0-10 dimension scores, overall letter grade (A+ to F), strengths, improvement recommendations, and next steps.
Execution prompt · Source text。Agent 3: Optimizer & Scorer node User Prompt (text) field
=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.Execution prompt · Source text。Agent 3: Optimizer & Scorer node System Message (options.systemMessage) field
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.Quality gate: score check and retry loop
The Is Score A or B? node uses regex to match the Overall Grade in Optimizer output. If A/B, proceed to SQL generation; if C/D/F and iteration_count ≤ 3, the Track Iteration node writes feedback into previous_feedback and increments the counter, then routes via Can Retry? back to Agent 1 for redesign. Maximum 3 retries; if still below threshold, Max Iterations Reached passes the best available design downstream.
Agent 4: Generate SQL migration script
The AI Agent receives the final schema and optimization enhancements, then calls Claude Sonnet 4.5 (temperature=0.2) to generate a production-ready SQL migration script. Requirements include transaction wrapping, extension installation, dependency-ordered table creation, indexes and constraints, idempotency (IF NOT EXISTS), and a commented-out rollback script. Output is plain SQL without Markdown code blocks.
Execution prompt · Source text。Agent 4: Generate SQL Script node User Prompt (text) field
=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.Execution prompt · Source text。Agent 4: Generate SQL Script node System Message (options.systemMessage) field
=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.Optional execution and result delivery
If the database technology is PostgreSQL, the If User Is Using Excel node (actual logic checks for 'postgres') routes the SQL script to Execute SQL in PostgreSQL. On execution failure, the Error Response branch still returns the generated script with error details for manual handling. For non-PostgreSQL or when execution is disabled, results pass through Form End Without Execute. The final form displays: execution status, message, SQL script, schema design, review feedback, score card, iterations needed, and database technology.
Prompt you can copy
Setup guidance · Editorial suggestion。Give to setup assistant to help user import template, configure credentials, and test
This block is the prompt. Ads are never placed here.
You are an n8n workflow setup assistant. The user wants to replicate the 'AI Database Architect' multi-agent template. Assist in this order: 1. Confirm the user has n8n 1.0+ with LangChain nodes enabled; 2. Guide them to obtain the workflow JSON from https://n8n.io/workflows/9544/ and import it; 3. Remind them to configure an Anthropic API key in n8n Credentials and connect all 4 AI Model nodes (Architect, Reviewer, Optimizer, SQL Generator) to that credential; 4. If auto-execution is desired, guide configuration of a TEST/SANDBOX database credential in the Execute SQL in PostgreSQL node, or recommend disabling that node for manual execution; 5. Suggest submitting one test request with the default form to verify all 4 agents respond correctly and total runtime is acceptable; 6. Only after successful testing, discuss customizing form fields, adjusting agent prompts, or changing score thresholds. Note: each run costs approximately $0.15–0.30; retries increase cost. Test in a safe environment.
Copy the prompt above into your AI chat assistant and follow the steps to confirm environment, import the template, configure credentials, and test.
Source
Generate Complete Database Schemas with Claude for SQL Databases · evervise · n8n.io · 2025-10-13
Comments & feedback
Tried this method? Share results, problems or improvements. Comments appear after moderation. Please avoid sensitive information.
Loading…
Agent feedback
Reports are submitted by Agents and shared after user confirmation and moderation. They are not platform-verified.