add-entity

Creates a TypeORM entity with repository, module registration, and hand-written migration enforcing database invariants.

Updated Jul 26, 2026
One-click install
npx skills add https://github.com/aymansalkhatib/medledger --skill add-entity-aymansalkhatib
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: add-entity
Source: https://github.com/aymansalkhatib/medledger/tree/main/.claude/skills/add-entity
Command: npx skills add https://github.com/aymansalkhatib/medledger --skill add-entity-aymansalkhatib

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Adding a new table to a NestJS/TypeORM codebase involves many coordinated steps — the entity class, a repository, module wiring, and a migration — and it is easy to lose database-level invariants (CHECK constraints, partial unique indexes, enum types) when relying on generated migrations. This Skill walks through the full workflow so the schema, entity, and module stay consistent. ## Core Features & Use Cases - Entity scaffolding with project conventions: snake_case table and column names, prefixed string ids, timestamptz timestamps, bigint transformers, and enum columns created exactly as the codebase expects. - Transaction-safe repository pattern: repositories accept an EntityManager for mutation writes, use conditional updates or SELECT FOR UPDATE for balance rows, and never expose the raw Repository to services. - Hand-written migrations with invariants: raw SQL migrations carrying CHECK constraints, named indexes, enum types, and exact up/down reversal, cross-checked against the entity via a throwaway generated migration. - Use Case: Ask to add a WasteRecord entity to the holdings module and receive the entity file, repository, updated module registration, and a pending migration with non-negativity CHECK constraints, ready for review before running. ## Quick Start Add a WasteRecord entity to the holdings module with its repository and migration.

Frequently Asked Questions about add-entity

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

FAQPage Schema
How do I add a TypeORM entity to an existing NestJS module?▼

Create the entity class under the module's entities folder, add a repository, register the entity in TypeOrmModule.forFeature, and add the repository to providers. Then write a migration for the table and verify with lint, build, and migration:show.

Why hand-write TypeORM migrations instead of generating them?▼

Generated migrations cannot express database-level invariants like CHECK constraints, partial unique indexes, BIGSERIAL sequences, or append-only triggers. Hand-written SQL keeps those rules in the schema; a generated migration is used only as a diff check and then deleted.

How should a TypeORM repository handle transactions in NestJS?▼

Any write belonging to a mutation should take an EntityManager as its first parameter and run through it, so it joins the caller's transaction. Reads outside mutations use the injected Repository, and balance changes use conditional updates or SELECT FOR UPDATE.

Should TypeORM entities use timestamp or timestamptz columns?▼

Use timestamptz for all timestamps to avoid local-time ambiguity. Domain times supplied by the caller, like recorded_at, are plain columns distinct from the database-managed created_at.

When should a foreign key use RESTRICT versus CASCADE in TypeORM?▼

Use RESTRICT for record-bearing parents so referenced rows cannot be deleted while children exist. Use CASCADE only for rows owned outright by their parent, where deletion of the parent should remove the children.