Surveys
This page documents the database schema used to manage surveys, their questions, and recorded responses. It mirrors the style used by the other dataschema pages: a visual diagram followed by a per-table breakdown with field definitions, indexes, and relationships.
Tables
surveys
Top-level survey metadata (title, description, context, and survey type).
View fields and relationships
- id: UUID, Primary Key
- created_at: Timestamp with time zone, The time when the survey was created.
- title: Text, Human-readable title for the survey.
- description: Text, Longer description shown to users.
- context: Text, Free-form context string describing where/why the survey is used.
- type: survey_types, Enum describing the kind of survey (e.g., intake, feedback, post-study).
- Indexes: Primary Key on
id. - Relationships: One-to-Many with
survey_questionsandsurvey_responses(each question and response referencessurveys.id).
survey_questions
Questions associated with a survey. Questions support different types and optional choice lists.
View fields and relationships
- id: UUID, Primary Key
- created_at: Timestamp with time zone, When the question was created.
- survey_id: UUID, Foreign Key referencing
surveys(id)— the survey that owns this question. - question_type: Text, The input type for the question (e.g.,
text,multiple_choice,checkbox,scale). - question_text: Text, The question prompt shown to the user.
- question_options: Text[], Optional list of choices for choice-based questions.
- is_required: Boolean, Whether answering the question is required.
- question_number: Integer, Ordering index for rendering questions within a survey.
- Indexes: Primary Key on
id, Foreign Key index onsurvey_id. - Relationships: Many-to-One with
surveys.
Notes:
question_optionsis stored as an array of text values; consumer code should validate option formats and ordering.question_numbershould be unique persurvey_idif strict ordering is required by the application.
survey_responses
Stores user-submitted responses. Answers are stored in a JSONB blob to allow flexible question shapes and typed answers.
View fields and relationships
- id: UUID, Primary Key
- created_at: Timestamp with time zone, When the response was submitted.
- survey_id: UUID, Foreign Key referencing
surveys(id)— the survey answered. - user_id: UUID, Foreign Key referencing
users(id)— the user who submitted the response. May be null if anonymous responses are allowed. - answers: JSONB, A JSON object mapping
question_numberorquestion_idto the user's answer. - Indexes: Primary Key on
id; recommended indexes onsurvey_idanduser_idfor query performance. - Relationships: Many-to-One with
surveys, Many-to-One withusers.
Notes:
- The
answersJSONB schema is intentionally flexible to support multiple question types and evolving forms; consumers should validate and normalize answers when reading. - If anonymity is required,
user_idmay be left null and any identifying fields should be omitted.
The users table is referenced in this schema to establish relationships with user-submitted responses. See the Users & Classroom dataschema for the full users table definition. See full definiton in the Users & Classroom.