Skip to content

Commit

Permalink
refactor(annim): use jsonb for extra
Browse files Browse the repository at this point in the history
  • Loading branch information
Yesterday17 committed Sep 5, 2024
1 parent bfff0b2 commit c1fd58a
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions annim/src/entities/postgres/album.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub struct Model {
pub level: MetadataOrganizeLevel,
pub created_at: DateTime,
pub updated_at: DateTime,
#[sea_orm(column_type = "JsonBinary", nullable)]
pub extra: Option<Json>,
}

Expand Down
2 changes: 1 addition & 1 deletion annim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async fn graphql_ws_handler(
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_max_level(tracing::Level::WARN)
.with_max_level(tracing::Level::INFO)
.with_test_writer()
.init();

Expand Down
40 changes: 40 additions & 0 deletions annim/src/migrator/m20240905_000004_album_extra_jsonb.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
use sea_orm::DbErr;
use sea_orm_migration::{prelude::*, schema::*};

use super::m20240817_000001_create_basic_tables::Album;

pub struct Migration;

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

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(Album::Table)
.modify_column(json_binary_null(Album::Extra))
.to_owned(),
)
.await?;

Ok(())
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.modify_column(json_null(Album::Extra))
.to_owned(),
)
.await?;

Ok(())
}
}
2 changes: 2 additions & 0 deletions annim/src/migrator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ mod helper;
mod m20240817_000001_create_basic_tables;
mod m20240824_000002_create_tag_tables;
mod m20240905_000003_add_tag_type_category;
mod m20240905_000004_album_extra_jsonb;

pub struct Migrator;

Expand All @@ -14,6 +15,7 @@ impl MigratorTrait for Migrator {
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),
Box::new(m20240905_000004_album_extra_jsonb::Migration),
]
}
}

0 comments on commit c1fd58a

Please sign in to comment.