feat: Introduce multi-tenancy support with organization-specific data, add interactive transcript functionality, and enhance lesson/course schemas.

This commit is contained in:
2026-01-15 18:02:04 -03:00
parent daeda7e905
commit 663950aa0e
26 changed files with 933 additions and 302 deletions
@@ -25,8 +25,3 @@ ALTER TABLE user_grades ALTER COLUMN organization_id DROP DEFAULT;
ALTER TABLE user_badges ADD COLUMN organization_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001';
ALTER TABLE user_badges ADD CONSTRAINT fk_user_badge_organization FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
ALTER TABLE user_badges ALTER COLUMN organization_id DROP DEFAULT;
-- 6. Add organization_id to points_log
ALTER TABLE points_log ADD COLUMN organization_id UUID NOT NULL DEFAULT '00000000-0000-0000-0000-000000000001';
ALTER TABLE points_log ADD CONSTRAINT fk_points_log_organization FOREIGN KEY (organization_id) REFERENCES organizations(id) ON DELETE CASCADE;
ALTER TABLE points_log ALTER COLUMN organization_id DROP DEFAULT;
@@ -0,0 +1,9 @@
-- Migration: Add branding columns to organizations table
-- Adds columns that exist in CMS but were missing in LMS
ALTER TABLE organizations
ADD COLUMN domain VARCHAR(255),
ADD COLUMN logo_url TEXT,
ADD COLUMN primary_color VARCHAR(7),
ADD COLUMN secondary_color VARCHAR(7),
ADD COLUMN certificate_template TEXT;
@@ -0,0 +1,11 @@
-- Migration: Fix organizations table for registration
-- Adds default UUID generation and unique constraint on name
ALTER TABLE organizations ALTER COLUMN id SET DEFAULT gen_random_uuid();
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'organizations_name_key') THEN
ALTER TABLE organizations ADD CONSTRAINT organizations_name_key UNIQUE (name);
END IF;
END $$;
@@ -0,0 +1,4 @@
-- Migration: Add updated_at to users table (LMS)
-- To match common::models::User struct requirements
ALTER TABLE users ADD COLUMN updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW();
@@ -0,0 +1,4 @@
-- Migration: Add pacing_mode to courses table (LMS)
-- To match common::models::Course struct and CMS schema
ALTER TABLE courses ADD COLUMN pacing_mode VARCHAR(50) NOT NULL DEFAULT 'self_paced';
@@ -0,0 +1,9 @@
-- Migration: Add unique constraint to enrollments table
-- Required for fn_enroll_student ON CONFLICT logic
DO $$
BEGIN
IF NOT EXISTS (SELECT 1 FROM pg_constraint WHERE conname = 'enrollments_user_id_course_id_key') THEN
ALTER TABLE enrollments ADD CONSTRAINT enrollments_user_id_course_id_key UNIQUE (user_id, course_id);
END IF;
END $$;
@@ -0,0 +1,7 @@
-- Migration: Add missing columns to lessons table (LMS)
-- To match common::models::Lesson struct and CMS schema
ALTER TABLE lessons ADD COLUMN IF NOT EXISTS summary TEXT;
ALTER TABLE lessons ADD COLUMN IF NOT EXISTS due_date TIMESTAMPTZ;
ALTER TABLE lessons ADD COLUMN IF NOT EXISTS important_date_type VARCHAR(50);
ALTER TABLE lessons ADD COLUMN IF NOT EXISTS transcription_status VARCHAR(20) DEFAULT 'idle';