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(UploadJobs::Table)
.if_not_exists()
.col(ColumnDef::new(UploadJobs::Id).big_integer().not_null().auto_increment().primary_key())
.col(ColumnDef::new(UploadJobs::UploadId).big_integer().not_null())
.col(ColumnDef::new(UploadJobs::Kind).string_len(32).not_null())
.col(ColumnDef::new(UploadJobs::Status).string_len(16).not_null().default("pending"))
.col(ColumnDef::new(UploadJobs::Error).text().null())
.col(ColumnDef::new(UploadJobs::Attempts).integer().not_null().default(0))
.col(ColumnDef::new(UploadJobs::StartedAt).timestamp_with_time_zone().null())
.col(ColumnDef::new(UploadJobs::CompletedAt).timestamp_with_time_zone().null())
.col(ColumnDef::new(UploadJobs::CreatedAt).timestamp_with_time_zone().not_null().default(Expr::current_timestamp()))
.col(ColumnDef::new(UploadJobs::UpdatedAt).timestamp_with_time_zone().not_null().default(Expr::current_timestamp()))
.foreign_key(
ForeignKey::create()
.name("fk_upload_jobs_upload_id")
.from(UploadJobs::Table, UploadJobs::UploadId)
.to(Alias::new("uploads"), Alias::new("id"))
.on_delete(ForeignKeyAction::Cascade)
.on_update(ForeignKeyAction::Cascade),
)
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("unique_upload_job_kind")
.table(UploadJobs::Table)
.col(UploadJobs::UploadId)
.col(UploadJobs::Kind)
.unique()
.to_owned(),
)
.await?;
manager
.create_index(
Index::create()
.name("idx_upload_jobs_status")
.table(UploadJobs::Table)
.col(UploadJobs::Status)
.to_owned(),
)
.await?;
Ok(())
}
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.drop_table(Table::drop().table(UploadJobs::Table).to_owned())
.await
}
}
#[derive(DeriveIden)]
enum UploadJobs {
Table,
Id,
UploadId,
Kind,
Status,
Error,
Attempts,
StartedAt,
CompletedAt,
CreatedAt,
UpdatedAt,
}
⭐
Log in to mark this repository.
2.9 KiB · text
History
1ce9641