diff --git a/Cargo.toml b/Cargo.toml index 1fa9b32..e1611cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/entities/status.rs b/src/entities/status.rs index 728b03a..6c6d081 100644 --- a/src/entities/status.rs +++ b/src/entities/status.rs @@ -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, diff --git a/src/entities/video_upload.rs b/src/entities/video_upload.rs index 1e8f854..88b8f4c 100644 --- a/src/entities/video_upload.rs +++ b/src/entities/video_upload.rs @@ -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, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/src/lib.rs b/src/lib.rs index fcf3843..3ef6e22 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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) diff --git a/src/migrator/m20231029_000006_alter_video_uploads_table_for_youtube_id.rs b/src/migrator/m20231029_000006_alter_video_uploads_table_for_youtube_id.rs new file mode 100644 index 0000000..07187ba --- /dev/null +++ b/src/migrator/m20231029_000006_alter_video_uploads_table_for_youtube_id.rs @@ -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::), + ) + .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, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index be0a61e..e028e38 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -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), ] } }