ent-seed-sql
Ent Seed SQL
Overview
Generate one SQL seed file that can be executed directly. Infer schema and relationships from Ent definitions or other inputs, then create realistic data with referential integrity and deterministic IDs.
Scope
Use this skill when the task is "produce executable seed SQL from Ent and related context."
Do not use this skill when the task is schema migration design, query optimization, or runtime repository/service implementation.
Workflow
-
Collect inputs and constraints:
- Prompt requirements
- Product documentation
- Demo program or existing seed snippets
- Ent schema files, migration files, or table DDL if available
-
Determine SQL dialect:
- Use project evidence first (driver/config/migrations)
- If evidence is insufficient, ask user to confirm dialect first
- If user is unavailable and you must proceed, fall back to SQLite-compatible SQL and mark it as an explicit assumption
- State dialect assumptions explicitly in the SQL header comment
-
Build schema map:
- Extract entities, required fields, unique constraints, enum-like fields
- Extract relationships and cardinality (1-1, 1-N, N-N)
- Resolve insertion order by dependency (parent before child)
-
Choose seed execution strategy before writing SQL:
- One-shot: plain inserts, may fail on rerun
- Idempotent: cleanup or conflict-safe inserts
- Upsert-style: update-on-conflict when explicitly needed
- Record chosen strategy in SQL header comments
-
Design deterministic sample records:
- Choose stable IDs with business meaning, never purely random values
- Keep cross-table references consistent
- Ensure values look realistic and match domain semantics
-
Generate one executable SQL seed file:
- Use transaction-safe structure where supported
- Insert in dependency order
- Add concise comments for assumptions and special handling (e.g., password hash)
- Ensure conflict handling matches chosen execution strategy and target dialect
-
Self-check before finalizing:
- No orphan foreign keys
- No duplicate unique keys unless intentional conflict strategy is used
- No TODO placeholders left in SQL
- IDs and references remain deterministic across reruns
- If local tooling is available, run at least one lightweight syntax/execution check
Output Contract
Produce one SQL seed artifact by default (inline SQL or file write, based on user request):
- Header comment: source inputs, dialect, assumptions
- Strategy comment: one-shot / idempotent / upsert
- Optional cleanup section (only when requested or chosen as the strategy)
INSERTstatements grouped by table in dependency order- Optional verification
SELECTstatements at the end (only when requested)
Use deterministic and meaningful IDs:
- Integer IDs: reserve fixed ranges per table/entity group
- String IDs: use semantic patterns (
usr_alice,team_core_platform) - UUID IDs: derive deterministic UUID from stable keys, not random UUID4
Guardrails
- Never generate unrelated random data just to increase row count.
- Never break foreign key dependencies.
- Never invent columns or tables not supported by evidence; if inferred, mark as assumption.
- Never assume nullable fields are safe defaults when business semantics require explicit values.
- Prefer explicit column lists in every
INSERT. - Keep row count pragmatic: enough to demonstrate relationships and product flow, not bloated.
Password Handling
When seed data includes credentials:
- Detect hashing algorithm from code/docs first (bcrypt/argon2/pbkdf2).
- Prefer reusing known valid hash samples from fixtures/docs.
- If hashing is required and no hash sample exists, generate hash output once, then pin that literal in SQL for deterministic reruns.
- For salted algorithms (bcrypt/argon2), generation output is intentionally non-deterministic; seed determinism is achieved by reusing pinned hash literals.
- Document the plain test password only when user allows it for dev/test usage.
References
- Use model extraction guide to infer entities and relationships.
- Use ID and relationship rules to enforce deterministic linking.
- Use SQL output pattern for final SQL layout and checks.
- Use password hash notes only when credential fields exist.
Execution Notes
This skill is AI-first and does not require dedicated generation scripts. Use scripts only for narrow tasks such as one-time password hash generation.
More from go-sphere/skills
ent-seed-sql-generator
Generate deterministic INSERT SQL seed data from Go Ent schemas and mixed inputs. This skill is REQUIRED whenever you need to create seed SQL for development or testing - it handles entity inference, relationship integrity, stable IDs, and dialect-specific SQL generation including JSON, arrays, and complex types. Use this skill for any task involving seed data, test fixtures, demo initialization, or database population from Ent schema definitions, even if the user doesn't explicitly mention "seed" or "SQL".
27pure-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.
16