ln-723-seed-data-generator

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ln-723-seed-data-generator

ln-723-seed-data-generator

Type: L3 Worker Category: 7XX Project Bootstrap Parent: ln-720-structure-migrator
Universal seed data generator with two modes: MIGRATE (parse existing ORM schemas) or GENERATE (create from entity definitions). Outputs to any target format (C#, TypeScript, Python, JSON, SQL).

类型: L3 Worker 分类: 7XX项目启动工具 父项: ln-720-structure-migrator
通用种子数据生成器,支持两种模式:MIGRATE(解析现有ORM架构)或GENERATE(从实体定义创建)。可输出至任意目标格式(C#、TypeScript、Python、JSON、SQL)。

Purpose & Scope

用途与范围

AspectDescription
InputORM schema files (MIGRATE) or entity list (GENERATE)
OutputSeed data files in target format
ModesMIGRATE: parse existing ORM → seed data. GENERATE: entity definitions → seed data
Scope boundaries:
  • Parses ORM schema definitions or accepts entity lists
  • Generates seed data in requested target format
  • Creates realistic sample data using faker libraries
  • Does not generate database migrations, EF Core configs, or ORM models

维度说明
输入ORM架构文件(MIGRATE模式)或实体列表(GENERATE模式)
输出目标格式的种子数据文件
模式MIGRATE:解析现有ORM→生成种子数据;GENERATE:实体定义→生成种子数据
范围边界:
  • 解析ORM架构定义或接收实体列表
  • 按请求的目标格式生成种子数据
  • 使用faker类库生成真实感样本数据
  • 不生成数据库迁移脚本、EF Core配置或ORM模型

Mode Selection

模式选择

ModeWhenInputSource
MIGRATETRANSFORM pipeline — existing ORM schemas foundORM schema filesDrizzle, Prisma, TypeORM, EF Core, SQLAlchemy, Django ORM
GENERATECREATE pipeline — no existing schemasEntity list from ln-700 Phase 0User-provided or starter template (User, Role)
If GENERATE mode receives no entity list, generate starter template with
User
(id, name, email, role, createdAt) and
Role
(id, name, description).

模式适用场景输入来源
MIGRATETRANSFORM流水线——存在现有ORM架构ORM架构文件Drizzle、Prisma、TypeORM、EF Core、SQLAlchemy、Django ORM
GENERATECREATE流水线——无现有架构ln-700阶段0提供的实体列表用户提供或起始模板(User、Role)
若GENERATE模式未收到实体列表,则自动生成包含
User
(id、name、email、role、createdAt)和
Role
(id、name、description)的起始模板。

Target Formats

目标格式

FormatOutput FileFaker LibraryUse Case
C# MockData
MockData.cs
Bogus.NET projects
TypeScript fixtures
seed.ts
Faker.jsNode/React projects
Python factories
factories.py
Faker (Python)Django/Flask projects
JSON
seed.json
API testing, import scripts
SQL
seed.sql
Direct DB seeding

格式输出文件Faker类库适用场景
C# 模拟数据
MockData.cs
Bogus.NET项目
TypeScript 测试夹具
seed.ts
Faker.jsNode/React项目
Python 工厂类
factories.py
Faker (Python)Django/Flask项目
JSON
seed.json
API测试、导入脚本
SQL
seed.sql
直接数据库初始化

Workflow

工作流程

PhaseNameActionsOutput
1Parse/Define1A: Parse ORM schema (MIGRATE) or 1B: Accept entity list (GENERATE)Entity model
2Map TypesApply universal type mapping to target formatTarget type definitions
3Generate Seed DataCreate seed files with faker-based realistic dataSeed data files
4VerifyValidate relationships, check syntaxValid seed files

阶段名称操作输出
1解析/定义1A:解析ORM架构(MIGRATE模式)或1B:接收实体列表(GENERATE模式)实体模型
2类型映射将通用类型转换为目标格式类型目标类型定义
3生成种子数据使用faker类库创建包含真实感数据的种子文件种子数据文件
4验证验证关系、检查语法合法的种子文件

Phase 1: Parse/Define

阶段1:解析/定义

1A: MIGRATE Mode — Parse ORM Schema

1A:MIGRATE模式——解析ORM架构

StepActionReference
1A.1Locate schema file(s)
1A.2Auto-detect ORM type
orm_patterns.md
— ORM Auto-Detection table
1A.3Extract table/model definitions
orm_patterns.md
— per-ORM parsing section
1A.4Extract column definitions with types
orm_patterns.md
1A.5Identify constraints (PK, FK, nullable, unique)
orm_patterns.md
1A.6Extract enum definitions
orm_patterns.md
步骤操作参考文档
1A.1定位架构文件
1A.2自动检测ORM类型
orm_patterns.md
——ORM自动检测表
1A.3提取表/模型定义
orm_patterns.md
——各ORM解析章节
1A.4提取带类型的列定义
orm_patterns.md
1A.5识别约束(主键、外键、可空、唯一)
orm_patterns.md
1A.6提取枚举定义
orm_patterns.md

1B: GENERATE Mode — Accept Entity Definitions

1B:GENERATE模式——接收实体定义

StepActionReference
1B.1Receive entity list from orchestrator (or use starter template)
1B.2Parse entity definitions (name, fields, types)
1B.3Infer relationships from field names (
userId
→ FK to User)
relationship_mapping.md
1B.4Apply default constraints (id = PK,
*Id
= FK)
Output: Entity model with columns, types, and constraints.

步骤操作参考文档
1B.1从编排器接收实体列表(或使用起始模板)
1B.2解析实体定义(名称、字段、类型)
1B.3从字段名推断关系(
userId
→关联至User的外键)
relationship_mapping.md
1B.4应用默认约束(id=主键,
*Id
=外键)
输出: 包含列、类型和约束的实体模型。

Phase 2: Map Types

阶段2:类型映射

Convert entity types to target format types.
StepActionReference
2.1Select target format (from orchestrator params)
2.2Map column types to target format
type_mapping.md
— Universal Type Mapping table
2.3Determine nullable status per target
type_mapping.md
2.4Map foreign keys and relationships
relationship_mapping.md
2.5Transform names to target conventionSee Name Conventions table below
Name Conventions by Target:
TargetClass/ModelProperty/FieldFile
C#PascalCase singularPascalCasePascalCase.cs
TypeScriptPascalCase singularcamelCasecamelCase.ts
PythonPascalCase singularsnake_casesnake_case.py
JSONcamelCasecamelCasekebab-case.json
SQLsnake_case pluralsnake_casesnake_case.sql

将实体类型转换为目标格式类型。
步骤操作参考文档
2.1选择目标格式(来自编排器参数)
2.2将列类型映射至目标格式
type_mapping.md
——通用类型映射表
2.3确定目标格式下的可空状态
type_mapping.md
2.4映射外键与关系
relationship_mapping.md
2.5将名称转换为目标格式的命名规范见下方命名规范表
各目标格式的命名规范:
目标格式类/模型属性/字段文件
C#单数大驼峰大驼峰大驼峰.cs
TypeScript单数大驼峰小驼峰小驼峰.ts
Python单数大驼峰蛇形命名蛇形命名.py
JSON小驼峰小驼峰短横线命名.json
SQL复数蛇形命名蛇形命名蛇形命名.sql

Phase 3: Generate Seed Data

阶段3:生成种子数据

Create seed files with realistic data using faker libraries.
StepActionReference
3.1Determine generation order (parents → children)
relationship_mapping.md
3.2Generate IDs (GUIDs/UUIDs) for all entities
data_generation.md
3.3Generate field values using faker
data_generation.md
,
type_mapping.md
— Faker Integration
3.4Ensure FK relationships valid (child references existing parent ID)
relationship_mapping.md
3.5Write seed file in target format
Faker integration rule: All generated seed files MUST use faker libraries for realistic data with deterministic seeding (fixed seed value for reproducibility).
TargetFaker Setup
C#
var faker = new Bogus.Faker(); Randomizer.Seed = new Random(42);
TypeScript
import { faker } from '@faker-js/faker'; faker.seed(42);
Python
from faker import Faker; fake = Faker(); Faker.seed(42)
Generation order by dependency:
OrderEntity TypeGenerate After
1Root entities (no FK)First
2First-level childrenParents exist
3Second-level childrenGrandparents exist
NDeepest childrenAll ancestors exist

使用faker类库创建包含真实感数据的种子文件。
步骤操作参考文档
3.1确定生成顺序(父实体→子实体)
relationship_mapping.md
3.2为所有实体生成ID(GUID/UUID)
data_generation.md
3.3使用faker生成字段值
data_generation.md
,
type_mapping.md
——Faker集成章节
3.4确保外键关系合法(子实体引用已存在的父实体ID)
relationship_mapping.md
3.5按目标格式写入种子文件
Faker集成规则: 所有生成的种子文件必须使用faker类库生成真实感数据,并保证确定性生成(固定种子值以确保可复现)。
目标格式Faker配置
C#
var faker = new Bogus.Faker(); Randomizer.Seed = new Random(42);
TypeScript
import { faker } from '@faker-js/faker'; faker.seed(42);
Python
from faker import Faker; fake = Faker(); Faker.seed(42)
按依赖关系的生成顺序:
顺序实体类型生成时机
1根实体(无外键)最先生成
2一级子实体父实体已生成
3二级子实体祖父实体已生成
N最深层子实体所有祖先实体已生成

Phase 4: Verify

阶段4:验证

CheckMethodExpected
Syntax validLanguage-specific checkNo syntax errors
FKs validCross-referenceAll FKs point to existing IDs
Types correctType analysisProper types for target format
Names follow conventionPattern checkPer-target naming convention
Faker deterministicRe-run with same seedIdentical output

检查项方法预期结果
语法合法语言特定检查无语法错误
外键合法交叉引用所有外键指向已存在的ID
类型正确类型分析符合目标格式的正确类型
名称符合规范模式检查符合对应目标格式的命名规范
Faker确定性使用相同种子重新生成输出完全一致

Supported ORM Detection

支持的ORM检测

ORMDetection PatternEcosystem
Drizzle
pgTable()
,
mysqlTable()
,
sqliteTable()
Node.js
Prisma
model X {
syntax in
.prisma
files
Node.js
TypeORM
@Entity()
,
@Column()
decorators
Node.js
EF Core
DbContext
,
DbSet<>
,
[Table]
attributes
.NET
SQLAlchemy
Base = declarative_base()
,
Column()
Python
Django ORM
models.Model
,
models.CharField()
Python

ORM检测模式技术生态
Drizzle
pgTable()
,
mysqlTable()
,
sqliteTable()
Node.js
Prisma
.prisma
文件中的
model X {
语法
Node.js
TypeORM
@Entity()
,
@Column()
装饰器
Node.js
EF Core
DbContext
,
DbSet<>
,
[Table]
特性
.NET
SQLAlchemy
Base = declarative_base()
,
Column()
Python
Django ORM
models.Model
,
models.CharField()
Python

Entity Transformation Rules

实体转换规则

SourceTargetTransformation
Table name (plural, snake)Class name (singular, Pascal)
user_profiles
UserProfile
Column name (snake)Property name (target convention)
created_at
CreatedAt
/
createdAt
/
created_at
Enum nameEnum type (Pascal)
status_enum
StatusEnum
FK columnNavigation property
user_id
UserId
/
userId

来源目标转换方式
表名(复数、蛇形命名)类名(单数、大驼峰)
user_profiles
UserProfile
列名(蛇形命名)属性名(目标格式规范)
created_at
CreatedAt
/
createdAt
/
created_at
枚举名枚举类型(大驼峰)
status_enum
StatusEnum
外键列导航属性
user_id
UserId
/
userId

Sample Data Guidelines

样本数据指南

Field TypeSample CountDistribution
Root entities3-5 itemsVaried status/priority
Child entities5-10 itemsDistributed across parents
Leaf entities10-20 itemsRealistic variety

字段类型样本数量分布方式
根实体3-5条包含不同状态/优先级
子实体5-10条均匀分布至各父实体
叶子实体10-20条真实感多样性

Critical Rules

核心规则

  • Single Responsibility: Generate only seed data, no ORM models or migrations
  • Idempotent: Can re-run with same seed to produce identical output
  • Valid Relationships: All FKs must reference existing parent IDs
  • Faker Required: Use faker libraries for realistic data, never random strings
  • Deterministic Seeding: Fixed seed value (42) for reproducibility across re-runs
  • Generation Order: Parents before children, always
  • Mode Awareness: MIGRATE parses files; GENERATE accepts definitions — never mix

  • 单一职责: 仅生成种子数据,不生成ORM模型或迁移脚本
  • 幂等性: 使用相同种子重新运行可生成完全一致的输出
  • 合法关系: 所有外键必须指向已存在的父实体ID
  • 强制使用Faker: 使用faker类库生成真实感数据,禁止使用随机字符串
  • 确定性生成: 使用固定种子值(42)确保多次运行的可复现性
  • 生成顺序: 始终先生成父实体,再生成子实体
  • 模式区分: MIGRATE模式解析文件;GENERATE模式接收定义——禁止混合使用

Definition of Done

完成标准

  • Mode determined (MIGRATE or GENERATE)
  • Entity model extracted/defined with all fields and constraints
  • Target format selected and type mappings applied
  • Seed data files generated with faker-based realistic values
  • Deterministic seeding verified (re-run produces identical output)
  • Foreign keys reference valid parent IDs
  • Names follow target format conventions
  • Sample data includes 5-10 items per entity

  • 确定模式(MIGRATE或GENERATE)
  • 提取/定义包含所有字段和约束的实体模型
  • 选择目标格式并应用类型映射
  • 生成包含faker真实感数据的种子文件
  • 验证确定性生成(重新运行输出一致)
  • 外键均指向合法的父实体ID
  • 名称符合目标格式的命名规范
  • 每个实体的样本数据包含5-10条

Risk Mitigation

风险缓解

RiskDetectionMitigation
Unknown ORM typeAuto-detection failsLog warning, ask orchestrator for ORM hint
Invalid type mappingUnknown column typeUse string as fallback, log warning
FK mismatchFK references non-existent IDGenerate parents first, validate after
No entity list in GENERATEEmpty inputUse starter template (User, Role)
Name collisionDuplicate class/table namesPrefix with feature name
Circular referencesSelf-referencing with cyclesLimit depth, validate graph

风险检测方式缓解措施
未知ORM类型自动检测失败记录警告,向编排器请求ORM提示
无效类型映射未知列类型使用字符串作为 fallback,记录警告
外键不匹配外键引用不存在的ID先生成父实体,生成后验证
GENERATE模式无实体列表输入为空使用起始模板(User、Role)
名称冲突类/表名重复以功能名作为前缀
循环引用自引用存在循环限制深度,验证关系图

Reference Files

参考文件

FilePurpose
references/orm_patterns.md
ORM auto-detection and schema parsing patterns (Drizzle, Prisma, TypeORM, EF Core, SQLAlchemy, Django)
references/type_mapping.md
Universal type mapping (ORM-agnostic → C#, TypeScript, Python) + Faker integration
references/data_generation.md
Realistic sample data patterns and generation rules
references/relationship_mapping.md
FK handling, generation order, relationship inference

Version: 3.0.0 Last Updated: 2026-02-07
文件用途
references/orm_patterns.md
ORM自动检测与架构解析规则(Drizzle、Prisma、TypeORM、EF Core、SQLAlchemy、Django)
references/type_mapping.md
通用类型映射(ORM无关→C#、TypeScript、Python)+ Faker集成规则
references/data_generation.md
真实感样本数据模式与生成规则
references/relationship_mapping.md
外键处理、生成顺序、关系推断规则

版本: 3.0.0 最后更新: 2026-02-07