Skip to content

🗄️ Data Model Overview

This document describes the database schema used for managing users, partitions (spaces), files, and their relationships.
It is implemented using SQLAlchemy ORM with PostgreSQL as the backend.


Stores information about API users and administrators.

ColumnTypeDescription
idInteger (PK)Unique user identifier
external_user_idString (nullable, unique)Optional external system reference
display_nameStringDisplay name
tokenString (unique, hashed)SHA-256 hash of the user’s API token
is_adminBooleanMarks system administrator users
created_atDateTimeTimestamp of creation

Relationships

  • memberships: one-to-many → PartitionMembership

Represents a logical workspace or “space” that groups files and users.

ColumnTypeDescription
idInteger (PK)Unique partition identifier
partitionString (unique, indexed)Human-readable name / key
created_atDateTimeTimestamp of creation

Relationships

  • files: one-to-many → File
  • memberships: one-to-many → PartitionMembership

Represents an indexed file belonging to a partition.

ColumnTypeDescription
idInteger (PK)Internal file identifier
file_idString (indexed)External file identifier (e.g., hash or ID)
partition_nameString (FK → partitions.partition)Partition that owns the file
file_metadataJSONAdditional metadata (format, size, etc.)

Constraints

  • UniqueConstraint(file_id, partition_name) → a file can appear only once per partition.
  • Composite index ix_partition_file (partition_name, file_id) for efficient queries.

Defines the many-to-many relationship between users and partitions, including role-based access control.

ColumnTypeDescription
idInteger (PK)Unique row ID
partition_nameString (FK → partitions.partition, CASCADE)Partition identifier
user_idInteger (FK → users.id, CASCADE)Linked user
roleStringRole of the user: owner, editor, or viewer
added_atDateTimeTimestamp of when the membership was created

Constraints

  • UniqueConstraint(partition_name, user_id) → a user can appear only once per partition.
  • CheckConstraint(role IN ('owner','editor','viewer')) → role validation.
  • Composite index ix_user_partition (user_id, partition_name).

Relationships

  • partition: many-to-one → Partition
  • user: many-to-one → User

RelationshipTypeDescription
UserPartitionMembership1–NA user can belong to multiple partitions with different roles
PartitionPartitionMembership1–NA partition can have multiple users (owners, editors, viewers)
PartitionFile1–NA partition can contain multiple files
FilePartitionN–1Each file belongs to exactly one partition

  • Roles (owner, editor, viewer) determine what users can do in each partition.
  • is_admin users are privileged globally (admin endpoints, user management).
  • SUPER_ADMIN_MODE=true allows the global admin to bypass all partition-level restrictions.

  • Tokens are generated at user creation time (or-<random hex>).
  • Only a SHA-256 hash is stored in the database.
  • During authentication, the incoming Bearer token is hashed and compared with the stored hash.