use sea_orm_migration::{prelude::*, schema::*};
use crate::m20260208_034207_inboxes::Inbox;
#[derive(DeriveIden)]
enum Message {
Table,
Gid,
InboxId,
Envelope,
CreatedAt,
}
#[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(Message::Table)
.if_not_exists()
.col(uuid(Message::Gid).not_null().primary_key())
.col(uuid(Message::InboxId).not_null())
.col(json(Message::Envelope).not_null())
.col(timestamp(Message::CreatedAt).not_null())
.foreign_key(
ForeignKey::create()
.from(Message::Table, Message::InboxId)
.to(Inbox::Table, Inbox::Id)
.on_delete(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_message_inbox_created")
.table(Message::Table)
.col(Message::InboxId)
.col(Message::CreatedAt)
.to_owned(),
)
.await
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(Message::Table).to_owned())
.await
}
}