diff --git a/annim/src/entities/helper/postgres.rs b/annim/src/entities/helper/postgres.rs index 003705b..48c9d30 100644 --- a/annim/src/entities/helper/postgres.rs +++ b/annim/src/entities/helper/postgres.rs @@ -44,9 +44,7 @@ impl From 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, } } @@ -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, } } diff --git a/annim/src/entities/postgres/sea_orm_active_enums.rs b/annim/src/entities/postgres/sea_orm_active_enums.rs index 8a4ab18..dc837a7 100644 --- a/annim/src/entities/postgres/sea_orm_active_enums.rs +++ b/annim/src/entities/postgres/sea_orm_active_enums.rs @@ -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")] diff --git a/annim/src/migrator/m20240824_000002_create_tag_tables.rs b/annim/src/migrator/m20240824_000002_create_tag_tables.rs index 772c0eb..21c4a9f 100644 --- a/annim/src/migrator/m20240824_000002_create_tag_tables.rs +++ b/annim/src/migrator/m20240824_000002_create_tag_tables.rs @@ -221,7 +221,7 @@ pub enum TagInfo { } #[derive(Iden, EnumIter)] -enum TagType { +pub enum TagType { Artist, Group, Animation, diff --git a/annim/src/migrator/m20240905_000003_add_tag_type_category.rs b/annim/src/migrator/m20240905_000003_add_tag_type_category.rs new file mode 100644 index 0000000..3dc8f87 --- /dev/null +++ b/annim/src/migrator/m20240905_000003_add_tag_type_category.rs @@ -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(()) + } +} diff --git a/annim/src/migrator/mod.rs b/annim/src/migrator/mod.rs index 4f91ce8..d8f14f1 100644 --- a/annim/src/migrator/mod.rs +++ b/annim/src/migrator/mod.rs @@ -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; @@ -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), ] } }