Skip to content

A Practical Database Schema Review Checklist

Review a production database schema for integrity, ownership, time and history, tenant safety, query paths, migrations, and recoverability before it becomes expensive to change.

A database schema review asks whether the database protects the product’s important facts when application code is wrong, retried, or deployed gradually. It is not mainly a naming review. Table names can be fixed with a rename. A missing uniqueness rule, a tenant key left out of a constraint, or a migration that cannot run alongside the previous release creates damage that is much harder to undo.

The schema usually outlives the application code around it. Frameworks get replaced, services get split, but the tables and the data in them stay. That is why I review the schema whenever a feature introduces a new concept, a new relationship, or a new way of querying existing data. This checklist is written with PostgreSQL in mind, but nearly all of it applies to any relational database.

Start from the product facts

Before reading table definitions, list the facts the product must never get wrong. For example:

  • a user belongs to an organization with exactly one role;
  • an invoice is paid at most once;
  • an email address is unique within an organization;
  • a deleted project’s files are removed after a retention period;
  • an imported row is imported once, even if the import is re-run.

Then check whether each fact is enforced by the database, enforced only by application code, or not enforced at all. This list is more useful than reviewing every column in alphabetical order.

Product factWhere to enforce itTypical mechanism
Every record is identifiableDatabasePrimary key
Relationships stay validDatabaseForeign key with intentional delete behavior
Business identity is uniqueDatabaseUnique constraint, often composite with tenant
Values stay within valid statesDatabase where possibleCheck constraint or enum type
Rules depending on other rows or external stateApplication, backed by locks or constraintsTransaction with conditional update
Who may change whatApplicationAuthorization in the API

Integrity first

  • Every table has a stable primary key.
  • Required relationships use foreign keys, or a documented reason explains why not.
  • Foreign keys have intentional ON DELETE behavior: restrict, cascade, or set null.
  • Uniqueness represents business identity, not only implementation convenience.
  • Columns that must have a value are NOT NULL.
  • Check constraints protect valid ranges and states where possible.
  • Money is stored as an integer in minor units or an exact decimal type, never a float.

An application-level “check then insert” cannot reliably prevent duplicates under concurrency. Two requests can both check, both find nothing, and both insert. If an email must be unique within an organization, express that as a composite unique constraint on (organization_id, lower(email)) or an equivalent normalized column.

The same principle protects background work. A unique constraint on (import_id, source_row_number) turns a duplicate import attempt into a harmless error instead of duplicate data. Background jobs that do not lose work depend on constraints like this to be safely retried.

Model ownership and deletion deliberately

For every table, someone should be able to answer:

  • Which module or service owns writes to it?
  • Which other parts of the system read it?
  • What happens to these rows when the parent is deleted?
  • How long must the data be kept, and when must it be removed?

Deletion is where schemas often get vague. Cascading deletes are convenient and can remove far more than intended. Soft deletes, such as a deleted_at column, help with recovery and audit, but they require every query to exclude deleted rows and every unique constraint to account for them, for example through a partial unique index on rows where deleted_at is null. Soft deletes also do not satisfy a requirement to actually erase personal data.

Choose per table, write the rule down, and make it consistent.

Model time and change

Decide whether each value represents a current state, an event, or a versioned fact.

  • A task’s status may be enough as current state.
  • Payments, subscriptions, and permission changes usually need a history that explains how the current state came to be.
  • Prices, tax rates, and plan limits often need effective dates, because old orders must keep the values that applied at the time.

Timestamp guidelines:

  • Store timestamps in UTC with a time-zone-aware type.
  • Use names with clear meaning: created_at, updated_at, completed_at, cancelled_at.
  • Store a user’s time zone separately when scheduling depends on local time.
  • Do not overload one timestamp to mean several things.

If support regularly asks “when did this change and who changed it?”, the schema needs an audit table or an event history for that entity.

Tenant safety

For a multi-tenant SaaS product, data isolation is the highest-impact property in the schema.

  • Every tenant-owned table includes the tenant key, even if it could be derived through a join.
  • Unique constraints that represent business identity include the tenant key.
  • Indexes used by tenant-scoped queries start with the tenant key where it fits the query.
  • Foreign keys cannot link a row in one tenant to a row in another, for example by including the tenant key in composite foreign keys.
  • Row-level security is considered as a second layer, not a replacement for application scoping.

Never rely on a UI filter for isolation. The API must resolve the tenant and authorize the operation before any query runs; the backend API design checklist covers that side of the boundary.

Review real query paths

An index is only useful when it supports a real filter and ordering pattern. Review the queries behind the product’s actual screens, endpoints, and jobs.

  • List the main queries for each high-traffic screen and job.
  • Confirm an index supports the WHERE and ORDER BY of each, in a useful column order.
  • Check query plans on realistic data volumes, not an almost empty development database.
  • Remove or avoid indexes that no query uses; every index slows writes.
  • Watch for queries that load unbounded result sets.
  • Look for N+1 query patterns in the application’s data access.

Large JSON or JSONB columns deserve a specific look. They are useful for flexible attributes and payload storage. They become a problem when the application filters, joins, or enforces rules on fields inside them, because those fields lose the constraints and clear types that columns give you.

Migrations are part of the design

A production deployment is a transition, not an instant switch. For some period, old application code may run against the new schema, or new code against the old schema. Design migrations for that overlap.

Prefer expand and contract:

  1. Add a compatible column or table. Do not remove or rename anything yet.
  2. Deploy code that can read both shapes and writes to both where needed.
  3. Backfill existing data in controlled batches.
  4. Move reads and writes to the new shape and verify.
  5. Remove the old shape in a later release.
flowchart LR
  accTitle: Expand and contract schema migration
  accDescr: A compatible schema change is added first, then application code that handles both shapes is deployed, data is backfilled in batches, reads and writes move to the new shape and are verified, and the old shape is removed in a later release.
  E["Expand:<br/>add compatible shape"] --> D["Deploy code<br/>that handles both"]
  D --> B["Backfill<br/>in batches"]
  B --> S["Switch reads<br/>and writes"]
  S --> V["Verify"]
  V --> C["Contract:<br/>remove old shape later"]

Migration review questions:

  • Can the previous application version run against the migrated schema?
  • Does the migration take locks that block writes on a large table?
  • Are new indexes on large tables created concurrently where the database supports it?
  • Is adding a NOT NULL column done with a default or a backfill first?
  • Is the backfill batched, resumable, and observable?
  • What happens if the migration fails halfway, and how is it retried?
  • Is there a backup taken or verified before a destructive step?

A migration is incomplete if the team cannot explain what happens when it fails halfway.

Recoverability

  • Automated backups exist, with retention that matches the business need.
  • A restore has been tested recently, and the time it takes is known.
  • Point-in-time recovery is available for the main database if the product needs it.
  • Uploaded files and object storage have their own backup and retention policy.
  • Derived data, such as search indexes and caches, can be rebuilt from source data.
  • Repair scripts and manual data corrections are reviewed and recorded.

A backup that has never been restored is an assumption, not a recovery plan.

Reviewing an inherited schema

When you take over an existing product, the schema often tells you the real domain rules faster than the code. Look for missing constraints that explain recurring bugs, columns that are always null, tables that nothing reads, and migration history that does not match production. The 30-day checklist for taking over an existing codebase includes a data review step that pairs well with this checklist.

Fix inherited schema problems with the same expand-and-contract approach. Clean existing data first, then add the constraint, so the migration does not fail on rows that already violate it.

Database schema review checklist

  • Product facts that must never be wrong are listed and mapped to enforcement.
  • Primary keys, foreign keys, NOT NULL, unique, and check constraints are in place.
  • Delete behavior and retention are intentional per table.
  • Money uses exact types; timestamps use UTC with clear names.
  • History or effective dates exist where the business needs them.
  • Tenant keys are present in tenant-owned tables, constraints, and indexes.
  • Indexes match real query paths verified on realistic data.
  • Migrations follow expand and contract and are safe to run alongside the previous release.
  • Backfills are batched and resumable.
  • Backups and restores are tested, including file storage.

A good schema makes invalid states hard to write and real questions easy to answer. That protection keeps working even when the application code around it is new, rushed, or wrong.

Frequently asked questions

What should a database schema review check?

Check primary keys, foreign keys, uniqueness that matches business identity, check constraints, delete and retention behavior, how time and history are modeled, tenant scoping, indexes against real query paths, migration safety, and backup and restore expectations.

Why use database constraints if the application already validates data?

Application checks can be skipped by another code path, a script, or a bug, and a check-then-insert cannot prevent duplicates under concurrent requests. Constraints enforce the rule for every writer, every time.

How do you change a production schema without downtime?

Use expand-and-contract migrations: add a compatible column or table, deploy code that can work with both shapes, backfill in controlled batches, move writes and reads to the new shape, and remove the old shape in a later release.

Should I use soft deletes?

Only when you need them for recovery, audit, or legal retention, and with a clear rule for how queries exclude deleted rows and how unique constraints treat them. Soft deletes everywhere add filtering bugs and do not satisfy data deletion requirements by themselves.

[NL] Newsletter

Practical notes for building work that lasts.

Occasional field notes on product engineering, architecture, and delivery. No recycled growth hacks.

Start with the free production readiness checklist

Check your inbox to confirm your subscription.

Processed by Brevo