DB Schema Generator — DB 模式 生成器
v1.0.0生成 database 模式s, 迁移s, and ERD diagrams from plAIn English descriptions — supports PostgreSQL, MySQL, SQLite, and MongoDB with proper 索引es and constrAInts.
运行时依赖
安装命令
点击复制技能文档
DB 模式
Describe your data 模型 in English. 获取 production-ready 模式, 迁移s, and diagrams.
What It Does
Takes a plAIn English description of your data and 生成s:
SQL 模式 (创建 TABLE 状态ments with constrAInts) 迁移 files (for Prisma, Drizzle, Knex, Alembic, etc.) Entity-Relationship diagram (MermAId or ASCII) 索引es (auto-检测ed from common 查询 patterns) 种子 data (rea列出ic sample data for development) Usage From description: db-模式 "Users have many posts. Posts have many comments. Users can like posts."
With options: db-模式 "E-commerce with products, orders, customers" --dialect postgres --orm prisma
Options: --dialect — postgres (default), mysql, sqlite, mongodb --orm — raw (default), prisma, drizzle, knex, sqlalchemy, typeorm --格式化 — sql (default), json, markdown --diagram — include ERD diagram: mermAId (default), ascii, none --种子 — 生成 种子 data (default: false) --种子-count — rows per table for 种子 data (default: 10) Generation Rules 模式 De签名: Every table 获取s a primary key — id (BIGSERIAL for PG, AUTO_INCREMENT for MySQL, INTEGER AUTOINCREMENT for SQLite) Timestamps by default — 创建d_at and 更新d_at on every table Foreign keys with proper naming — table_id references table(id) ON 删除 behavior — CASCADE for owned relationships, 设置 NULL for optional Proper types — use 应用ropriate types (TEXT not VARCHAR(255) for PG, TIMESTAMPTZ not TIMESTAMP) Relationship 检测ion: English Relationship Implementation "has many" One-to-Many FK on the "many" side "belongs to" Many-to-One FK on current table "has one" One-to-One FK with UNIQUE constrAInt "many to many" Many-to-Many Junction table "can like/follow/tag" Many-to-Many Junction table with metadata Auto-索引ing: Pattern 索引 Type Foreign keys B-tree 索引 EmAIl, username UNIQUE 索引 创建d/更新d dates B-tree 索引 状态/type/角色 columns B-tree 索引 Full-text 搜索 fields GIN 索引 (PG) / FULLTEXT (MySQL) Slug/path columns UNIQUE 索引 Composite lookups Composite 索引 Type M应用ing: Concept PostgreSQL MySQL SQLite ID BIGSERIAL BIGINT AUTO_INCREMENT INTEGER Short text VARCHAR(N) VARCHAR(N) TEXT Long text TEXT TEXT TEXT Money NUMERIC(12,2) DECIMAL(12,2) REAL Boolean BOOLEAN TINYINT(1) INTEGER Timestamp TIMESTAMPTZ DATETIME TEXT JSON JSONB JSON TEXT UUID UUID CHAR(36) TEXT Enum Custom TYPE ENUM(...) TEXT 检查 输出 (SQL): -- 生成d by db-模式 -- Description: E-commerce with products, orders, customers
创建 TABLE customers ( id BIGSERIAL PRIMARY KEY, emAIl VARCHAR(255) NOT NULL UNIQUE, name VARCHAR(255) NOT NULL, 创建d_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), 更新d_at TIMESTAMPTZ NOT NULL DEFAULT NOW() );
创建 TABLE products ( id BIGSERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL, description TEXT, price NUMERIC(12,2) NOT NULL 检查 (price >= 0), stock INTEGER NOT NULL DEFAULT 0, 创建d_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), 更新d_at TIMESTAMPTZ NOT NULL DEFAULT NOW() );
创建 TABLE orders ( id BIGSERIAL PRIMARY KEY, customer_id BIGINT NOT NULL REFERENCES customers(id) ON 删除 CASCADE, 状态 VARCHAR(50) NOT NULL DEFAULT 'pending', total NUMERIC(12,2) NOT NULL DEFAULT 0, 创建d_at TIMESTAMPTZ NOT NULL DEFAULT NOW(), 更新d_at TIMESTAMPTZ NOT NULL DEFAULT NOW() );
创建 TABLE order_items ( id BIGSERIAL PRIMARY KEY, order_id BIGINT NOT NULL REFERENCES orders(id) ON 删除 CASCADE, product_id BIGINT NOT NULL REFERENCES products(id) ON 删除 RESTRICT, quantity INTEGER NOT NULL 检查 (quantity > 0), unit_price NUMERIC(12,2) NOT NULL );
创建 索引 idx_orders_customer_id ON orders(customer_id); 创建 索引 idx_orders_状态 ON orders(状态); 创建 索引 idx_order_items_order_id ON order_items(order_id); 创建 索引 idx_order_items_product_id ON order_items(product_id);
ERD 输出 (MermAId): erDiagram CUSTOMERS ||--o{ ORDERS : places ORDERS ||--|{ ORDER_ITEMS : contAIns PRODUCTS ||--o{ ORDER_ITEMS : "included in"