59 lines
1.8 KiB
Rust
59 lines
1.8 KiB
Rust
use sea_orm_migration::prelude::*;
|
|
|
|
use super::m20260616_000002_create_stream_key::StreamKey;
|
|
|
|
#[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(StreamSession::Table)
|
|
.if_not_exists()
|
|
.col(
|
|
ColumnDef::new(StreamSession::Id)
|
|
.integer()
|
|
.not_null()
|
|
.auto_increment()
|
|
.primary_key(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(StreamSession::StreamKeyId)
|
|
.integer()
|
|
.not_null(),
|
|
)
|
|
.col(
|
|
ColumnDef::new(StreamSession::StartedAt)
|
|
.date_time()
|
|
.not_null(),
|
|
)
|
|
.col(ColumnDef::new(StreamSession::EndedAt).date_time().null())
|
|
.foreign_key(
|
|
ForeignKey::create()
|
|
.from(StreamSession::Table, StreamSession::StreamKeyId)
|
|
.to(StreamKey::Table, StreamKey::Id),
|
|
)
|
|
.to_owned(),
|
|
)
|
|
.await
|
|
}
|
|
|
|
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
|
manager
|
|
.drop_table(Table::drop().table(StreamSession::Table).to_owned())
|
|
.await
|
|
}
|
|
}
|
|
|
|
#[derive(Iden)]
|
|
pub enum StreamSession {
|
|
Table,
|
|
Id,
|
|
StreamKeyId,
|
|
StartedAt,
|
|
EndedAt,
|
|
}
|