Paths and Peers

Bedrock has two "special" tables, and then everything else. The paths-table and the peers-table. These two are closely related and could in fact be combined but for ergonomic and conceptual reasons they are separate. These special tables are essential for the distributed nature of the database to work.

A path is "where" the data lives and the peers are who are "in" that path. Each row in the peers table is just a (path, ship, role) and some timestamps. %host is the only meaningful role, everything else is up to application-specific logic to define the meaning of. Currently each path has one %host who is the "ultimate source of truth" for all that data in that path. Other distribution protocols are specifiable but currently only %host is supported.

Peers table

+$  peers  (map path (list peer))
:: when we create an object, we must specify who our peers are for the /path
+$  peer
  $:  =path           :: same as path.row
      =role           :: %host or any other custom role

Paths table

The path-table is a little more complicated, because it's the metadata container for the "rules" of the path. Basically the path-row specifies who is allowed to create, modify, or delete what kind of data within that path. It also contains typical database "constraint" rules like "id column must be unique in the foo table"

+$  paths     (map path path-row)
+$  path-row
  $:  =path
      default-access=access-rules   :: for everything not found in the table-access
      =table-access                 :: allows a path to specify role-based access rules on a per-table basis
      =constraints                  :: if there is not a constraint rule for a given type, the default constraints for types will be applied
      space=(unit [=path =role:membership])  :: if the path-row is created from a space, record the info
+$  replication   ?(%host %gossip %shared-host)  :: for now only %host is supported
+$  table-access  (map type:common access-rules)
+$  access-rules  (map role access-rule)
+$  access-rule   [create=? edit=permission-scope delete=permission-scope]
+$  permission-scope  ?(%table %own %none)
:: by default the host can CED everything and everyone else can CED the objects they created
++  default-access-rules  (~(gas by *access-rules) ~[[%host [%.y %table %table]] [%$ [%.y %own %own]]])
+$  constraints   (map type:common constraint)
+$  constraint    [=type:common =uniques]
+$  uniques       (set unique-columns)  :: the various uniqueness rules that must all be true
+$  unique-columns  (set column-accessor)  :: names of columns that taken together must be unique in the table+path
++  default-vote-constraint  [%vote (silt ~[(~(gas in *unique-columns) ~[1 2 3 ""])]) ~]
++  default-rating-constraint  [%rating (silt ~[(~(gas in *unique-columns) ~[3 4 5 "" 2])]) ~]
++  default-constraints
  %-  ~(gas by *constraints)
  :~  [%vote default-vote-constraint]
      [%rating default-rating-constraint]
+$  column-accessor  ?(@ud tape)

Last updated