db-modelling

Designs PostgreSQL schemas with Drizzle ORM by mapping domain entities to tables, columns, and indexes.

4|Updated Jul 30, 2026
One-click install
npx skills add https://github.com/gabriellst/codm --skill db-modelling-gabriellst
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: db-modelling
Source: https://github.com/gabriellst/codm/tree/main/.claude/skills/db-modelling
Command: npx skills add https://github.com/gabriellst/codm --skill db-modelling-gabriellst

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Translating a validated domain model into a correct, performant database schema is error-prone: value objects get wrongly split into tables, foreign keys lack indexes, and enums lose type safety. This Skill provides a structured process and enforced patterns for designing Drizzle ORM schemas that mirror the domain model without copying it 1:1. ## Core Features & Use Cases - Domain-to-Schema Mapping: Converts entities and value objects into Drizzle table definitions using pgSchema namespaces per bounded context, with mandatory BaseEntity fields (id, createdAt, updatedAt, version). - Value Object Persistence Strategies: Flattens structured VOs into prefixed columns, stores simple VOs as single columns, and uses a custom typed jsonb wrapper only for VO arrays. - Relationship & Index Design: Defines 1:1, 1:N, and N:M relationships with FK indexes, composite unique constraints, and Drizzle relations declarations. - Use Case: After validating a new Patient aggregate with an Address value object and a list of phone numbers, use this Skill to produce the patients table with flattened address columns, a typed JSONB phones column, and indexed foreign keys before running /migrate. ## Quick Start Ask the agent to design the database schema for a new bounded context entity using the db-modelling skill, then verify the output against the registry.yaml patterns before running /migrate.

Frequently Asked Questions about db-modelling

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

FAQPage Schema
How do I design a Drizzle ORM schema from a domain model?

Start from the validated entity and value objects, then create a table inside a pgSchema namespace for the bounded context. Map domain types to Drizzle columns, add the mandatory BaseEntity fields (id, createdAt, updatedAt, version), and declare enums before the tables that use them.

How should value objects be persisted in PostgreSQL with Drizzle?

Structured value objects like Address are flattened into prefixed columns on the parent table, simple VOs like Email become single columns, and only arrays of VOs use JSONB. Never create a separate table for a non-array value object.

Should I use the stock Drizzle jsonb type with the BunSQL driver?

No. The stock jsonb from drizzle-orm/pg-core causes double-encoding on writes and raw-text passthrough on reads with the BunSQL driver. Import the custom jsonb wrapper from '../types/jsonb' and type it with a generic parameter like jsonb<TagProps[]>('tags').

Do foreign key columns need indexes in Drizzle schemas?

Yes. Every foreign key column must have an index declared in the table's third argument, for example index('order_customer_idx').on(table.customerId). Missing FK indexes are flagged as a bad practice because they degrade join and lookup performance.

When should I not use this database modelling skill?

Do not use it to generate or apply migrations (use /migrate), to design the domain model itself (use /ddd-modeling and /entity first), or to write repository code (use /repository). It only covers schema design decisions.

How are cross-bounded-context references modelled in the schema?

References to aggregates in another bounded context are stored as plain text ID columns without a foreign key constraint. Foreign keys with references() and onDelete policies are only used within the same bounded context.