Add is_highlighted and is_archived to project

This commit is contained in:
2024-11-10 02:16:01 +01:00
parent 1d16a16b59
commit 5eb0246863
3 changed files with 76 additions and 1 deletions

View File

@@ -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<Box<dyn MigrationTrait>> {
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),

View File

@@ -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
}
}

View File

@@ -18,6 +18,8 @@ pub struct Model {
pub github_url: Option<String>,
pub download_url: Option<String>,
pub visit_url: Option<String>,
pub is_highlighted: bool,
pub is_archived: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
@@ -39,4 +41,4 @@ impl Related<super::data::Entity> for Entity {
fn via() -> Option<RelationDef> {
Some(super::project_thumbnails::Relation::Projects.def().rev())
}
}
}