Skip to main content

Surveys - Developer Guide

This guide covers the technical architecture, database schema, and implementation details of the Survey feature in Pawtograder.

Overview

The survey system allows instructors to create custom surveys, collect student responses, and analyze feedback. It uses SurveyJS for the question builder and renderer.

Architecture

Tech Stack

Key Dependencies

Database Schema

Tables

surveys

Main table storing survey definitions.

survey_series

Stores survey series for trend analysis.

assignment_groups

Updated to include mentor assignments.

survey_responses

Stores individual student responses.

survey_assignments

Maps surveys to specific students (when not assigned to all).

survey_templates

Reusable survey templates.

Enum Types

Database Triggers

RPC Functions

soft_delete_survey(p_survey_id UUID, p_survey_logical_id UUID)

Atomically soft-deletes a survey and all its responses.

create_survey_assignments(p_survey_id UUID, p_profile_ids UUID[])

Bulk creates survey assignments for specific students.

get_survey_status_for_assignment(p_assignment_id BIGINT, p_profile_id UUID)

Returns survey completion status for a student on a specific assignment.
Returns surveys linked to the assignment with completion status for the specified student.

get_survey_responses_with_group_context(p_class_id BIGINT, p_survey_id UUID)

Aggregates survey responses with group and mentor information for analytics.
Returns response data joined with group membership, mentor assignments, and section information.

Row Level Security (RLS)

Survey Policies

Response Policies

TypeScript Types

File Structure

SurveyJS Integration

Rendering Surveys

Survey JSON Structure

Supported Question Types

Response Handling

Saving Responses

Auto-save on Value Change

When allow_response_editing is enabled, responses are auto-saved:

CSV Export

The export functionality includes security protections against CSV injection:

Testing

E2E Tests

Survey E2E tests are located at tests/e2e/surveys.test.tsx.

Manual Testing

  1. Create a test class with npm run seed
  2. Log in as an instructor
  3. Navigate to Surveys to test CRUD operations
  4. Log in as a student to test survey taking

Common Development Tasks

Adding a New Question Type

  1. Update SurveyBuilderDataTypes.ts:
  2. Update the builder UI in SurveyBuilder.tsx
  3. Add rendering support in Survey.tsx (usually automatic via SurveyJS)

Modifying the Database Schema

  1. Create a new migration:
  2. Write your SQL in supabase/migrations/[timestamp]_your_migration_name.sql
  3. Apply locally:
  4. Regenerate types:

Adding RLS Policies

Troubleshooting

Survey not appearing for students

  1. Check survey status is published
  2. Verify deleted_at is NULL
  3. If using specific assignments, confirm student is in survey_assignments
  4. Check RLS policies are not blocking access

Response not saving

  1. Verify the student’s profile_id matches their class enrollment
  2. Check for unique constraint violations (duplicate responses)
  3. Verify is_submitted trigger is working

Visual Builder not updating JSON

  1. Check browser console for JavaScript errors
  2. Verify onChange callback is properly wired
  3. Check for JSON serialization issues in serde.ts