liveBook · Manning

Schema

As explained in Functional Design and Architecture: Examples in Haskell

A database schema is the structure defining the data types, fields, and relationships represented in a database.

A schema turns requirements into an explicit database structure: data types, fields, tables, relationships, keys, and constraints. Getting requirements wrong can undermine later storage, access, and query decisions, so schema design belongs alongside broader architectural choices. section 12.2

A schema is the database-facing shape of a model, distinct from domain types that represent the real world. In a relational setting, it describes tables and columns; in a key–value setting, it can describe typed entities encoded as strings, JSON, compressed data, or binary values. section 11.2.1 section 12.2

A practical schema design addresses:

  • Which fields and database-supported types represent each entity. section 12.2.2
  • Which table name and primary key identify each row. section 12.2.2
  • How tables, relations, normalization, indexes, views, stored procedures, and SQL queries support application behavior. section 12.2
  • How database entities are converted to and from domain values. section 11.2.1
Listing 12.3 DBMeteor table definition
import Database.Beam (Columnar, Beamable)
  
data DBMeteorT f = DBMeteor              #1
  { _id          :: Columnar f Int       #2
  , _size        :: Columnar f Int
  , _mass        :: Columnar f Int
  , _azimuth     :: Columnar f Int
  , _altitude    :: Columnar f Int
  , _timestamp   :: Columnar f UTCTime
  }
  deriving (Generic, Beamable)           #3

A Beam table schema models a meteor table as an Haskell record: each Columnar field represents a column, while deriving Generic and Beamable enables library integration. section 12.2.2

Meteor schema

A meteor table can expose identifier, size, mass, azimuth, altitude, and timestamp fields. The schema then associates the table with its name and primary key, and a database record collects that table for queries such as filtering meteors by size. section 12.2.2

How Functional Design and Architecture: Examples in Haskell covers it

How deep it goes
Defines fields, column types, table names, primary keys, and database declarations, while deferring broader relational theory and implementation choices.
Examples
Uses meteor records with typed fields, JSON key–value entities, primary-key declarations, and size-filtered queries as concrete schema examples.
What it assumes
Assumes requirements and domain types, while introducing database models, storage-specific entities, relational structures, and schema declarations.
What you can do after
Build it from scratch by declaring typed tables, primary keys, database settings, and conversions between stored entities and domain values.
How it connects
Connects schemas with database models, domain types, tables, primary keys, relations, normalization, indexes, serialization, and SQL queries.

Also explained in

Compare how 44 books explain schema →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Functional Design and Architecture: Examples in Haskell. The section links point to the parts of the book it draws on.