Skip to content

Commit

Permalink
fix(annim): add missing category tag_type
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Sep 5, 2024
1 parent 44d3bca commit bfff0b2
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 4 deletions.
5 changes: 2 additions & 3 deletions annim/src/entities/helper/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ impl From<TagTypeEnum> for TagType {
TagTypeEnum::Project => TagType::Project,
TagTypeEnum::Game => TagType::Game,
TagTypeEnum::Organization => TagType::Organization,
// TODO: category
// TagTypeEnum::Category => TagType::Category,
TagTypeEnum::Category => TagType::Others,
TagTypeEnum::Category => TagType::Category,
TagTypeEnum::Others => TagType::Others,
}
}
Expand All @@ -63,6 +61,7 @@ impl From<&TagType> for TagTypeEnum {
TagType::Project => TagTypeEnum::Project,
TagType::Game => TagTypeEnum::Game,
TagType::Organization => TagTypeEnum::Organization,
TagType::Category => TagTypeEnum::Category,
TagType::Others => TagTypeEnum::Others,
}
}
Expand Down
2 changes: 2 additions & 0 deletions annim/src/entities/postgres/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub enum TagType {
Animation,
#[sea_orm(string_value = "artist")]
Artist,
#[sea_orm(string_value = "category")]
Category,
#[sea_orm(string_value = "game")]
Game,
#[sea_orm(string_value = "group")]
Expand Down
2 changes: 1 addition & 1 deletion annim/src/migrator/m20240824_000002_create_tag_tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ pub enum TagInfo {
}

#[derive(Iden, EnumIter)]
enum TagType {
pub enum TagType {
Artist,
Group,
Animation,
Expand Down
37 changes: 37 additions & 0 deletions annim/src/migrator/m20240905_000003_add_tag_type_category.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
use extension::postgres::Type;
use sea_orm::DbErr;
use sea_orm_migration::prelude::*;

pub struct Migration;

impl MigrationName for Migration {
fn name(&self) -> &str {
"m20240905_000003_add_tag_type_category"
}
}

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
match manager.get_database_backend() {
sea_orm::DatabaseBackend::Postgres => {
manager
.alter_type(
Type::alter()
.name(Alias::new("tag_type"))
.add_value(Alias::new("category"))
.before(super::m20240824_000002_create_tag_tables::TagType::Others),
)
.await?;
}
_ => {}
}

Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
// Can not revert the type change
Ok(())
}
}
2 changes: 2 additions & 0 deletions annim/src/migrator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod helper;

mod m20240817_000001_create_basic_tables;
mod m20240824_000002_create_tag_tables;
mod m20240905_000003_add_tag_type_category;

pub struct Migrator;

Expand All @@ -12,6 +13,7 @@ impl MigratorTrait for Migrator {
vec![
Box::new(m20240817_000001_create_basic_tables::Migration),
Box::new(m20240824_000002_create_tag_tables::Migration),
Box::new(m20240905_000003_add_tag_type_category::Migration),
]
}
}

0 comments on commit bfff0b2

Please sign in to comment.