Skip to main content

mebook_questions

Overview

The mebook_questions table stores the individual questions within each MeBook section. Questions have various types (multiple_choice, scale, text, etc.) and can optionally map to app preferences via the maps_to_preference field.

Schema

-- From 20260130_mebook_system.sql
CREATE TABLE mebook_questions (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
section_id UUID NOT NULL REFERENCES mebook_sections(id) ON DELETE CASCADE,
key TEXT UNIQUE NOT NULL,
question_text TEXT NOT NULL,
question_type TEXT NOT NULL CHECK (question_type IN (
'multiple_choice', 'scale', 'text', 'toggle', 'ranking', 'color_picker'
)),
description TEXT,
maps_to_preference TEXT,
sort_order INTEGER DEFAULT 0,
is_required BOOLEAN DEFAULT FALSE,
is_active BOOLEAN DEFAULT TRUE,
metadata JSONB DEFAULT '{}',
created_at TIMESTAMPTZ DEFAULT NOW()
);

Columns

ColumnTypeNullableDefaultDescription
iduuidNogen_random_uuid()Primary key
section_iduuidNo--Parent section
keytextNo--Unique question key
question_texttextNo--The question text shown to users
question_typetextNo--Input type: multiple_choice, scale, text, toggle, ranking, color_picker
descriptiontextYes--Additional context for the question
maps_to_preferencetextYes--App preference key this maps to
sort_orderintegerNo0Display order within section
is_requiredbooleanNoFALSEWhether answer is required
is_activebooleanNoTRUEWhether question is available
metadatajsonbNo'{}'Additional question configuration
created_attimestamptzNoNOW()Seed timestamp

RLS Policies

-- SELECT: All authenticated users can read questions
CREATE POLICY "Questions are readable by all"
ON mebook_questions FOR SELECT
USING (true);

Last updated: 2026-02-07