Skip to content

Implement DatabaseSettingsNode (database-settings schema + behavior) #1398

Closed

Description

@malibio

Overview

Implement DatabaseSettingsNode as a core node type: the `database-settings` schema entry + `DatabaseSettingsNodeBehavior`. This is a singleton per NodeSpace database instance — it is the container for all database-level configuration: sync state, user roles, and future settings.

This issue was introduced to cleanly separate database-level state from identity. Previously `role` and `auth_status` were specified on PersonNode (ADR-037); they are moved here as part of that revision.

Read first

  • `components/node-behavior-system.md` — Core (hardcoded) vs Extension (schema-driven) behavior architecture
  • `decisions/037-collection-access-model.md` — tenant role axis and Last-Admin Invariant
  • `architecture/cloud-sync.md` — sync lifecycle and upgrade path

Data model

DatabaseSettingsNode has `node_type = 'database-settings'` and a fixed symbolic ID of `"database-settings"` (same pattern as `"task"`, `"text"`, `"ai-chat"`). This makes creation idempotent and querying deterministic.

Node properties

Field Type Notes
`sync_enabled` `bool` Default `false`. User intent to sync. Inert on free/community tier.
`auth_status` enum `local` / `connected` System-managed. Default `local`. Set to `connected` by daemon after Supabase bind.

Role edge: `has_role`

Tenant-level authority is carried on a `has_role` relationship edge between a PersonNode and DatabaseSettingsNode (not on the PersonNode itself):

Edge property Type Notes
`role` enum `owner` / `admin` / `editor` / `viewer` Tenant-level authority for this person in this database.
`status` enum `active` / `pending` `pending` = invite sent, not yet accepted.

Exactly one `owner` edge must exist at all times (enforced — see Last-Admin Invariant).

Why role is on the edge, not the node

A person's authority is contextual to a specific database — not intrinsic to who they are. This also enables `@` mention of any PersonNode regardless of their role/status, with the UI distinguishing pending invites via the edge `status` field.

Seeding

DatabaseSettingsNode is seeded at first launch (not on-demand), with:

  • `sync_enabled: false`
  • `auth_status: local`
  • One `has_role` edge to the local user's PersonNode with `role: owner`, `status: active`

This makes sync-state queries unconditional (no absent-node handling needed) and matches the free-tier-coherent-by-default principle established by PersonNode seeding.

Sync policy

Unlike core schema slugs, DatabaseSettingsNode is not excluded from cloud sync — it varies per installation. It syncs with the rest of the graph. `sync_enabled` and `auth_status` have different writers (user vs. daemon) — callers should expect and retry on OCC version conflicts.

Implementation Tasks

  • Add `database-settings` `SchemaNode` to `packages/core/src/models/core_schemas.rs` with `sync_enabled` (bool, default false) and `auth_status` (enum, Core-protected).
  • Implement `DatabaseSettingsNodeBehavior` implementing the `NodeBehavior` trait.
  • Register it in `NodeBehaviorRegistry::new()` in `packages/core/src/behaviors/mod.rs`.
  • `validate`: enforce `auth_status` is a valid enum value; `sync_enabled` is bool.
  • `can_have_children()` → `false`.
  • Singleton enforcement: NodeService must reject creation of a second `database-settings` node (fixed ID makes this idempotent — use `INSERT OR IGNORE` semantics).
  • Seed at first launch: create the node + initial `has_role` owner edge to local PersonNode.
  • Register `has_role` as a valid relationship type.
  • Unit tests: schema present; behavior registered; singleton enforcement; valid/invalid `auth_status` values; seeding creates node + owner edge.

Acceptance Criteria

  • `database-settings` schema entry exists with `sync_enabled` and Core-protected `auth_status`.
  • `DatabaseSettingsNodeBehavior` implements all `NodeBehavior` methods and is registered.
  • Fixed ID `"database-settings"` — second creation is a no-op, not an error.
  • Seeded at first launch with `sync_enabled: false`, `auth_status: local`, and owner `has_role` edge to local PersonNode.
  • `has_role` relationship type registered and documented.
  • Unit tests cover singleton, seeding, and validation.
  • Passes `cargo clippy`; no lint suppression.

Scope

In scope: DatabaseSettingsNode schema + behavior + seeding + `has_role` edge type.

NOT in scope:

  • Pro sync logic (setting `auth_status: connected`, `sync_enabled: true`) — pro/sync daemon
  • UI for sync toggle (upgrade CTA surface) — separate UI issue
  • RLS enforcement — pro/sync
  • `auth_identities` bind — pro/sync

Relationships

Activity

  1. malibio commented on Jun 9, 2026

    @malibio
    CollaboratorAuthor

    Dependency note from #133 follow-up

    The auth_identities bind in nodespace-sync (Pro upgrade flow) was previously expected to find auth_status: 'local' on the PersonNode. That field has been removed from PersonNode seeding (PR #1402) — it was incorrectly placed there.

    When this issue (#1398) is implemented, nodespace-sync's upgrade flow needs to:

    1. Read auth_status from DatabaseSettingsNode (not PersonNode)
    2. Update DatabaseSettingsNode.auth_status to 'connected' after the Supabase bind (instead of updating PersonNode)

    The auth_identities row itself (person_node_id ↔ supabase_uid) is unchanged — it still keys on the PersonNode ID.

  2. self-assigned this
    on Jul 7, 2026
  3. mstomar125 commented on Jul 7, 2026

    @mstomar125
    Contributor

    Picked up now (2026-07-07) — implementation in flight.

    This is the one self-contained, dependency-free ticket in the ADR-053 group: schema entry + DatabaseSettingsNodeBehavior + has_role edge + first-launch seeding, all following the existing PersonNode/AiChatNode templates. PR incoming; routing through the review→merge loop.

  4. mstomar125 commented on Jul 7, 2026

    @mstomar125
    Contributor

    Merged via #1573 (squash → main). DatabaseSettingsNode schema + behavior + has_role edge + first-launch seeding landed; CI green (test:all + test:e2e); approved + deadline-merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions