实体: - 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 个测试全通过
115 lines
4.0 KiB
Rust
115 lines
4.0 KiB
Rust
// 日记条目表
|
|
|
|
use sea_orm_migration::prelude::*;
|
|
|
|
#[derive(DeriveMigrationName)]
|
|
pub struct Migration;
|
|
|
|
#[async_trait::async_trait]
|
|
impl MigrationTrait for Migration {
|
|
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.create_table(
|
|
Table::create()
|
|
.table(JournalEntries::Table)
|
|
.if_not_exists()
|
|
.col(ColumnDef::new(JournalEntries::Id).uuid().not_null().primary_key())
|
|
.col(ColumnDef::new(JournalEntries::TenantId).uuid().not_null())
|
|
.col(ColumnDef::new(JournalEntries::AuthorId).uuid().not_null())
|
|
.col(ColumnDef::new(JournalEntries::ClassId).uuid().null())
|
|
.col(ColumnDef::new(JournalEntries::Title).string().not_null())
|
|
.col(ColumnDef::new(JournalEntries::Date).date().not_null())
|
|
.col(ColumnDef::new(JournalEntries::Mood).string().not_null().default("calm"))
|
|
.col(ColumnDef::new(JournalEntries::Weather).string().not_null().default("sunny"))
|
|
.col(ColumnDef::new(JournalEntries::Tags).json_binary().null())
|
|
.col(ColumnDef::new(JournalEntries::IsPrivate).boolean().not_null().default(true))
|
|
.col(ColumnDef::new(JournalEntries::SharedToClass).boolean().not_null().default(false))
|
|
.col(ColumnDef::new(JournalEntries::AssignedTopicId).uuid().null())
|
|
.col(
|
|
ColumnDef::new(JournalEntries::CreatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(
|
|
ColumnDef::new(JournalEntries::UpdatedAt)
|
|
.timestamp_with_time_zone()
|
|
.not_null()
|
|
.default(Expr::current_timestamp()),
|
|
)
|
|
.col(ColumnDef::new(JournalEntries::CreatedBy).uuid().not_null())
|
|
.col(ColumnDef::new(JournalEntries::UpdatedBy).uuid().not_null())
|
|
.col(ColumnDef::new(JournalEntries::DeletedAt).timestamp_with_time_zone().null())
|
|
.col(ColumnDef::new(JournalEntries::Version).integer().not_null().default(1))
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
// 租户 + 作者索引
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_journal_entries_tenant_author")
|
|
.table(JournalEntries::Table)
|
|
.col(JournalEntries::TenantId)
|
|
.col(JournalEntries::AuthorId)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
// 日期索引(日历查询)
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_journal_entries_tenant_date")
|
|
.table(JournalEntries::Table)
|
|
.col(JournalEntries::TenantId)
|
|
.col(JournalEntries::Date)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
// 班级索引(班级日记墙)
|
|
manager
|
|
.create_index(
|
|
Index::create()
|
|
.name("idx_journal_entries_class")
|
|
.table(JournalEntries::Table)
|
|
.col(JournalEntries::ClassId)
|
|
.to_owned(),
|
|
)
|
|
.await?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(JournalEntries::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(DeriveIden)]
|
|
pub enum JournalEntries {
|
|
Table,
|
|
Id,
|
|
TenantId,
|
|
AuthorId,
|
|
ClassId,
|
|
Title,
|
|
Date,
|
|
Mood,
|
|
Weather,
|
|
Tags,
|
|
IsPrivate,
|
|
SharedToClass,
|
|
AssignedTopicId,
|
|
CreatedAt,
|
|
UpdatedAt,
|
|
CreatedBy,
|
|
UpdatedBy,
|
|
DeletedAt,
|
|
Version,
|
|
}
|