SKILL.md
Add Database Entity
Create entity for $ARGUMENTS.
Steps
- Read the pattern: Open
packages/server/api/src/app/tables/table/table.entity.tsas reference.
- Create entity file at
packages/server/api/src/app/{module}/{name}.entity.ts:
- Use EntitySchema (NOT decorators) - Include ...BaseColumnSchemaPart (id, created, updated) - Use ApIdSchema for foreign key columns ({ ...ApIdSchema, nullable: false }) - Add projectId column + relation to project (CASCADE delete) - Add foreignKeyConstraintName on all join columns - Array columns: { type: String, array: true, nullable: false }
- Register entity: Import and add to
getEntities()array inpackages/server/api/src/app/database/database-connection.ts. This is REQUIRED — TypeORM does NOT auto-discover.
- Create migration:
- Read playbook - Name: {Timestamp}{PascalCaseDescription} (e.g., AddMyFeature1774500000000) - Import in packages/server/api/src/app/database/postgres-connection.ts - Add to getMigrations() array (chronological order) - PGlite: CREATE INDEX (not CONCURRENTLY). Set transaction = false for CONCURRENTLY.
- Create repository:
const myRepo = repoFactory(MyEntity)— call asmyRepo()ormyRepo(entityManager)for transactions.
- Verify:
npm run lint-dev