// 老师点评表 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(Comments::Table) .if_not_exists() .col(ColumnDef::new(Comments::Id).uuid().not_null().primary_key()) .col(ColumnDef::new(Comments::TenantId).uuid().not_null()) .col(ColumnDef::new(Comments::JournalId).uuid().not_null()) .col(ColumnDef::new(Comments::AuthorId).uuid().not_null()) .col(ColumnDef::new(Comments::Content).text().not_null()) .col( ColumnDef::new(Comments::CreatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col( ColumnDef::new(Comments::UpdatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col(ColumnDef::new(Comments::CreatedBy).uuid().not_null()) .col(ColumnDef::new(Comments::UpdatedBy).uuid().not_null()) .col(ColumnDef::new(Comments::DeletedAt).timestamp_with_time_zone().null()) .col(ColumnDef::new(Comments::Version).integer().not_null().default(1)) .to_owned(), ) .await?; // 日记索引(加载日记的所有评语) manager .create_index( Index::create() .name("idx_comments_journal") .table(Comments::Table) .col(Comments::JournalId) .to_owned(), ) .await?; // 外键约束 manager .create_foreign_key( ForeignKey::create() .name("fk_comments_journal") .from(Comments::Table, Comments::JournalId) .to(super::m20260531_000170_create_journal_entries::JournalEntries::Table, super::m20260531_000170_create_journal_entries::JournalEntries::Id) .on_delete(ForeignKeyAction::Cascade) .to_owned(), ) .await?; Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(Comments::Table).to_owned()) .await } } #[derive(DeriveIden)] enum Comments { Table, Id, TenantId, JournalId, AuthorId, Content, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, DeletedAt, Version, }