mirror of
https://github.com/OMGeeky/twitch_backup.local_db.git
synced 2026-01-06 19:45:29 +01:00
add some fields & fix migrator
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
[package]
|
||||
name = "local-db"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
@@ -18,6 +18,8 @@ pub enum Status {
|
||||
#[sea_orm(num_value = 40)]
|
||||
Split,
|
||||
#[sea_orm(num_value = 50)]
|
||||
Uploading,
|
||||
#[sea_orm(num_value = 55)]
|
||||
PartiallyUploaded,
|
||||
#[sea_orm(num_value = 59)]
|
||||
UploadFailed,
|
||||
|
||||
@@ -10,6 +10,7 @@ pub struct Model {
|
||||
#[sea_orm(primary_key, auto_increment = false)]
|
||||
pub part: i32,
|
||||
pub upload_status: UploadStatus,
|
||||
pub youtube_video_id: Option<String>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
|
||||
@@ -7,8 +7,8 @@ use crate::{
|
||||
};
|
||||
use sea_orm::ActiveValue::Set;
|
||||
use sea_orm::{
|
||||
ActiveModelTrait, ColumnTrait, Database, DatabaseConnection, DbErr, EntityTrait, ModelTrait,
|
||||
QueryFilter,
|
||||
ActiveModelTrait, ActiveValue, ColumnTrait, Database, DatabaseConnection, DbErr, EntityTrait,
|
||||
ModelTrait, QueryFilter,
|
||||
};
|
||||
use sea_orm_migration::MigratorTrait;
|
||||
use tracing::{info, instrument};
|
||||
@@ -32,7 +32,8 @@ pub async fn reset_db(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
}
|
||||
/// Applies all migrations that are not already applied.
|
||||
pub async fn migrate_db(db: &DatabaseConnection) -> Result<(), DbErr> {
|
||||
Migrator::refresh(db).await?;
|
||||
Migrator::up(db, None).await?;
|
||||
// Migrator::refresh(db).await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -104,6 +105,7 @@ pub async fn create_video_upload<'a, V: Into<&'a videos::Model>>(
|
||||
video_id: Set(video.id),
|
||||
part: Set(part),
|
||||
upload_status: Set(UploadStatus::Pending),
|
||||
youtube_video_id: ActiveValue::NotSet,
|
||||
};
|
||||
let upload = upload.insert(db).await?;
|
||||
Ok(upload)
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
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
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(VideoUpload::Table)
|
||||
.add_column(
|
||||
ColumnDef::new(VideoUpload::YoutubeVideoId)
|
||||
.string()
|
||||
.null()
|
||||
.default(None::<String>),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.alter_table(
|
||||
Table::alter()
|
||||
.table(VideoUpload::Table)
|
||||
.drop_column(VideoUpload::YoutubeVideoId)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
#[derive(Iden)]
|
||||
pub enum VideoUpload {
|
||||
Table,
|
||||
YoutubeVideoId,
|
||||
}
|
||||
@@ -5,7 +5,7 @@ mod m20230916_000002_create_videos_table;
|
||||
mod m20230916_000003_create_video_upload_table;
|
||||
mod m20230916_000004_add_sample_data;
|
||||
mod m20231015_000005_alter_videos_table_for_errors;
|
||||
|
||||
mod m20231029_000006_alter_video_uploads_table_for_youtube_id;
|
||||
pub struct Migrator;
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
@@ -16,6 +16,7 @@ impl MigratorTrait for Migrator {
|
||||
Box::new(m20230916_000003_create_video_upload_table::Migration),
|
||||
// Box::new(m20230916_000004_add_sample_data::Migration),
|
||||
Box::new(m20231015_000005_alter_videos_table_for_errors::Migration),
|
||||
Box::new(m20231029_000006_alter_video_uploads_table_for_youtube_id::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user