Skip to content

Simplify user IDs to a single public_id in backend #472

@clostao

Description

@clostao
  • Goal: Simplify the usage of user IDs because now co-exists two different IDs for users and creates some unnecessary complexities.

  • TLDR: The two IDs that exist are (oauth_provider, oauth_user_id) and public_id, after this update auto-drive backend won't have a reference to either oauth_provider or oauth_user_id

Data Model Update

  • Migration 1 — Add and backfill public_id:

    • Add a new nullable public_id column to every table that currently uses (oauth_provider, oauth_user_id).
    • Backfill public_id for existing rows by computing it with @generateUserPublicId from the pair (oauth_provider, oauth_user_id).
    • Keep existing constraints in place during backfill. Optionally add indexes on public_id where lookups will happen.
  • Migration 2 — Remove oauth columns and enforce public_id:

    • Remove the oauth_user_id column(s) from those tables.
    • Make the new public_id column NOT NULL and update any keys/constraints to use public_id.
  • Notes:

    • @generateUserPublicId is the existing helper used to deterministically derive the public_id from (oauth_provider, oauth_user_id) and should be used for the backfill step.
    • Apply this to all tables that currently key or reference users by the oauth pair.

Models updates

  • Replace all oauthProvider/oauthUserId usages with a single publicId in domain types and DTOs.
    • objects/object.ts: Owner{ publicId: string; role } (remove oauth fields).
    • uploads/upload.ts: table shape uses public_id; model shape/schemas use publicId. Update fileUploadSchema/folderUploadSchema, UploadEntry, and mappers accordingly.
    • users/apiKey.ts: replace oauth fields with publicId: string.
    • users/jwt.ts: payloads include publicId; remove oauth fields and Hasura claims x-hasura-oauth-*. Keep x-hasura-public-id.
    • users/user.ts: make publicId the primary identifier; keep OAuthUser only for provider-bound data.
  • Naming: DB-facing structs use public_id (snake_case); model-facing types use publicId (camelCase).
  • Versioning: mark as breaking change and bump models package major; update tests/fixtures.

Hasura updates

  • In tables/object_ownerships.yml: Replace oauth_* columns for public_id
  • In filter like in tables/async_downloads.yml: Replace oauth_* columns for public_id in filters

GraphQL updates

  • Some queries use oauth_* matching the current schema, these queries should be updated too

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions