AgentSkillsCN

lms-schema-audit

深入审计LMS应用的PostgreSQL数据库架构,识别实体与数据库之间的不匹配,依据Canvas、Moodle、Coursera等前沿模式进行优化,并指导从Supabase/Neon/本地Docker之间的迁移。适用于调试Hibernate启动失败、规划数据库迁移,或优化LMS数据库架构设计的场景。

SKILL.md
--- frontmatter
name: lms-schema-audit
description: Deep audit PostgreSQL schemas for LMS applications, identify Entity-DB mismatches, optimize for SOTA patterns (Canvas, Moodle, Coursera), and guide migrations between Supabase/Neon/Local Docker. Use when debugging Hibernate startup failures, planning database migrations, or optimizing LMS schema design.

LMS Schema Audit Skill

Comprehensive schema auditing for Learning Management System databases, with focus on Entity ↔ Database synchronization and SOTA LMS patterns.

When to Use This Skill

  • Debugging Hibernate ddl-auto: validate startup failures
  • Auditing schema for type mismatches, missing indexes
  • Planning migrations between Supabase, Neon, Local Docker
  • Verifying LMS domain patterns (courses, enrollments, quizzes)
  • Optimizing schema for performance

Related Skills

  • postgresql - PostgreSQL connections, configuration, roles
  • sql-optimization-patterns - EXPLAIN analysis, indexing strategies, N+1 fixes

Core Audit Workflow

Step 1: Gather Schema Information

Collect from these sources:

SourcePath Pattern
Flyway Migrationsapi/src/main/resources/db/migration/V*.sql
JPA Entitiesapi/src/main/java/**/entity/*JpaEntity.java
Schema Documentationschema_*.md files
Spring Configapplication-*.yml

Step 2: Type Consistency Check

Compare JPA Entity types with PostgreSQL column types:

PostgreSQLJava TypeCommon Error
integerIntegerUsing BigDecimal
numericBigDecimalUsing Integer
jsonbMap<> + @Type(JsonType.class)Missing @Type
uuidUUIDUsing String
timestamptzInstantUsing LocalDateTime

Step 3: LMS Domain Pattern Verification

Check for SOTA patterns from Canvas, Moodle, Coursera:

  • Course Hierarchy: courseschapterslessonssections
  • Class-based Enrollment: learning_classes + enrollments (not direct course enrollment)
  • Grading System: grade_configs per class with weighted components
  • Quiz Structure: Separate questions, quiz_questions, quiz_attempts
  • Rich Content: JSONB content_blocks for EditorJS compatibility
  • File Attachments: Polymorphic via entity_type + entity_id

Step 4: Output Format

code
🔴 CRITICAL: [Issue causing startup failure]
   Table: xxx | Column: xxx
   DB Type: xxx | Entity Type: xxx
   Fix: [Specific migration or code change]

🟡 MEDIUM: [Performance/design issue]
   Table: xxx
   Issue: [Description]
   Recommendation: [Specific fix]

🟢 LOW: [Naming/style inconsistency]

Migration Configurations

Local Docker

yaml
spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/lms
    username: lms
    password: lms

Neon (Serverless)

yaml
spring:
  datasource:
    url: jdbc:postgresql://ep-xxx.aws.neon.tech/neondb?sslmode=require
    username: neondb_owner
    password: <password>

Supabase (via Pooler)

yaml
spring:
  datasource:
    url: jdbc:postgresql://aws-1-ap-southeast-1.pooler.supabase.com:6543/postgres?sslmode=require
    username: postgres.projectid
    password: <password>

Constraints

  • DO NOT run ALTER TABLE without Flyway migration
  • DO NOT use ddl-auto: update in production
  • ALWAYS backup before migration: pg_dump -Fc > backup.dump
  • ALWAYS use CREATE INDEX CONCURRENTLY in production