Black Friday race Join
Software development

Database schema template

Eight tables of an online store with every column, type and key, joined by ten labeled crow’s-foot lines. Four cards record the naming, money, time and delete rules.

The Database schema template

What is a database schema diagram?

A database schema diagram shows the tables of a relational database, the columns in each table, and the lines that join a foreign key to the key it points at. It is the physical level of data modeling: real table names, real column types, real keys. Developers read it to write queries, and reviewers read it to catch a missing relation before a migration ships.

This template holds the schema of an online store in eight tables: users, addresses, reviews, categories, orders, payments, order_items and products. Ten relationship lines join them, a key explains the line ends, and four cards record the conventions the schema follows.

The database schema template: eight tables in two rows joined by crow’s-foot lines, a Key in the top right corner and four convention cards along the bottom.
The whole board: people and catalog on top, orders and money below.

Users, addresses and reviews

Each table is a box with its name in the header and one row per column: name, type, and a PK or FK badge where the column is a key. The users table is the simplest: id (uuid, the primary key), email, password_hash, full_name and created_at.

Two lines leave users. The one labeled “has” goes to addresses, where the column user_id carries the FK badge. The one labeled “writes” goes to reviews, which has two foreign keys, product_id and user_id, because a review belongs to both a product and its author. The label on each line is a verb, so you read it as a sentence: a user has addresses, a user writes reviews.

A foreign key column on one table, a labeled line to the table it points at.

Orders, payments, items and products

The bottom row is the part of the store that handles money. orders has two foreign keys, user_id and shipping_address_id, plus status, total_cents and placed_at. Lines arrive from users (“places”) and from addresses (“ships to”).

From orders, “paid by” goes to payments and “contains” goes to order_items. The order_items table is the join between orders and products. It has order_id, product_id, quantity and unit_price_cents. The price is stored on the line on purpose: a later change to price_cents in products must not rewrite what past customers paid. The line from products to order_items is labeled “sold as”.

order_items joins orders to products and keeps the price at the time of sale.

Reading the crow’s feet

The ends of each line say how many rows can take part. The Key shows the four endings: Exactly one, Zero or one, One or many, Zero or many. The three-pronged fork that gives the notation its name always sits on the “many” side.

Most lines in the example run from exactly one to zero or many. One user places zero or many orders, since a new account has none yet. The “contains” line is different, and the difference is a business rule. It ends in one or many: an order must have at least one item. When you draw your own lines, decide the minimum at each end deliberately. “Can this be empty?” is the question that finds bugs.

Four line endings and two badges are the whole notation.

A table that points at itself

One line starts and ends on the same table. categories has the columns id, parent_id, name and slug, and parent_id is a foreign key to the id of another category. The loop on its right side is labeled “parent of”.

This is how a tree is stored in a flat table: Shoes can be the parent of Running shoes. The line’s two ends are zero or one and zero or many. A category has at most one parent, and a top-level category has none. A parent can have any number of children. Below, the “groups” line joins categories to products through category_id.

parent_id refers to another row of the same table, which makes a tree.

Conventions written on the board

Four cards at the bottom record decisions that would otherwise be argued again in every code review. Two of them:

  • Names. “Plural snake_case tables; singular_id foreign keys.” So the table is orders and the column that points at it is order_id.
  • Money. “Whole cents in integer columns, never floats.” That is why the columns are called amount_cents, total_cents, price_cents and unit_price_cents.

The value of writing these down shows in the tables above. You can guess a column’s name before you look, and you never have to ask whether 19.99 was stored as a float.

Naming and money rules, stated once and followed by every table.

How to use the database schema template

  1. Open it on a Pro or Team plan. It is a Pro template. The store’s eight tables arrive ready to edit.
  2. Rename tables and columns to yours. Click a table to add, remove or reorder rows, and mark each key column as PK or FK.
  3. Reconnect the lines. For every FK column there should be one line. Write a verb on it and choose both endings from the key.
  4. Rewrite the four cards. Keep Time and Deletes too. The example stores timestamptz in UTC, and its rule for deletes is “Orders and payments are never deleted, only voided.”

If you are starting from nothing, FlowDraw AI can draft tables from a description of your product, and you refine the keys by hand.

Time zones and deletes are the two rules teams most often leave unwritten.

When a schema diagram fits, and when to step back

Use it when you design a new feature’s tables, review a migration, or explain an existing database to someone who has to query it. It shows what will actually be created, column by column.

If you are still deciding which things exist and how they relate, types and keys are a distraction. Start with the ER diagram template or, for the classic notation with diamonds, the Chen ER diagram. To model behavior as well as data, with methods and inheritance, use the domain model template, which describes the same store as classes.

Questions about the Database schema template

What is the difference between a database schema and an ER diagram?

An ER diagram describes entities and relationships as ideas, often before a database is chosen. A schema diagram shows what is created: exact table names, column types and keys. This template is a schema; its types, such as uuid and timestamptz, are ones a database accepts.

What do PK and FK mean?

PK marks the primary key, the column that identifies each row, such as id in users. FK marks a foreign key, a column that holds the primary key of a row in another table, such as user_id in orders. Every FK on the board has a line to its target.

Why store money as integer cents?

Floating-point numbers cannot represent most decimal fractions exactly, so sums drift by fractions of a cent. Whole cents in an integer column add up exactly. The board’s Money card states the rule, and columns such as total_cents follow it.

Do I need a paid plan for the database schema template?

Yes. It is one of the Pro templates, which open on the Pro and Team plans. The board itself is small, 48 elements, and exports as PNG, SVG, PDF or JSON once you have edited it.