Skip to main content

Database Schema

Last Updated: June 29, 2025

This document details the PostgreSQL database schema, main tables, and relationships between tables for the SurfAI project. All tables and columns are defined based on TypeORM entities.

1. Overview

  • Database System: PostgreSQL
  • ORM: TypeORM
  • Main Entities: User, Workflow, GeneratedOutput

2. Table Details

a. users table

This is the core table for storing user account information. It has a hybrid structure supporting both Google login and standard email/password login.

Column NameTypeConstraintsDescription
idintegerPK, Auto-incrementUnique identifier for the user
emailvarcharUniqueUser's email address. Used as login ID.
displayNamevarcharNot NullDisplay name for the user (nickname).
passwordvarcharNullable, Select=falsebcrypt hash of the password used for standard registration.
googleIdvarcharUnique, NullableUnique Google ID for Google login.
imageUrlvarchar(2048)NullableURL of the user's profile picture (Google or default image).
roleenumNot Null, Default='user'User's role. (admin or user)
currentHashedRefreshTokenvarcharNullable, Select=falsebcrypt hash of the JWT Refresh Token. Set to NULL on logout.
createdAttimestamptzNot NullTimestamp of record creation (auto-generated)
updatedAttimestamptzNot NullTimestamp of last record modification (auto-updated)

b. workflows table

This table manages both workflow "templates" and user-saved "my workflow" instances with custom parameters.

Column NameTypeConstraintsDescription
idintegerPK, Auto-incrementUnique identifier for the workflow
namevarcharNot NullName of the workflow template or instance.
descriptiontextNullableDetailed description of the workflow.
definitionjsonbNullableOriginal ComfyUI workflow API format JSON. (Mainly used when isTemplate: true)
parameter_mapjsonbNullableInformation mapping dynamic parameters to actual nodes.
previewImageUrltextNullableURL of the template's preview image to display in lists.
tagstext[]NullableArray of tags for template classification.
isTemplatebooleanNot Null, Default=truetrue if it's an admin-created template, false if it's a user-saved instance.
isPublicTemplatebooleanNot Null, Default=falsetrue if it's a template publicly available to all users.
ownerUserIdintegerNullable, FK (users.id)ID of the user who owns this workflow.
sourceTemplateIdintegerNullable, FK (workflows.id)ID of the original template from which this workflow was derived. (Used when isTemplate: false)
createdAttimestamptzNot NullTimestamp of record creation
updatedAttimestamptzNot NullTimestamp of last record modification

c. generated_outputs table

This table stores metadata for all generated outputs (images/videos) by users.

Column NameTypeConstraintsDescription
idintegerPK, Auto-incrementUnique identifier for the generated output
ownerUserIdintegerNot Null, FK (users.id)ID of the user who generated this output.
sourceWorkflowIdintegerNot Null, FK (workflows.id)ID of the workflow used for generation.
r2Urlvarchar(2048)Not NullUnique path URL of the actual file stored in Cloudflare R2.
originalFilenamevarcharNot NullOriginal filename generated by ComfyUI.
mimeTypevarcharNot NullMIME type of the file. (e.g., image/png, video/mp4)
promptIdvarcharNot Null, IndexComfyUI's prompt ID identifying the generation task.
usedParametersjsonbNullableRecord of dynamic parameter values entered by the user during generation.
durationfloatNullablePlayback duration in seconds if the output is a video.
createdAttimestamptzNot NullTimestamp of record creation

3. Table Relationships (ERD Summary)

  • User (1) : (N) Workflow: One user can own multiple workflow instances.
  • User (1) : (N) GeneratedOutput: One user can generate multiple outputs.
  • Workflow (1) : (N) Workflow: One workflow template can have multiple user instances. (Self-referencing relationship)
  • Workflow (1) : (N) GeneratedOutput: One workflow can be used to generate multiple outputs.