Skip to content

Commit 8be37e8

Browse files
committed
add documentation about variants used in codebase
1 parent 00e5fa3 commit 8be37e8

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ 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+
-}
23+
824
--------------------------------------------------------------------------------
925
-- TxOutVariantType
1026
--------------------------------------------------------------------------------

0 commit comments

Comments
 (0)