feat(diary): 添加 15 个 SeaORM 实体和数据库迁移 (Phase B1)

实体:
- journal_entry: 日记核心表 (心情/天气/标签/版本)
- journal_element: 日记元素 (文字/图片/贴纸/手写/胶带)
- handwriting_stroke: 手写笔画 (独立大字段表)
- school_class: 班级 (6位码/过期控制)
- class_member: 班级成员 (复合PK)
- topic_assignment: 主题布置
- comment: 老师点评
- sticker_pack + sticker: 贴纸包和贴纸
- template: 日记模板
- achievement + user_achievement: 成就系统
- parent_child_binding: 家长-孩子绑定 (PIPL)
- teacher_profile: 老师档案
- user_settings: 用户设置

迁移 (000170-000184):
- 15 个建表迁移 + 索引 + RLS 策略 + 种子数据
- 所有表含 tenant_id 多租户隔离
- 软删除 + 乐观锁版本号
- 外键级联删除
- 暖记权限注册到基座 permissions 表

验证: cargo check 通过, 425 个测试全通过
This commit is contained in:
iven
2026-05-31 22:29:56 +08:00
parent a99d565e2e
commit 3d9896a676
32 changed files with 2316 additions and 2 deletions

View File

@@ -0,0 +1,50 @@
// 成就定义 — 可解锁的成就徽章
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "achievements")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 成就编码(唯一标识,如 "first_diary", "streak_7"
pub code: String,
/// 成就名称
pub name: String,
/// 成就描述
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// 图标 URL 或 emoji
#[serde(skip_serializing_if = "Option::is_none")]
pub icon: Option<String>,
/// 分类writing/social/collection/special
pub category: String,
/// 解锁条件 (JSONB: { type, threshold, ... })
#[serde(skip_serializing_if = "Option::is_none")]
pub condition: Option<serde_json::Value>,
/// 排序权重
pub sort_order: i32,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::user_achievement::Entity")]
UserAchievement,
}
impl Related<super::user_achievement::Entity> for Entity {
fn to() -> RelationDef {
Relation::UserAchievement.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,49 @@
// 班级成员 — 复合主键 (class_id + user_id)
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "class_members")]
pub struct Model {
/// 班级 ID复合主键之一
#[sea_orm(primary_key, auto_increment = false)]
pub class_id: Uuid,
/// 用户 ID复合主键之一
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
pub tenant_id: Uuid,
/// 成员角色student/teacher
pub role: String,
/// 班级内昵称
#[serde(skip_serializing_if = "Option::is_none")]
pub nickname: Option<String>,
/// 加入时间
pub joined_at: DateTimeUtc,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::school_class::Entity",
from = "Column::ClassId",
to = "super::school_class::Column::Id",
on_delete = "Cascade"
)]
SchoolClass,
}
impl Related<super::school_class::Entity> for Entity {
fn to() -> RelationDef {
Relation::SchoolClass.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,44 @@
// 老师点评 — 老师对学生日记的评语
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "comments")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 被点评的日记
pub journal_id: Uuid,
/// 点评者老师ID
pub author_id: Uuid,
/// 评语内容
pub content: String,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::journal_entry::Entity",
from = "Column::JournalId",
to = "super::journal_entry::Column::Id",
on_delete = "Cascade"
)]
JournalEntry,
}
impl Related<super::journal_entry::Entity> for Entity {
fn to() -> RelationDef {
Relation::JournalEntry.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,79 @@
// 手写笔画 — 独立表,大字段隔离,延迟加载
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
/// 画笔类型
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum BrushType {
/// 钢笔(压感)
Pen,
/// 铅笔(纹理)
Pencil,
/// 马克笔(半透明)
Marker,
/// 橡皮擦
Eraser,
}
impl std::fmt::Display for BrushType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
BrushType::Pen => write!(f, "pen"),
BrushType::Pencil => write!(f, "pencil"),
BrushType::Marker => write!(f, "marker"),
BrushType::Eraser => write!(f, "eraser"),
}
}
}
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "handwriting_strokes")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 所属日记元素
pub element_id: Uuid,
/// 点坐标序列 (JSONB: [{x, y}, ...])
pub points: serde_json::Value,
/// 压力值序列 (JSONB: [0.0-1.0, ...])
#[serde(skip_serializing_if = "Option::is_none")]
pub pressures: Option<serde_json::Value>,
/// 时间戳序列 (JSONB: [ms, ...])
#[serde(skip_serializing_if = "Option::is_none")]
pub timestamps: Option<serde_json::Value>,
/// 笔画颜色 (hex)
pub color: String,
/// 笔画基础宽度
pub stroke_width: f64,
/// 画笔类型
pub brush_type: String,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::journal_element::Entity",
from = "Column::ElementId",
to = "super::journal_element::Column::Id",
on_delete = "Cascade"
)]
JournalElement,
}
impl Related<super::journal_element::Entity> for Entity {
fn to() -> RelationDef {
Relation::JournalElement.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,93 @@
// 日记元素 — 手账页面中的文字/图片/贴纸/手写引用/胶带等元素
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
/// 元素类型枚举
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum ElementType {
/// 文本框
Text,
/// 图片
Image,
/// 贴纸
Sticker,
/// 手写引用(指向 handwriting_stroke
HandwritingRef,
/// 和纸胶带
Tape,
}
impl std::fmt::Display for ElementType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ElementType::Text => write!(f, "text"),
ElementType::Image => write!(f, "image"),
ElementType::Sticker => write!(f, "sticker"),
ElementType::HandwritingRef => write!(f, "handwriting_ref"),
ElementType::Tape => write!(f, "tape"),
}
}
}
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "journal_elements")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 所属日记
pub journal_id: Uuid,
/// 元素类型
pub element_type: String,
/// X 坐标位置
pub position_x: f64,
/// Y 坐标位置
pub position_y: f64,
/// 宽度
pub width: f64,
/// 高度
pub height: f64,
/// 旋转角度(度)
pub rotation: f64,
/// 层叠顺序
pub z_index: i32,
/// 元素内容JSON: 文本内容/图片URL/贴纸ID等
#[serde(skip_serializing_if = "Option::is_none")]
pub content: Option<serde_json::Value>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::journal_entry::Entity",
from = "Column::JournalId",
to = "super::journal_entry::Column::Id",
on_delete = "Cascade"
)]
JournalEntry,
#[sea_orm(has_many = "super::handwriting_stroke::Entity")]
HandwritingStroke,
}
impl Related<super::journal_entry::Entity> for Entity {
fn to() -> RelationDef {
Relation::JournalEntry.def()
}
}
impl Related<super::handwriting_stroke::Entity> for Entity {
fn to() -> RelationDef {
Relation::HandwritingStroke.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,70 @@
// 日记条目 — 暖记核心实体
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "journal_entries")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 日记作者
pub author_id: Uuid,
/// 所属班级(可选,独立用户可为空)
#[serde(skip_serializing_if = "Option::is_none")]
pub class_id: Option<Uuid>,
/// 日记标题
pub title: String,
/// 日记日期
pub date: chrono::NaiveDate,
/// 心情
pub mood: String,
/// 天气
pub weather: String,
/// 标签JSON 数组)
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<serde_json::Value>,
/// 是否私密
pub is_private: bool,
/// 是否分享到班级
pub shared_to_class: bool,
/// 关联的主题布置(老师布置的主题)
#[serde(skip_serializing_if = "Option::is_none")]
pub assigned_topic_id: Option<Uuid>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
/// 乐观锁版本号(同步冲突检测核心)
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::journal_element::Entity")]
JournalElement,
#[sea_orm(
belongs_to = "super::school_class::Entity",
from = "Column::ClassId",
to = "super::school_class::Column::Id",
on_delete = "Cascade"
)]
SchoolClass,
}
impl Related<super::journal_element::Entity> for Entity {
fn to() -> RelationDef {
Relation::JournalElement.def()
}
}
impl Related<super::school_class::Entity> for Entity {
fn to() -> RelationDef {
Relation::SchoolClass.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -1,2 +1,17 @@
// erp-diary SeaORM 实体占位
// 后续 Phase B1 会定义完整的 ~15 个实体
// erp-diary SeaORM 实体定义
pub mod journal_entry;
pub mod journal_element;
pub mod handwriting_stroke;
pub mod school_class;
pub mod class_member;
pub mod topic_assignment;
pub mod comment;
pub mod sticker_pack;
pub mod sticker;
pub mod template;
pub mod achievement;
pub mod user_achievement;
pub mod parent_child_binding;
pub mod teacher_profile;
pub mod user_settings;

View File

@@ -0,0 +1,35 @@
// 家长-孩子绑定 — PIPL 合规:未满 14 岁必须家长授权
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "parent_child_bindings")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 家长用户 ID
pub parent_id: Uuid,
/// 孩子用户 ID
pub child_id: Uuid,
/// 验证方式qr/sms/manual
pub verification_method: String,
/// 验证通过时间
#[serde(skip_serializing_if = "Option::is_none")]
pub verified_at: Option<DateTimeUtc>,
/// 绑定状态pending/verified/revoked
pub status: String,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,65 @@
// 班级 — 老师创建,学生通过班级码加入
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "school_classes")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 班级名称
pub name: String,
/// 学校名称
#[serde(skip_serializing_if = "Option::is_none")]
pub school_name: Option<String>,
/// 创建者老师ID
pub teacher_id: Uuid,
/// 6 位班级码字母数字混合62^6 ≈ 568 亿种组合)
pub class_code: String,
/// 成员数量(缓存字段)
pub member_count: i32,
/// 是否激活
pub is_active: bool,
/// 班级码过期时间(学期结束自动失效)
#[serde(skip_serializing_if = "Option::is_none")]
pub expires_at: Option<DateTimeUtc>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::class_member::Entity")]
ClassMember,
#[sea_orm(has_many = "super::topic_assignment::Entity")]
TopicAssignment,
#[sea_orm(has_many = "super::journal_entry::Entity")]
JournalEntry,
}
impl Related<super::class_member::Entity> for Entity {
fn to() -> RelationDef {
Relation::ClassMember.def()
}
}
impl Related<super::topic_assignment::Entity> for Entity {
fn to() -> RelationDef {
Relation::TopicAssignment.def()
}
}
impl Related<super::journal_entry::Entity> for Entity {
fn to() -> RelationDef {
Relation::JournalEntry.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,50 @@
// 贴纸 — 单个贴纸素材
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "stickers")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 所属贴纸包
pub pack_id: Uuid,
/// 贴纸名称
pub name: String,
/// 图片 URL
pub image_url: String,
/// 分类
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
/// 标签 (JSON 数组)
#[serde(skip_serializing_if = "Option::is_none")]
pub tags: Option<serde_json::Value>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::sticker_pack::Entity",
from = "Column::PackId",
to = "super::sticker_pack::Column::Id",
on_delete = "Cascade"
)]
StickerPack,
}
impl Related<super::sticker_pack::Entity> for Entity {
fn to() -> RelationDef {
Relation::StickerPack.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,48 @@
// 贴纸包 — 一组贴纸的集合
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "sticker_packs")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 贴纸包名称
pub name: String,
/// 描述
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// 缩略图 URL
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>,
/// 是否免费
pub is_free: bool,
/// 价格积分0 = 免费)
pub price: i32,
/// 分类
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_many = "super::sticker::Entity")]
Sticker,
}
impl Related<super::sticker::Entity> for Entity {
fn to() -> RelationDef {
Relation::Sticker.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,35 @@
// 老师档案 — 老师的扩展信息
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "teacher_profiles")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 关联的用户 ID
pub user_id: Uuid,
/// 学校名称
#[serde(skip_serializing_if = "Option::is_none")]
pub school_name: Option<String>,
/// 任教科目 (JSON 数组: ["语文", "数学"])
#[serde(skip_serializing_if = "Option::is_none")]
pub subjects: Option<serde_json::Value>,
/// 个人简介
#[serde(skip_serializing_if = "Option::is_none")]
pub bio: Option<String>,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,37 @@
// 模板 — 日记模板(布局+预设元素)
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "templates")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 模板名称
pub name: String,
/// 缩略图 URL
#[serde(skip_serializing_if = "Option::is_none")]
pub thumbnail_url: Option<String>,
/// 布局数据 (JSONB: 元素定义数组)
#[serde(skip_serializing_if = "Option::is_none")]
pub layout_data: Option<serde_json::Value>,
/// 分类
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<String>,
/// 是否官方模板
pub is_official: bool,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,52 @@
// 主题布置 — 老师发布日记主题,学生提交对应日记
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "topic_assignments")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 所属班级
pub class_id: Uuid,
/// 布置主题的老师
pub teacher_id: Uuid,
/// 主题标题
pub title: String,
/// 主题描述/要求
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
/// 截止日期
#[serde(skip_serializing_if = "Option::is_none")]
pub due_date: Option<chrono::NaiveDate>,
/// 是否激活
pub is_active: bool,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::school_class::Entity",
from = "Column::ClassId",
to = "super::school_class::Column::Id",
on_delete = "Cascade"
)]
SchoolClass,
}
impl Related<super::school_class::Entity> for Entity {
fn to() -> RelationDef {
Relation::SchoolClass.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,44 @@
// 用户成就 — 复合主键 (user_id + achievement_id)
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "user_achievements")]
pub struct Model {
/// 用户 ID复合主键之一
#[sea_orm(primary_key, auto_increment = false)]
pub user_id: Uuid,
/// 成就 ID复合主键之一
#[sea_orm(primary_key, auto_increment = false)]
pub achievement_id: Uuid,
pub tenant_id: Uuid,
/// 解锁时间
pub unlocked_at: DateTimeUtc,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::achievement::Entity",
from = "Column::AchievementId",
to = "super::achievement::Column::Id",
on_delete = "Cascade"
)]
Achievement,
}
impl Related<super::achievement::Entity> for Entity {
fn to() -> RelationDef {
Relation::Achievement.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,28 @@
// 用户设置 — 个性化配置
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Serialize, Deserialize)]
#[sea_orm(table_name = "user_settings")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub tenant_id: Uuid,
/// 关联的用户 ID
pub user_id: Uuid,
/// 设置数据 (JSONB: { theme, fontSize, defaultBrush, ... })
pub settings: serde_json::Value,
pub created_at: DateTimeUtc,
pub updated_at: DateTimeUtc,
pub created_by: Uuid,
pub updated_by: Uuid,
#[serde(skip_serializing_if = "Option::is_none")]
pub deleted_at: Option<DateTimeUtc>,
pub version: i32,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}