Skip to content

survey_versions

Overview

Survey versions. Rows are added on every save and rollback and are never deleted.

Table Definition

Logical name Physical name Column Type PK Relation Unique Nullable Default Notes
Version survey_versions id uuid โ—ฏ gen_random_uuid()
survey_id uuid surveys:id (cascade)
version_no integer Version number, sequential within the survey
status survey_status Status at the time the version was created
source_version_id uuid โ—ฏ ID of the version copied from. No FK constraint
rollback_from_version_id uuid โ—ฏ ID of the version restored. No FK constraint
created_by uuid users:id (restrict) The user who created the version
created_at timestamptz now()

Relations

  • survey_id โ†’ surveys.id (onDelete: cascade)
  • created_by โ†’ users.id (onDelete: restrict)
  • Referenced by: survey_version_sections.survey_version_id (cascade)
  • Referenced by: survey_version_pointers.version_id (cascade)

Indexes

  • Primary key (id)
  • UNIQUE INDEX: survey_versions_survey_id_version_no_idx (survey_id, version_no)

Notes

  • Version 1 is created when the survey is created
  • A save creates a new version containing a copy of the entire latest snapshot
  • A rollback creates a new version restoring the content of the given version; earlier versions are not deleted
  • source_version_id / rollback_from_version_id are self-references and carry no foreign key constraint
  • Running an export (POST /api/surveys/{surveyId}/export) also updates the latest version's status to Exported