Cloudrive

Data model

The Postgres schema behind tenants, storage accounts, the credential vault and the S3 gateway.

Migrations live in apps/api/migrations (golang-migrate, 000001 … 000005). Ids are uuid with DEFAULT uuidv7(), text columns carry CHECK constraints, timestamps are timestamptz. Every tenant-owned table carries organization_id with a composite foreign key to workspaces (id, organization_id), ready for row-level security later.

Tables

users ─┬─< organization_members >── organizations ──< workspaces ─┬─< workspace_members >── users
       │                                  │                       │
       └─< organization_invitations ──────┘                       ├─< storage_accounts ── providers
                                                                  │        │
                                                                  │        └── storage_account_secrets (1:1, encrypted)
                                                                  ├─< s3_credentials (encrypted secret)
                                                                  └─< s3_buckets ──> storage_accounts
users ──< onboarding_surveys (one per user)
MigrationTables
000001users
000002organizations, organization_members (owner/admin/member), workspaces, workspace_members (admin/member/viewer), organization_invitations (pending/accepted/rejected/revoked/expired)
000003providers, storage_accounts, storage_account_secrets
000004s3_credentials, s3_buckets
000005onboarding_surveys

Providers

A global catalog seeded by seeders/provider.go:

slugprotocolauth_type
google_driveoauth2_cloudoauth2
onedriveoauth2_cloudoauth2
dropboxoauth2_cloudoauth2
s3_compatibles3_compatibleaccess_key

capabilities (JSONB) records features such as versioning, trash and multipart.

Storage accounts and the vault

  • storage_accounts is one connected account bound to one workspace, with display_name, account_email, external_account_id, settings (JSONB) and status (pending_auth, active, expired, revoked, error). The same external account cannot be connected twice to a workspace.
  • storage_account_secrets holds the credentials, 1:1, in a separate table so everyday queries never touch them. Values are sealed with AES-256-GCM as key_id:base64(nonce):base64(ciphertext) by internal/lib/secretbox, inside the repositories.

S3 gateway tables

  • s3_credentials: access keys issued per workspace. The secret is encrypted with the same vault, status is active or revoked, and last_used_at is updated on each request.
  • s3_buckets: a globally unique bucket name (S3 naming rules, enforced by a CHECK) mapped to one storage account and a root_prefix (empty, or ending in /).

Planned

docs/erd-cloud-storage.md describes the next part of the schema, not migrated yet: a unified file tree (storage_nodes), version history, shares, sync jobs and upload sessions.

On this page