ForkFit Docs
ServerDatabase

Identity & Access Management (IAM)

Database tables governing user registration, credentials, OAuth connections, sessions, and Role-Based Access Control (RBAC).

Identity & Access Management (IAM)

This module defines the relational schema for managing user profiles, authentication credentials, third-party OAuth links, user sessions, and fine-grained access control permissions.

Migrated by: 00001_create_iam.sql


1. Core Users & Credentials

users

Stores user identity metadata, verification flags, and current lifecycle status.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Unique user identifier.
    emailcitextNOT NULL UNIQUE-Case-insensitive email address.
    email_verifiedbooleanNOT NULLfalseTrue if the user email has been verified.
    statustextNOT NULL CHECK (status IN ('active', 'suspended', 'pending_verification'))'active'Account status context.
    created_attimestamptzNOT NULLnow()Registration timestamp.
    updated_attimestamptzNOT NULLnow()Timestamp of last user metadata change.
    deleted_attimestamptz--Timestamp for soft-delete audits.

user_credentials

Stores passwords using secure hashing algorithms.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Unique credential identifier.
    user_iduuidNOT NULL UNIQUE-Foreign key referencing users.id (ON DELETE CASCADE).
    password_hashtextNOT NULL-Securely hashed password.
    password_changed_attimestamptz--Track history of password changes.
    created_attimestamptzNOT NULLnow()Creation timestamp.
    updated_attimestamptzNOT NULLnow()Update timestamp.

2. OAuth Accounts

oauth_accounts

Tracks third-party authorization providers (e.g., Google, GitHub) connected to user profiles.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Link identifier.
    user_iduuidNOT NULL-Foreign key referencing users.id (ON DELETE CASCADE).
    providertextNOT NULL-OAuth provider name (e.g., 'google', 'github').
    provider_user_idtextNOT NULL-Provider-provided unique user ID.
    provider_emailtext--Provider profile email.
    created_attimestamptzNOT NULLnow()Link timestamp.
    updated_attimestamptzNOT NULLnow()Update timestamp.
  • Unique Constraints: (provider, provider_user_id) ensures OAuth links remain unique per provider account.

3. Session Management & OTP

sessions

Records active browser/device sessions and refresh token hashes.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()Session ID.
    user_iduuidNOT NULL-Foreign key referencing users.id (ON DELETE CASCADE).
    token_hashtextNOT NULL UNIQUE-SHA-256 hash of the session's active refresh token.
    ip_addressinet--Connection IP address.
    user_agenttext--Device browser user-agent.
    device_nametext--Resolved device model / type.
    expires_attimestamptzNOT NULL-Expiration timestamp.
    revoked_attimestamptz--Set if the session was explicitly logged out/revoked.
    last_seen_attimestamptz--Timestamp of the last API call.
    created_attimestamptzNOT NULLnow()Session creation timestamp.

otp_verifications

Saves temporary verification codes for account verification or password resets.

  • Schema:
    ColumnTypeConstraintsDefaultDescription
    iduuidPRIMARY KEYgen_random_uuid()OTP transaction identifier.
    emailcitextNOT NULL-Destination email address.
    otp_hashtextNOT NULL-Hashed one-time verification password.
    purposetextNOT NULL-Usage intent (e.g., 'email_verification', 'password_reset').
    attemptsintegerNOT NULL0Number of input attempts (capped at 5).
    expires_attimestamptzNOT NULL-OTP lifetime limit.
    consumed_attimestamptz--Timestamp when the OTP was verified.
    created_attimestamptzNOT NULLnow()Dispatch timestamp.

4. Access Control (RBAC)

roles

Stores access role classes.

  • Schema: id (UUID), name (unique: 'admin', 'user'), description, created_at.

permissions

Exposes resources and action limits for security mapping.

  • Schema: id (UUID), resource (e.g. 'roles'), action (e.g. 'read', 'create'), created_at.
  • Unique Constraints: (resource, action) ensures resource actions remain unique.

role_permissions

Junction table mapping permissions to roles.

  • Schema: role_id (foreign key roles), permission_id (foreign key permissions). Joint primary key.

user_roles

Junction table mapping users to roles.

  • Schema: user_id (foreign key users), role_id (foreign key roles), assigned_at. Joint primary key.

On this page