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(CopilotRules::Table) .col( ColumnDef::new(CopilotRules::Id) .uuid() .not_null() .primary_key(), ) .col(ColumnDef::new(CopilotRules::TenantId).uuid().not_null()) .col( ColumnDef::new(CopilotRules::Name) .string_len(200) .not_null(), ) .col( ColumnDef::new(CopilotRules::Category) .string_len(50) .not_null(), ) .col( ColumnDef::new(CopilotRules::ConditionExpr) .json() .not_null(), ) .col( ColumnDef::new(CopilotRules::Score) .small_integer() .not_null(), ) .col( ColumnDef::new(CopilotRules::Severity) .string_len(20) .not_null(), ) .col(ColumnDef::new(CopilotRules::Suggestion).text().null()) .col( ColumnDef::new(CopilotRules::Enabled) .boolean() .not_null() .default(true), ) .col( ColumnDef::new(CopilotRules::SortOrder) .integer() .not_null() .default(0), ) .col( ColumnDef::new(CopilotRules::CreatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col( ColumnDef::new(CopilotRules::UpdatedAt) .timestamp_with_time_zone() .not_null() .default(Expr::current_timestamp()), ) .col(ColumnDef::new(CopilotRules::CreatedBy).uuid().null()) .col(ColumnDef::new(CopilotRules::UpdatedBy).uuid().null()) .col( ColumnDef::new(CopilotRules::DeletedAt) .timestamp_with_time_zone() .null(), ) .col( ColumnDef::new(CopilotRules::VersionLock) .integer() .not_null() .default(1), ) .to_owned(), ) .await?; manager .create_index( Index::create() .name("idx_copilot_rules_tenant_category") .table(CopilotRules::Table) .col(CopilotRules::TenantId) .col(CopilotRules::Category) .to_owned(), ) .await } async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { manager .drop_table(Table::drop().table(CopilotRules::Table).to_owned()) .await } } #[derive(DeriveIden)] enum CopilotRules { Table, Id, TenantId, Name, Category, ConditionExpr, Score, Severity, Suggestion, Enabled, SortOrder, CreatedAt, UpdatedAt, CreatedBy, UpdatedBy, DeletedAt, VersionLock, }