From 9631711090d79a92b0a07c2ae5ae32ad1497d93d Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Wed, 20 May 2026 06:11:09 -0700 Subject: [PATCH] Seed default LMS personas in migration 063. Insert ids 1-3 catalog rows and sync sequence on up; delete seed ids on down before dropping lms_personas. Co-authored-by: Cursor --- db/migrations/000063_lms_personas.down.sql | 4 +++ db/migrations/000063_lms_personas.up.sql | 30 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/db/migrations/000063_lms_personas.down.sql b/db/migrations/000063_lms_personas.down.sql index 40384d4..9b468e1 100644 --- a/db/migrations/000063_lms_personas.down.sql +++ b/db/migrations/000063_lms_personas.down.sql @@ -14,4 +14,8 @@ SET persona_id = NULL; ALTER TABLE lms_practices ADD CONSTRAINT lms_practices_persona_id_fkey FOREIGN KEY (persona_id) REFERENCES users (id) ON DELETE SET NULL; +-- Remove seeded default personas before dropping the catalog table. +DELETE FROM lms_personas +WHERE id IN (1, 2, 3); + DROP TABLE IF EXISTS lms_personas; diff --git a/db/migrations/000063_lms_personas.up.sql b/db/migrations/000063_lms_personas.up.sql index a38060d..fd4eece 100644 --- a/db/migrations/000063_lms_personas.up.sql +++ b/db/migrations/000063_lms_personas.up.sql @@ -14,6 +14,36 @@ WHERE is_active; CREATE INDEX idx_lms_personas_created_at ON lms_personas (created_at DESC); +-- Default catalog personas (stable ids for envs and Postman); add more via API. +INSERT INTO lms_personas (id, name, description, avatar_url, is_active) +VALUES + ( + 1, + 'Friendly Coach', + 'Warm, encouraging tutor for everyday conversational practice.', + NULL, + TRUE + ), + ( + 2, + 'Exam Coach', + 'Structured, exam-style guidance and clear checkpoints.', + NULL, + TRUE + ), + ( + 3, + 'Story Narrator', + 'Story-led scenarios with character-driven prompts.', + NULL, + TRUE + ); + +SELECT setval( + pg_get_serial_sequence('lms_personas', 'id'), + (SELECT COALESCE(MAX(id), 1) FROM lms_personas) +); + -- persona_id historically referenced users.id; personas are now catalog rows on lms_personas. ALTER TABLE lms_practices DROP CONSTRAINT IF EXISTS lms_practices_persona_id_fkey;