kmaruthi2002/universal-llm-skills/database-design

Claude Code and agent skill by kmaruthi2002/universal-llm-skills

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Choose the right kind of data store and design the data model inside it: relational, document, key-value, wide-column, graph, time-series, search, and vector stores; entities and relationships; normalization vs. denormalization; primary and foreign keys; data types; constraints and integrity; indexes for access patterns; multi-tenancy, history, soft deletion, and evolution of the model. Use when starting a schema, adding tables or collections, picking a database, modelling a new feature's data, deciding what to index, fixing integrity problems or duplicated data, or reviewing a data model. For writing and tuning queries use sql-and-queries; for changing a live schema safely use database-migrations.

Install

npx vskill@latest install kmaruthi2002/universal-llm-skills/database-design

SKILL.md

The same SKILL.md was published earlier as kmaruthi2002/universal-llm-skills/database-design.

Database Design

Data outlives code. Applications get rewritten; the data model, and the data in it, usually survives. A good design makes invalid data impossible to store, makes the common queries cheap, and can evolve without rewriting everything. A poor one produces bugs that no amount of application code can fully contain, because the store itself lets contradictions in.

Scope

Covers choosing a store type, conceptual and logical modelling, physical schema (types, keys, constraints, indexes), and design patterns for recurring needs (tenancy, history, soft delete, hierarchies, polymorphism, money, time).

Neighbours:

  • Writing correct and efficient queries, reading query plans — sql-and-queries.
  • Changing a schema that is already in production — database-migrations.
  • Replication, partitioning, consistency across machines — system-design.
  • Cleaning or validating existing data — data-cleaning-and-validation.
  • Vector stores in the context of retrieval systems — rag-systems.

Core principles

1. Model the domain truthfully, then optimise for access

First capture what is true about the world: which things exist, what identifies them, how they relate, what rules always hold. Then shape the physical design around how the data is read and written. Skipping the first step leads to models that encode one screen's needs and break with the next feature. Skipping the second leads to elegant models that are too slow.

2. Let the database enforce what must always be true

Uniqueness, required values, valid references, allowed ranges, and allowed states are best enforced by the store itself (unique constraints, NOT NULL, foreign keys, check constraints, enum or domain types, schema validation in document stores). The "why": application code has many paths — handlers, jobs, scripts, admin consoles, future services, manual fixes — and every one of them will eventually skip a check. A constraint applies to all of them, and under concurrency it is the only check that is reliable.

3. Every fact in one place, unless you have a reason

Normalisation exists to avoid update anomalies: if a customer's address is stored in five places, an update will eventually miss one. Store each fact once and derive the rest. Denormalise deliberately, for measured read performance or for history (see below), and know who keeps the copies consistent.

4. Design from access patterns, especially for non-relational stores

Write down the queries before the schema: "fetch a user's 20 most recent orders with totals", "find all open tickets assigned to team X ordered by priority", "count events per device per minute". Relational stores tolerate unanticipated queries reasonably well; document, key-value, and wide-column stores often do not — their schema is their query plan.

5. Choose boring technology unless the problem demands otherwise

A mainstream relational database handles a remarkably wide range of workloads — transactional data, JSON documents, full-text search, geospatial data, moderate time-series, even vector similarity with extensions — with mature tooling, strong integrity, and well-understood operations. Add a specialised store when a measured requirement exceeds what the general one does well, not because the data "looks like" a graph or a document.

6. Names and types are part of the contract

Columns and tables are read by many people and tools for years. Clear, consistent names and precise types (not strings for everything) prevent whole classes of bugs and make the model self-documenting.

Discovering context

Before designing or changing a model:

  • Find the existing schema: migration files, schema dumps, ORM model definitions, or (with permission) introspect the database's catalog. The migrations history shows how the model evolved and which decisions were deliberate.
  • Learn the conventions: table naming (singular/plural, case), primary key type and naming, foreign key naming, timestamp columns, soft-delete approach, tenant column, enum handling, index naming. New tables should be indistinguishable in style from existing ones.
  • Identify the engine and version: features (partial indexes, generated columns, JSON operators, check constraints, deferrable constraints) differ by engine and version.
  • Find the access patterns: the queries the application runs (repository code, ORM usage, slow-query logs, query statistics views), and their frequency.
  • Learn data volumes and growth: rows per table, growth per month, largest tenants. Design choices differ for thousands vs. billions of rows.
  • Check retention, privacy, and compliance requirements for the data: personal data, deletion obligations, audit needs, residency.

Choosing a store

Store typeStrong atWeak atChoose when
Relational (row store)Integrity constraints, transactions across entities, flexible ad hoc queries and joins, mature toolingHorizontal write scaling (without sharding or distributed SQL), very wide sparse recordsDefault for business data: users, orders, accounts, anything with relationships and invariants
Distributed SQLRelational semantics with horizontal scale and multi-regionHigher latency per transaction, operational and cost complexityRelational needs that genuinely exceed one primary's capacity or need multi-region writes
DocumentHierarchical records read and written as a unit, flexible per-record shapeCross-document joins and transactions (limited or costly), enforcing referencesSelf-contained aggregates (a product catalogue entry, a content item, a form submission) with varied shape
Key-valueExtremely fast get/put by key, simple scalingAnything but key lookup; secondary queriesCaches, sessions, feature flags, idempotency keys, counters
Wide-columnMassive write throughput, predictable queries by partition key, time-ordered data within a partitionAd hoc queries, joins, transactions across partitionsVery large-scale event, messaging, or IoT data with known query shapes
GraphMulti-hop relationship traversal with variable depthBulk analytics over all data, simple tabular accessQueries like "friends of friends who…", fraud rings, dependency graphs, where traversal depth is variable and central
Time-seriesHigh-rate timestamped appends, downsampling, retention, time-window aggregationUpdating past data, relational lookupsMetrics, sensor data, monitoring, financial ticks
Search engineFull-text relevance, faceting, fuzzy matchingBeing the source of truth, transactions, strong consistencySearch over text, product search, log exploration — fed from the source of truth
Vector store / indexNearest-neighbour similarity over embeddingsExact filtering at scale (varies), transactional updatesSemantic search, recommendation, retrieval for LLM applications
Columnar analytics warehouseAggregations over billions of rows, compressionSingle-row lookups and updates, high-rate small transactionsReporting and analytics, separate from the operational store

Practical guidance:

  • Start with one relational store as the source of truth for most products. Add a cache, a search index, or an analytics warehouse as derived stores fed from it.
  • Keep one source of truth per fact. Derived stores (search, cache, warehouse) can be rebuilt from the source; if they cannot, they have become a second source of truth and need the same care.
  • Polyglot persistence has a cost: more operations, more failure modes, and synchronisation between stores (see the dual-write discussion in system-design).
  • Many relational engines offer JSON columns, full-text search, and vector extensions; these often suffice at moderate scale and avoid a second store.

For modelling in document, key-value, wide-column, graph, time-series, and vector stores, read references/non-relational-modelling.md.

Process for relational modelling

Step 1: Entities, identity, and relationships

List the entities (nouns the business cares about), what uniquely identifies each in the real world (if anything), and the relationships: one-to-one, one-to-many, many-to-many. For each relationship, ask whether it is required, whether it can change over time, and whether its history matters.

Step 2: Attributes and rules

For each entity, list attributes with their type, whether they are required, allowed values or ranges, and rules that involve several attributes ("ends_at after starts_at", "exactly one of user_id or team_id"). These become types and constraints.

Step 3: Normalise

Aim for third normal form as the default — informally, every non-key column describes the key, the whole key, and nothing but the key:

  • No repeating groups or lists packed into a column (comma-separated IDs, phone1, phone2, phone3). Use a child table.
  • No columns depending on only part of a composite key.
  • No columns depending on other non-key columns (storing country_name next to country_code in every row).
Step 4: Map access patterns and decide denormalisation

Walk each important query against the model. Where a hot query needs many joins or aggregations over large data and is measured (or confidently estimated) to be too slow, consider: an index first; then a materialised view or summary table; then a denormalised column maintained by the application or a trigger. Document every denormalisation and how it is kept consistent.

Step 5: Physical design

Choose types, keys, constraints, and indexes (sections below). Name everything per the project's conventions.

Step 6: Plan evolution

Consider which parts are likely to change (new states, new relationship cardinalities, new tenants) and make those changes additive where you can. Write the schema as migrations (see database-migrations).

Step 7: Review with real or realistic data

Load representative data volumes if you can and run the key queries. Check plans and timings (see sql-and-queries).

Keys

This is the start of the file. Read the full SKILL.md on GitHub.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/kmaruthi2002/universal-llm-skills/database-design/badge)](https://verified-skill.com/skills/kmaruthi2002/universal-llm-skills/database-design)

Something wrong with this skill or its page? Tell us.