ent

Guides Ent ORM schema changes, code regeneration, and Postgres type mappings in Go.

2.2k|210|Updated Jun 6, 2023
One-click install
npx skills add https://github.com/openmeterio/openmeter --skill ent
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ent
Source: https://github.com/openmeterio/openmeter/tree/main/.agents/skills/ent
Command: npx skills add https://github.com/openmeterio/openmeter --skill ent

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Working with Ent ORM in a large Go codebase involves subtle pitfalls: Postgres array columns silently mapping to jsonb, truncated identifier names colliding, upserts that fail to clear nullable fields, and generated code that must never be hand-edited. This Skill encodes those hard-won conventions so schema changes and query work are done correctly the first time.

Core Features & Use Cases

  • Schema authoring guidance: Correct patterns for Postgres text[] columns via field.Other with pq.StringArray, char(26) ULID foreign keys, soft-delete unique indexes, and JSONB value scanners.
  • Custom selects and joins: Use generated entselectedparse helpers like db.Parse<Entity>FromSelectedValues instead of hand-written row scanners.
  • Update and upsert correctness: Rules for UpdateNewValues(), SetOrClear<Field> helpers, and pointer GoTypes that lack SetNillable<Field> variants.
  • Use Case: You add a new nullable column to an Ent schema, regenerate with make generate, and need the upsert path to properly clear the column when the value is absent.

Quick Start

Ask the assistant to modify an Ent schema under openmeter/ent/schema and regenerate the code following the ent skill conventions.

Frequently Asked Questions about ent

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a Postgres text[] array column in Ent?

Use field.Other with pq.StringArray and a SchemaType mapping of text[] for the Postgres dialect, importing github.com/lib/pq. Avoid field.Strings, which creates jsonb or breaks the runtime encode/decode path.

How do I regenerate Ent code after a schema change?

Edit files under openmeter/ent/schema and run make generate to regenerate all generated Go code. For faster local iteration, run go generate ./openmeter/ent/... to regenerate only Ent output.

Why does my Ent upsert not clear a nullable field?

UpdateNewValues only updates fields set on the create mutation, so unset optional fields keep their old values. Chain the generated Update<Field>() method explicitly after UpdateNewValues to write NULL.

Why do Ent-generated index or foreign key names collide in PostgreSQL?

PostgreSQL truncates identifiers at 63 bytes, so long generated names can collide. Shorten them proactively with StorageKey on edges and indexes before generating migrations.

Can I edit the generated Ent code in the db directory directly?

No, files under openmeter/ent/db are generated and must not be edited manually. Make changes in the schema definitions and regenerate the code instead.