Skip to content

Instantly share code, notes, and snippets.

@cowlicks
Last active November 4, 2024 19:00
Show Gist options
  • Save cowlicks/c38c23a9f36239a943734c1e83eef71a to your computer and use it in GitHub Desktop.
Save cowlicks/c38c23a9f36239a943734c1e83eef71a to your computer and use it in GitHub Desktop.
Nix entity relationship diagram
  erDiagram
    ValidPaths {
        int id PK
        string path
        string hash
        int registrationTime
        string deriver
        int narSize
        int ultimate
        string sigs
        string ca
    }
    
    Refs {
        int referrer PK,FK
        int reference PK,FK
    }
    
    DerivationOutputs {
        int drv PK,FK
        string id PK
        int path FK
    }
    
    Invalidations {
        string path PK
        int time
    }

    ValidPaths ||--o{ Refs : "references"
    ValidPaths ||--o{ DerivationOutputs : "outputs"
    ValidPaths ||--o{ DerivationOutputs : "is_output"
    Refs }|--|| ValidPaths : "referenced_by"
Loading

I'll create an ER diagram showing the relationships between the tables in the Nix database.

erDiagram
    ValidPaths {
        int id PK
        string path
        string hash
        int registrationTime
        string deriver
        int narSize
        int ultimate
        string sigs
        string ca
    }
    
    Refs {
        int referrer PK,FK
        int reference PK,FK
    }
    
    DerivationOutputs {
        int drv PK,FK
        string id PK
        int path FK
    }
    
    Invalidations {
        string path PK
        int time
    }

    ValidPaths ||--o{ Refs : "references"
    ValidPaths ||--o{ DerivationOutputs : "outputs"
    ValidPaths ||--o{ DerivationOutputs : "is_output"
    Refs }|--|| ValidPaths : "referenced_by"

Loading

Key points about the relationships shown:

  1. ValidPaths is the central table, containing all store paths
  2. Refs has a many-to-many relationship with ValidPaths, as each path can reference multiple other paths and be referenced by multiple paths
  3. DerivationOutputs connects to ValidPaths twice:
    • Once for the derivation itself (drv field)
    • Once for the output path (path field)
  4. Invalidations is standalone as it just tracks removed paths

The diagram shows cardinality where:

  • || represents exactly one
  • o{ represents zero or many
  • }| represents many to one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment