ent-seed-sql-generator
Ent Seed SQL Generator
Produce one executable seed SQL artifact from Ent schemas and mixed evidence — with deterministic IDs, valid relationships, and realistic production-like data. Confirm the generation plan before writing SQL so that dialect, strategy, and scope mismatches are caught before they waste effort.
Trigger / Non-Trigger
Use this skill when the task is to generate or revise seed SQL from Ent schema context, docs, demo behavior, or prompt requirements.
Do not use this skill for schema migration design, runtime repository/service implementation, or query performance tuning.
Reference Loading Plan
Load only what is needed for the current task:
- references/model-extraction.md: entity/field/relation extraction and dependency planning
- references/id-and-relation-rules.md: deterministic IDs, FK integrity, multi-tenant constraints
- references/output-sql-pattern.md: final SQL layout and strategy-specific patterns
- references/password-hashing.md: only when credential fields are seeded
Checklist
Work through these in order. Create a task for each item.
- Collect inputs — prompt, Ent schema files, existing seeds, product docs
- Detect dialect and resolve ambiguities — ask one question at a time if unclear
- Present generation plan — entities, strategy, row counts; get approval
- Build schema map — dependency order, FK graph, enum values
- Generate SQL artifact — following output-sql-pattern.md
- Run quality gates — orphan FKs, unique violations, missing required fields
Process Flow
digraph ent_seed_sql_generator {
"Collect inputs" [shape=box];
"Any ambiguities?" [shape=diamond];
"Ask clarifying question\n(one at a time)" [shape=box];
"Present generation plan" [shape=box];
"Plan approved?" [shape=diamond];
"Build schema map\n& dependency order" [shape=box];
"Generate SQL artifact" [shape=box];
"Quality gates" [shape=box];
"Deliver artifact" [shape=doublecircle];
"Collect inputs" -> "Any ambiguities?";
"Any ambiguities?" -> "Ask clarifying question\n(one at a time)" [label="yes"];
"Ask clarifying question\n(one at a time)" -> "Any ambiguities?";
"Any ambiguities?" -> "Present generation plan" [label="no"];
"Present generation plan" -> "Plan approved?";
"Plan approved?" -> "Present generation plan" [label="revise"];
"Plan approved?" -> "Build schema map\n& dependency order" [label="yes"];
"Build schema map\n& dependency order" -> "Generate SQL artifact";
"Generate SQL artifact" -> "Quality gates";
"Quality gates" -> "Deliver artifact";
}
Phase 1: Collect Inputs and Clarify
Gather available inputs in this order:
- Current prompt requirements
- Ent schemas and migration/DDL files (
ent/schema/*.go,ent/migrate/) - Existing seed files and demo code behavior
- Product docs and domain notes
Then detect the SQL dialect:
- Check
ent/client.goor config for driver name (mysql,postgres,sqlite) - Look at migration files for dialect-specific syntax
- Check
go.modfor dialect imports (ent/dialect/mysql, etc.)
If any of the following are unclear after reading available inputs, ask one question at a time:
- Dialect: "I couldn't determine the database dialect from the project files. Which are you targeting — MySQL, PostgreSQL, or SQLite?"
- Strategy: "Should this seed be one-shot (fresh setup only), idempotent (
INSERT OR IGNORE/ON CONFLICT DO NOTHING), or upsert (ON CONFLICT DO UPDATE)?" - Scope: "Should I seed all entities, or a specific subset? If a subset, which ones?"
- Row counts: "How many rows per entity? (3-10 is typical for development seeds)"
Do not ask questions that can be answered from the available files. Ask only what genuinely changes the output.
Phase 2: Generation Plan
Before writing SQL, present a compact plan:
Dialect: MySQL Strategy: idempotent Entity order (by dependency):
organizations— 3 rows, no dependenciesusers— 5 rows, FK → organizationsprojects— 4 rows, FK → organizations + usersID ranges: organizations 2000–2999, users 1000–1999, projects 3000–3999 Assumptions: password fields will use a fixed bcrypt hash for test credentials
Does this look right before I start writing?
Scale the plan to the complexity of the task. For a single entity with no FKs, a one-line summary is enough. For multi-tenant systems with many tables, list the full dependency order.
Phase 3: Build Schema Map
After plan approval, read references/model-extraction.md and extract from ent/schema/*.go:
- Fields: type,
Optional,Nillable,Unique,Default,Immutable,Sensitive - Enums: all valid values from
field.Enumorvalidaterules - Edges:
edge.To,edge.From,Required,Unique,Ref— derive FK ownership - Indexes: unique constraints and composite indexes
Compute topological dependency order: tables with no FK references first, dependent tables after. Join tables last.
Phase 4: Generate SQL Artifact
Follow references/output-sql-pattern.md. Apply references/id-and-relation-rules.md for ID ranges and FK integrity.
ID Assignment:
- Integer PKs: use non-overlapping ranges per entity type
- String PKs: use semantic IDs (
usr_admin,org_acme) - UUIDs: deterministic from business keys, never random
Data Coherence:
- Timestamps:
created_at <= updated_at, spread across realistic ranges - Status progressions: realistic lifecycle (
draft → active → archived) - Ownership: every
owner_idreferences an existing user row - Text content: meaningful strings, not Lorem Ipsum; real email patterns
For credential fields, read references/password-hashing.md.
Dialect-specific patterns:
| Type | PostgreSQL | MySQL | SQLite |
|---|---|---|---|
| JSON | '{"k":"v"}'::jsonb |
'{"k":"v"}' |
'{"k":"v"}' |
| Array | ARRAY['a','b'] |
not native | not native |
| Bool | TRUE/FALSE |
1/0 |
1/0 |
| Timestamp | '2026-01-01 09:00:00' |
'2026-01-01 09:00:00' |
'2026-01-01 09:00:00' |
Special cases to handle inline:
- Soft deletes: set
deleted_attoNULLfor active records - Self-referential (trees): insert root first, children reference valid parent IDs
- Multi-tenant: seed tenant table first; all dependent tables must carry valid tenant FK
- Composite unique constraints: verify all column combinations are unique across rows
Phase 5: Quality Gates
Before delivering, verify:
- No orphan FKs — every referenced ID exists
- No unique constraint violations — including composite unique indexes
- No placeholder or TODO values
- All IDs are deterministic (no random or auto-generated values)
- Timestamps are internally consistent (
created_at <= updated_at) - All required fields (
Required()in Ent schema) are present in every INSERT - No invalid enum values
- JSON columns contain valid JSON strings
Output Contract
Deliver exactly one SQL artifact (inline or file, per user request) with:
- Header comments: source inputs, dialect, strategy, assumptions
- Optional cleanup block (only for idempotent/upsert strategies)
INSERTblocks grouped by dependency order, each group preceded by a comment- Optional verification
SELECTqueries (only when requested)
Guardrails
- Never invent tables or columns without evidence — mark inferences as comments
- Never use random IDs — seed IDs must be stable across runs
- Never break FK dependency order — parents before children, join tables last
- Never bloat row counts — 3–10 rows per core table is usually sufficient
- Never expose production credentials — use test-only values
- Never mix dialects in one file
- Never omit required fields
More from go-sphere/skills
pure-admin-crud-generator
Generate CRUD pages and router modules for pure-admin-thin from local swagger API definitions. MUST be used whenever you need to scaffold admin list/edit/detail pages, dashboard views, or route configurations from existing API methods in src/api/swagger/Api.ts. This skill replaces manual Vue page creation - use it for any admin panel development task involving API-driven pages.
25proto-api-generator
Design proto3 + HTTP API contracts for go-sphere scaffold projects from prompts, input folders, or requirement docs with mock data. Use when defining service APIs, selecting between entpb/shared/custom messages, and enforcing scaffold conventions, router-safety rules, and service-local error placement. This skill is REQUIRED for any proto API design task in go-sphere scaffold - always use it instead of writing proto files from scratch.
21sphere-feature-workflow
Implement end-to-end feature changes in go-sphere scaffold projects by following sphere-layout conventions and generation workflow. Use when adding or modifying APIs, protobuf contracts, Ent schemas, bind/map registration, service logic, or cross-layer refactors that must stay protocol-first and avoid manual edits to generated files. This skill is REQUIRED for any task involving go-sphere proto files, Ent schemas, service implementations, or generation commands (make gen/proto, make gen/docs, make gen/wire).
19proto-service-generator
Generate or complete Go service implementations from protobuf-generated HTTP interfaces in go-sphere scaffold projects. Use when you need to create `internal/service/<module>/*.go` files, add missing method implementations to existing services, or generate compilable stubs for new proto endpoints. Trigger for: service implementation, proto handler, append-only update, interface assertion, CRUD via Ent, stub method generation.
18ent-schema-generator
Design and generate Go + Ent database schemas for sphere-layout projects from requirements. Use when users describe data models, entity relationships, database tables, or schema changes — including prompts, Markdown docs, existing proto/service files, or demo behavior. Produces implementation-ready schema plans with field definitions, ID strategies, relation designs, indexes, entproto annotations, and bind/render/service integration guidance.
16project-intake
Organize scattered project inputs and generate standardized intake documents. Use when users mention project kickoff, requirement initialization, PRD preparation, input organization, requirement gathering, or turning prototypes/demos/drafts into structured documents. Apply to new feature development, project initialization, requirement clarification, and similar scenarios. Always complete intake before writing PRD or any detailed design.
6