// 主题布置表 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(TopicAssignments::Table) .if_not_exists() .col(ColumnDef::new(TopicAssignments::Id).uuid().not_null().primary_key()) .col(ColumnDef::new(TopicAssignments::TenantId).uuid().not_null()) .col(ColumnDef::new(TopicAssignments::ClassId).uuid().not_null()) .col(ColumnDef::new(TopicAssignments::TeacherId).uuid().not_null()) .col(ColumnDef::new(TopicAssignments::Title).string().not_null()) .col(ColumnDef::new(TopicAssignments::Description).text().null()) .col(ColumnDef::new(TopicAssignments::DueDate).date().null()) .col(ColumnDef::new(TopicAssignments::IsActive).boolean().not_null().default(true)) .col( ColumnDef::new(TopicAssignments::CreatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col( ColumnDef::new(TopicAssignments::UpdatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col(ColumnDef::new(TopicAssignments::CreatedBy).uuid().not_null()) .col(ColumnDef::new(TopicAssignments::UpdatedBy).uuid().not_null()) .col(ColumnDef::new(TopicAssignments::DeletedAt).timestamp_with_time_zone().null()) .col(ColumnDef::new(TopicAssignments::Version).integer().not_null().default(1)) .to_owned(), ) .await?; // 班级 + 激活状态索引 manager .create_index( Index::create() .name("idx_topic_assignments_class_active") .table(TopicAssignments::Table) .col(TopicAssignments::ClassId) .col(TopicAssignments::IsActive) .to_owned(), ) .await?; // 外键约束 manager .create_foreign_key( ForeignKey::create() .name("fk_topic_assignments_class") .from(TopicAssignments::Table, TopicAssignments::ClassId) .to(super::m20260531_000173_create_school_classes::SchoolClasses::Table, super::m20260531_000173_create_school_classes::SchoolClasses::Id) .on_delete(ForeignKeyAction::Cascade) .to_owned(), ) .await?; Ok(()) } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(TopicAssignments::Table).to_owned()) .await } } #[derive(DeriveIden)] enum TopicAssignments { Table, Id, TenantId, ClassId, TeacherId, Title, Description, DueDate, IsActive, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, DeletedAt, Version, }