diff --git a/Cargo.toml b/Cargo.toml index c5ed7bf..a6eec0f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "twba-local-db" -version = "0.2.1" +version = "0.3.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -9,13 +9,13 @@ edition = "2021" sea-orm = { version = "0.12", features = ["sqlx-sqlite", "runtime-tokio-rustls", "macros"] } sea-orm-migration = "0.12" -tokio = { version = "1.33" , features = ["full"]} +tokio = { version = "1.33", features = ["full"] } thiserror = "1.0" futures = "0.3" tracing = "0.1" -anyhow = { version = "1.0" , optional = true} -tracing-subscriber = { version = "0.3" ,optional = true} +anyhow = { version = "1.0", optional = true } +tracing-subscriber = { version = "0.3", optional = true } [features] build-binary = ["anyhow", "tracing-subscriber"] diff --git a/src/entities/users.rs b/src/entities/users.rs index 3e35645..b8e3ded 100644 --- a/src/entities/users.rs +++ b/src/entities/users.rs @@ -26,6 +26,7 @@ pub struct Model { /// be split into multiple parts. pub youtube_max_duration: i32, pub active: bool, + pub timezone: String, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/src/lib.rs b/src/lib.rs index ae2b902..3d66417 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,3 @@ -use crate::entities::video_upload::UploadStatus; -use crate::{ - entities::prelude::{Users, VideoUpload, Videos}, - entities::status::Status, - entities::*, - migrator::Migrator, -}; use sea_orm::ActiveValue::Set; use sea_orm::{ ActiveModelTrait, ActiveValue, ColumnTrait, Database, DatabaseConnection, DbErr, EntityTrait, @@ -12,6 +5,13 @@ use sea_orm::{ }; use sea_orm_migration::MigratorTrait; use tracing::{info, instrument}; +use { + entities::prelude::{Users, VideoUpload, Videos}, + entities::status::Status, + entities::video_upload::UploadStatus, + entities::*, + migrator::Migrator, +}; pub mod entities; mod migrator; diff --git a/src/migrator/m20240509_000006_alter_users_table_for_timezone.rs b/src/migrator/m20240509_000006_alter_users_table_for_timezone.rs new file mode 100644 index 0000000..13f1794 --- /dev/null +++ b/src/migrator/m20240509_000006_alter_users_table_for_timezone.rs @@ -0,0 +1,39 @@ +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(Users::Table) + .add_column( + ColumnDef::new(Users::Timezone) + .string() + .not_null() + .default("+00:00"), + ) + .to_owned(), + ) + .await + } + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Users::Table) + .drop_column(Users::Timezone) + .to_owned(), + ) + .await + } +} + +#[derive(Iden)] +pub enum Users { + Table, + Timezone, +} diff --git a/src/migrator/mod.rs b/src/migrator/mod.rs index e028e38..c1f1b06 100644 --- a/src/migrator/mod.rs +++ b/src/migrator/mod.rs @@ -6,6 +6,8 @@ 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; +mod m20240509_000006_alter_users_table_for_timezone; + pub struct Migrator; #[async_trait::async_trait] impl MigratorTrait for Migrator { @@ -14,9 +16,10 @@ impl MigratorTrait for Migrator { Box::new(m20230916_000001_create_users_table::Migration), Box::new(m20230916_000002_create_videos_table::Migration), Box::new(m20230916_000003_create_video_upload_table::Migration), - // Box::new(m20230916_000004_add_sample_data::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), + Box::new(m20240509_000006_alter_users_table_for_timezone::Migration), ] } }