Skip to content

Data model

PostgreSQL holds all data. The schema is managed by Flyway (src/main/resources/db/migration) and Hibernate only validates it (ddl-auto=validate).

Instances and stages

Instance data exists once per stage in tables with the same structure: current_* for IN_PROGRESS and released_* for RELEASED. instance holds what is independent of the stage.

erDiagram
    SPACE ||--o{ INSTANCE : contains
    INSTANCE ||--o| CURRENT_INSTANCE : "in progress"
    INSTANCE ||--o| RELEASED_INSTANCE : released
    CURRENT_INSTANCE ||--o| CURRENT_PAYLOAD : has
    CURRENT_INSTANCE ||--o{ CURRENT_IDENTIFIER : has
    CURRENT_INSTANCE ||--o{ CURRENT_RELATION : "outgoing links"
    CURRENT_INSTANCE ||--o{ CURRENT_PROPERTY_OCCURRENCE : has
    CURRENT_INSTANCE ||--o{ CONTRIBUTION : "merged from"
    RELEASED_INSTANCE ||--o| RELEASED_PAYLOAD : has
    RELEASED_INSTANCE ||--o{ RELEASED_IDENTIFIER : has
    RELEASED_INSTANCE ||--o{ RELEASED_RELATION : "outgoing links"
    RELEASED_INSTANCE ||--o{ RELEASED_PROPERTY_OCCURRENCE : has
    MARMOT_USER ||--o{ CONTRIBUTION : authored

    INSTANCE {
        bigint id PK
        uuid instanceId UK
        string releaseStatus
        timestamp createdAt
        timestamp lastUpdateAt
        timestamp firstReleaseAt
        timestamp lastReleaseAt
    }
    CURRENT_INSTANCE {
        bigint instance_id PK
        bigint type_id FK
        string label
        text searchable
        text sort_name
        text sort_type
    }
    CURRENT_PAYLOAD {
        bigint instance_id PK
        bytea jsonPayload
        string md5hash
        bytea alternative
    }
    CONTRIBUTION {
        bigint instance_id PK
        bigint user_id PK
        bytea jsonPayload
        text propertyUpdates
        string md5hash
    }
    CURRENT_RELATION {
        bigint instance_id PK
        string targetReference PK
        bigint resolved_target_id FK
    }
  • current_payload.jsonPayload is the merged result. contribution.jsonPayload holds what one user wrote, and propertyUpdates records when each property changed.
  • Payloads are gzip-compressed, so SQL can't look into them. Anything that has to be queried is extracted into its own table or column.
  • A *_relation row stores the target as written (targetReference) and, once known, the resolved instance.
  • sort_* columns are maintained by triggers and back the sorted listings (ADR-036).

Structure

erDiagram
    SPACE ||--o{ TYPE_IN_SPACE : has
    TYPE ||--o{ TYPE_IN_SPACE : "occurs in"
    TYPE ||--o{ PROPERTY_IN_TYPE : has
    PROPERTY ||--o{ PROPERTY_IN_TYPE : "used by"
    TYPE ||--o{ TYPE_SCOPE : has
    TYPE ||--o{ TYPE_VALIDATION_SCHEMA : has
    TYPE_VALIDATION_SCHEMA ||--o{ INSTANCE_VALIDATION_RESULT : produces
    INSTANCE ||--o{ INSTANCE_VALIDATION_RESULT : has

    SPACE {
        bigint id PK
        string spaceName UK
        boolean autoRelease
        boolean explicitSpecification
    }
    TYPE {
        bigint id PK
        string typeName UK
        string labelProperty
        string color
        boolean explicitSpecification
    }
    PROPERTY {
        bigint id PK
        string propertyName UK
        bytea specification
    }
    TYPE_SCOPE {
        bigint id PK
        bigint type_id FK
        string name
        bytea specification
    }

The current_*_summary tables (current_type_summary, current_property_occurrence_summary, current_incoming_link_summary, current_target_type_summary, current_embedded_type_summary) hold the counts behind the type information. Database triggers maintain them incrementally, and a nightly procedure recomputes them to correct any drift (ADR-009).

Users and collaboration

erDiagram
    MARMOT_USER ||--o{ INVITATION : receives
    INVITATION ||--o{ INVITATION_SCOPE : "applies to"
    INSTANCE ||--o{ PENDING_INVITATION : "invited through"
    PENDING_INVITATION ||--o{ PENDING_INVITATION_SCOPE : "applies to"
    MARMOT_USER ||--o{ FAVORITE_INSTANCE : flags
    INSTANCE ||--o{ FAVORITE_INSTANCE : "favorite of"
    MARMOT_USER |o--o{ INSTANCE_COMMENT : writes
    INSTANCE ||--o{ INSTANCE_COMMENT : has

    MARMOT_USER {
        bigint id PK
        string nativeId UK
        string username
        string email
    }
    PENDING_INVITATION {
        uuid id PK
        bigint instance_id FK
        string tokenHash UK
        string label
        timestamp expiresAt
    }
    INSTANCE_COMMENT {
        uuid id PK
        bigint instance_id FK
        string property
        text text
    }

Users are identified externally by their Keycloak nativeId (ADR-011). Pending invitations store only the SHA-256 of their token.

Other tables

Table Content
stored_query Stored queries, with the gzip-compressed specification and the root type, name and description denormalized for listing (ADR-038)
permission Role definitions: which claims grant which role
tenant, image Tenant definitions and images
curie_prefix Prefixes for the graph vocabulary (ADR-016)
tool, tool_category Tools built on top of the graph, with the claim patterns of the users they're listed to (ADR-063)
api_example Overrides of the OpenAPI examples, globally and per tenant (ADR-068)

Changing the schema

Add a new migration, V<next>__description.sql, and never edit an existing one. Since Hibernate validates the schema at startup, the entity and migration have to match.

Migrations are also applied in the integration tests, against a real PostgreSQL.