Skip to content

Commit 24fc662

Browse files
authored
Merge pull request #2030 from IntersectMBO/docs/variants
docs/variants: add documentation about variants used in codebase
2 parents 00e5fa3 + 77be351 commit 24fc662

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cardano-db/src/Cardano/Db/Schema/Variants.hs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@ import qualified Cardano.Db.Schema.Variants.TxOutAddress as VA
55
import qualified Cardano.Db.Schema.Variants.TxOutCore as VC
66
import Cardano.Prelude (ByteString, Text)
77

8+
-- |
9+
-- This module implements a schema variants system that allows db-sync to support different
10+
-- database layouts for the same logical data. Currently used for TxOut-related tables.
11+
--
12+
-- Two variants exist:
13+
-- - Core (default): Stores address data inline in tx_out tables (denormalised)
14+
-- - Address: Normalises addresses into a separate 'address' table for storage efficiency
15+
--
16+
-- Users configure this via 'tx_out.use_address_table' in the config file (see doc/configuration.md).
17+
-- Since the schema variant is determined by runtime configuration rather than compile time,
18+
-- we cannot use the type system alone to handle the different schemas. The wrapper types
19+
-- (TxOutW, TxOutIdW, etc.) use sum types to provide runtime polymorphism, allowing code to
20+
-- work with either variant through pattern matching. This design can be extended to other
21+
-- tables following the same pattern.
22+
823
--------------------------------------------------------------------------------
924
-- TxOutVariantType
1025
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)