diff --git a/migration/src/lib.rs b/migration/src/lib.rs index b0a3974..65d3e51 100644 --- a/migration/src/lib.rs +++ b/migration/src/lib.rs @@ -9,6 +9,7 @@ mod m20241030_002154_jobs; mod m20241030_024340_projects; mod m20241030_024830_data; mod m20241106_005545_project_thumbnails; +mod m20241110_011041_add_is_highlighted_to_project; pub struct Migrator; #[async_trait::async_trait] @@ -16,6 +17,7 @@ impl MigratorTrait for Migrator { fn migrations() -> Vec> { vec![ // inject-below + Box::new(m20241110_011041_add_is_highlighted_to_project::Migration), Box::new(m20241106_005545_project_thumbnails::Migration), Box::new(m20241030_024830_data::Migration), Box::new(m20241030_024340_projects::Migration), diff --git a/migration/src/m20241110_011041_add_is_highlighted_to_project.rs b/migration/src/m20241110_011041_add_is_highlighted_to_project.rs new file mode 100644 index 0000000..5c96d94 --- /dev/null +++ b/migration/src/m20241110_011041_add_is_highlighted_to_project.rs @@ -0,0 +1,71 @@ +use sea_orm_migration::{prelude::*, schema::*}; + +#[derive(DeriveMigrationName)] +pub struct Migration; + +#[derive(DeriveIden)] +enum Projects { + Table, + IsHighlighted, + IsArchived, +} + +#[async_trait::async_trait] +impl MigrationTrait for Migration { + async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { + // + // add column + // + manager + .alter_table( + Table::alter() + .table(Projects::Table) + .add_column_if_not_exists(boolean(Projects::IsHighlighted).default(false)) + .add_column_if_not_exists(boolean(Projects::IsArchived).default(false)) + .to_owned(), + ) + .await + + // + // delete column + // + /* + manager + .alter_table( + Table::alter() + .table(Movies::Table) + .drop_column(Movies::Rating) + .to_owned(), + ) + .await + */ + + // + // create index + // + /* + manager + .create_index( + Index::create() + .name("idx-movies-rating") + .table(Movies::Table) + .col(Movies::Rating) + .to_owned(), + ) + .await; + */ + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + manager + .alter_table( + Table::alter() + .table(Projects::Table) + .drop_column(Projects::IsHighlighted) + .drop_column(Projects::IsArchived) + .to_owned(), + ) + .await + } +} + diff --git a/src/models/_entities/projects.rs b/src/models/_entities/projects.rs index 2b0e0c2..3e0ccaf 100644 --- a/src/models/_entities/projects.rs +++ b/src/models/_entities/projects.rs @@ -18,6 +18,8 @@ pub struct Model { pub github_url: Option, pub download_url: Option, pub visit_url: Option, + pub is_highlighted: bool, + pub is_archived: bool, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] @@ -39,4 +41,4 @@ impl Related for Entity { fn via() -> Option { Some(super::project_thumbnails::Relation::Projects.def().rev()) } -} \ No newline at end of file +}