category, functor, natural transformation
Category Theory Example: Applied to a Database
Category = Schema
Objects:
Person
City
Morphism:
$lives_in: \text{Person} \to \text{City}$ (a foreign key relation)
This forms a category: objects and structure-preserving relationships.
Functor = Dataset
A functor $F: \mathcal{C} \to \mathbf{Set}$ assigns:
$F(\text{Person}) = {\text{Alice},\ \text{Bob}}$
$F(\text{City}) = {\text{Boston},\ \text{LA}}$
$F(\text{lives_in}) = {(\text{Alice},\ \text{Boston}),\ (\text{Bob},\ \text{LA})}$
This is one instance of data fitting the schema’s shape.
Another Functor = Updated Dataset
A second functor $G$ assigns:
$G(\text{Person}) = {\text{Alice},\ \text{Bob}}$
$G(\text{City}) = {\text{Boston},\ \text{LA}}$
$G(\text{lives_in}) = {(\text{Alice},\ \text{LA}),\ (\text{Bob},\ \text{LA})}$
Same schema, different data (e.g., Alice moved to LA).
Natural Transformation = Data Migration
A natural transformation $\eta: F \Rightarrow G$ maps data:
$\eta_{\text{Person}}$: identity on people
$\eta_{\text{City}}$: identity on cities
But updates how $lives_in$ points
This satisfies the naturality condition:
$G(lives_in) \circ \eta_{\text{Person}} = \eta_{\text{City}} \circ F(lives_in)$
So the structure (foreign key logic) is preserved even after the data update.