数据库生成
- 作者仓库星标 1,052
- 作者更新于 实时读取
- 作者仓库 moai-adk
- 领域
- 数据
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @modu-ai · 未声明 license
- Token 消耗评级
- 低消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 底层运行要求
- Node.js · Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 读取环境变量
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: moai-domain-database
description: > Enterprise Database Expertise - Comprehensive database patterns and implementations covering P…
category: 数据
runtime: Node.js / Python
---
# moai-domain-database 输出预览
## PART A: 任务判断
- 适用问题:表格、CSV、数据集、指标或分析流程。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Quick Reference / Implementation Guide / Quick Start Workflow”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于表格、CSV、数据集、指标或分析流程,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Quick Reference / Implementation Guide / Quick Start Workflow”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、读取环境变量、会按任务需要访问外部网络、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/users` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令、读取环境变量。
先用一个小任务确认它会围绕“Quick Reference / Implementation Guide / Quick Start Workflow”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: moai-domain-database
description: > Enterprise Database Expertise - Comprehensive database patterns and implementations covering P…
category: 数据
source: modu-ai/moai-adk
---
# moai-domain-database
## 什么时候使用
- 把数据处理方向的常用动作沉淀成 Agent 可调用的技能 适合处理表格、CSV、指标、数据集、分析和可视化报告,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查、可继续迭代的步…
- 面向表格、CSV、数据集、指标或分析流程,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Quick Reference / Implementation Guide / Quick Start Workflow」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令、读取环境变量;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "moai-domain-database" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Quick Reference / Implementation Guide / Quick Start Workflow
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Node.js / Python | 读取文件、写入/修改文件、执行终端命令、读取环境变量 | 会按任务需要访问外部网络
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Database Domain Specialist
Quick Reference
Enterprise Database Expertise - Comprehensive database patterns and implementations covering PostgreSQL, MongoDB, Redis, Oracle, and advanced data management for scalable modern applications.
Core Capabilities:
- PostgreSQL: Advanced relational patterns, optimization, and scaling
- MongoDB: Document modeling, aggregation, and NoSQL performance tuning
- Redis: In-memory caching, real-time analytics, and distributed systems
- Oracle: Enterprise patterns, PL/SQL, partitioning, and hierarchical queries
- Multi-Database: Hybrid architectures and data integration patterns
- Performance: Query optimization, indexing strategies, and scaling
- Operations: Connection management, migrations, and monitoring
When to Use:
- Designing database schemas and data models
- Implementing caching strategies and performance optimization
- Building scalable data architectures
- Working with multi-database systems
- Optimizing database queries and performance
Implementation Guide
Quick Start Workflow
Database Stack Initialization:
Create a DatabaseManager instance and configure multiple database connections. Set up PostgreSQL with connection string, pool size of 20, and query logging enabled. Configure MongoDB with connection string, database name, and sharding enabled. Configure Redis with connection string, max connections of 50, and clustering enabled. Use the unified interface to query user data with profile and analytics across all database types.
Single Database Operations:
Run PostgreSQL schema migrations using the migration command with the database type and migration file path. Execute MongoDB aggregation pipelines by specifying the collection name and pipeline JSON file. Warm Redis cache by specifying key patterns and TTL values.
Core Components
PostgreSQL Module:
- Advanced schema design and constraints
- Complex query optimization and indexing
- Window functions and CTEs
- Partitioning and materialized views
- Connection pooling and performance tuning
MongoDB Module:
- Document modeling and schema design
- Aggregation pipelines for analytics
- Indexing strategies and performance
- Sharding and scaling patterns
- Data consistency and validation
Redis Module:
- Multi-layer caching strategies
- Real-time analytics and counting
- Distributed locking and coordination
- Pub/sub messaging and streams
- Advanced data structures including HyperLogLog and Geo
Oracle Module:
- Hierarchical and recursive query patterns (CONNECT BY)
- PL/SQL procedures, packages, and batch operations
- Partitioning strategies (range, list, hash, composite)
- Enterprise features and statement caching
- LOB handling and large data processing
Advanced Patterns
Multi-Database Architecture
Polyglot Persistence Pattern:
Create a DataRouter class that initializes connections to PostgreSQL, MongoDB, Redis, and Oracle. Implement get_user_profile method that retrieves structured user data from PostgreSQL or Oracle, flexible profile data from MongoDB, and real-time status from Redis, then merges all data sources. Implement update_user_data method that routes structured data updates to PostgreSQL/Oracle, profile data updates to MongoDB, and real-time data updates to Redis, followed by cache invalidation.
Data Synchronization:
Create a DataSyncManager class that synchronizes user data across databases. Implement sync_user_data method that retrieves user from PostgreSQL, creates a search document for MongoDB, upserts to the MongoDB search collection, creates cache data, and updates Redis cache with TTL.
Performance Optimization
Query Performance Analysis:
For PostgreSQL, execute EXPLAIN ANALYZE BUFFERS on queries and use a QueryAnalyzer to generate optimization suggestions. For MongoDB, create an AggregationOptimizer to analyze and optimize aggregation pipelines. For Redis, retrieve info metrics and use a PerformanceAnalyzer to generate recommendations.
Scaling Strategies:
Configure PostgreSQL read replicas by providing replica connection URLs. Set up MongoDB sharding with shard key and number of shards. Configure Redis clustering by providing node URLs for the cluster.
Works Well With
Complementary Skills:
- moai-domain-backend - API integration and business logic
- moai-foundation-core - Database migration and schema management
- moai-workflow-project - Database project setup and configuration
- moai-platform-supabase - Supabase database integration patterns
- moai-platform-neon - Neon database integration patterns
- moai-platform-firestore - Firestore database integration patterns
Technology Integration:
- ORMs and ODMs including SQLAlchemy, Mongoose, and TypeORM
- Connection pooling with PgBouncer and connection pools
- Migration tools including Alembic, Flyway, and Data Pump
- Monitoring with pg_stat_statements, MongoDB Atlas, and Oracle AWR
- python-oracledb for Oracle connectivity and PL/SQL execution
- Cache invalidation and synchronization
Technology Stack
Relational Database:
- PostgreSQL 14+ as primary database
- MySQL 8.0+ as alternative
- Connection pooling with PgBouncer and SQLAlchemy
NoSQL Database:
- MongoDB 6.0+ as primary document store
- Document modeling and validation
- Aggregation framework
- Sharding and replication
In-Memory Database:
- Redis 7.0+ as primary cache
- Redis Stack for advanced features
- Clustering and high availability
- Advanced data structures
Enterprise Database:
- Oracle 19c+ / 21c+ for enterprise workloads
- python-oracledb (successor to cx_Oracle)
- PL/SQL procedures and packages
- Partitioning and advanced analytics
Supporting Tools:
- Migration tools including Alembic and Flyway
- Monitoring with Prometheus and Grafana
- ORMs and ODMs including SQLAlchemy and Mongoose
- Connection management utilities
Performance Features:
- Query optimization and analysis
- Index management and strategies
- Caching layers and invalidation
- Load balancing and failover
Resources
For working code examples, see examples.md.
For detailed implementation patterns and database-specific optimizations, see the modules directory.
Status: Production Ready Last Updated: 2026-01-11 Maintained by: MoAI-ADK Database Team
Common Rationalizations
| Rationalization | Reality |
|---|---|
| "I do not need an index, the table is small" | Tables grow. The missing index that is invisible at 1K rows becomes a production incident at 1M rows. |
| "I will add the migration later" | Schema changes without migrations are unreproducible. Every change must have a reversible migration script. |
| "This query works fine in development" | Development databases have tiny datasets. Production query plans differ dramatically at scale. Explain analyze first. |
| "NoSQL does not need schema design" | Schemaless does not mean designless. Document structure decisions affect every query and index. |
| "I will just add a column, it is non-breaking" | Adding a NOT NULL column without a default breaks existing inserts. Column additions need default values or migration backfills. |
| "Connection pooling is handled by the framework" | Framework defaults are generic. Pool size, timeout, and idle limits must be tuned to the workload. |
Red Flags
- Schema change committed without a corresponding migration file
- Query uses SELECT * in production code instead of explicit column list
- No index exists for columns used in WHERE, JOIN, or ORDER BY clauses
- Connection string hardcoded in source instead of environment variable
- Transaction scope spans user-facing HTTP request duration (long-held locks)
- No EXPLAIN ANALYZE output for new queries touching large tables
Verification
- Migration file exists for every schema change (show migration file list)
- Indexes exist for frequently queried columns (show index definitions)
- EXPLAIN ANALYZE run for new queries on representative data (show output)
- Connection credentials sourced from environment variables
- Transaction scopes are minimal and do not span I/O waits
- Backup and restore procedure documented and tested
- Connection pool settings configured with explicit size and timeout
Cloud Vendor Guide (absorbed from moai-platform-database-cloud)
Cloud database platform selection and configuration for Neon, Supabase, and Firebase Firestore.
Quick Decision Guide
| Need | Platform |
|---|---|
| Serverless PostgreSQL with auto-scaling | Neon |
| Database branching for CI/CD previews | Neon branching |
| Edge-compatible connection pooling | Neon + Neon Proxy |
| Vector search (pgvector) for AI/ML | Supabase |
| Row-Level Security for multi-tenant apps | Supabase RLS |
| Real-time subscriptions + full-stack | Supabase |
| Mobile-first with offline sync | Firebase Firestore |
| Cross-platform (iOS/Android/Web) | Firebase Firestore |
Neon (Serverless PostgreSQL)
Key features: Auto-scaling compute, scale-to-zero, database branching, pg_bouncer pooling.
Setup:
npm install @neondatabase/serverless
# Connection string: postgresql://user:pass@ep-xxx.neon.tech/dbname?sslmode=require
Branch workflow: Create a branch per PR (neonctl branches create --name pr-123), run migrations, test, delete on merge. Zero cost during idle periods.
Supabase (PostgreSQL 16)
Key features: pgvector, Row-Level Security, real-time subscriptions, built-in auth/storage.
RLS policy pattern:
CREATE POLICY "users_own_data" ON items
FOR ALL USING (auth.uid() = user_id);
pgvector search: SELECT * FROM embeddings ORDER BY embedding <-> $1 LIMIT 10;
Firebase Firestore (NoSQL)
Key features: Real-time sync, offline caching, Security Rules, mobile SDKs.
Security Rules pattern:
match /users/{userId} {
allow read, write: if request.auth.uid == userId;
}
Offline persistence: Enable via enableIndexedDbPersistence(db) (web) or SDK default (mobile).
Full platform reference: modules/cloud-database.md
Refactor Notes
R4 audit verdict (2026-04-23): REFACTOR — MERGE target (absorbs moai-platform-database-cloud) with additional restructuring needed SPEC: SPEC-V3R2-WF-001 §6.2 line 263 Refactor scope (deferred to future sub-SPEC):
- Separate moai-domain-db-docs workflow skill from this query/schema design skill
- Extract cloud vendor deep-dives (Neon, Supabase, Firestore) into dedicated Level-3 modules
- Consolidate overlapping ORM pattern content across database types
This skill is retained in v3.0 but its body will be restructured in a follow-up SPEC. Cloud vendor content absorbed from moai-platform-database-cloud in Wave 1.2.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核