Skip to content

Commit

Permalink
fix(database,backend): correct lot for import reports
Browse files Browse the repository at this point in the history
Also bump version.
  • Loading branch information
IgnisDa committed Jun 3, 2024
1 parent 03d1905 commit cf3beb2
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion apps/backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ryot"
version = "5.5.5"
version = "5.5.6"
edition = "2021"
repository = "https://github.com/IgnisDa/ryot"
license = "GPL-3.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
use sea_orm_migration::prelude::*;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
let db = manager.get_connection();
db.execute_unprepared(
r#"
DO $$
DECLARE
record RECORD;
item JSONB;
new_failed_items JSONB;
new_lot TEXT;
BEGIN
FOR record IN SELECT id, details FROM import_report LOOP
new_failed_items := '[]'::jsonb;
FOR item IN SELECT jsonb_array_elements(record.details->'failed_items') LOOP
new_lot := CASE item->>'lot'
WHEN 'AudioBook' THEN 'audio_book'
WHEN 'Anime' THEN 'anime'
WHEN 'Book' THEN 'book'
WHEN 'Podcast' THEN 'podcast'
WHEN 'Manga' THEN 'manga'
WHEN 'Movie' THEN 'movie'
WHEN 'Show' THEN 'show'
WHEN 'VideoGame' THEN 'video_game'
WHEN 'VisualNovel' THEN 'visual_novel'
ELSE item->>'lot'
END;
IF new_lot IS NOT NULL THEN
item := jsonb_set(item, '{lot}', to_jsonb(new_lot));
END IF;
new_failed_items := new_failed_items || item;
END LOOP;
UPDATE import_report
SET details = jsonb_set(record.details, '{failed_items}', new_failed_items)
WHERE id = record.id;
END LOOP;
END;
$$ LANGUAGE plpgsql;
"#,
)
.await?;
Ok(())
}

async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
Ok(())
}
}
2 changes: 2 additions & 0 deletions libs/database/src/migrations/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ mod m20240601_10_change_enums_to_snake_case;
mod m20240601_11_workout_table_changes;
mod m20240606_is_last_v5_migration;
mod m20240607_is_really_last_v5_migration;
mod m20240608_definitely_final_v5_migration;

pub use m20230410_create_metadata::Metadata as AliasedMetadata;
pub use m20230413_create_person::Person as AliasedPerson;
Expand Down Expand Up @@ -128,6 +129,7 @@ impl MigratorTrait for Migrator {
Box::new(m20240601_11_workout_table_changes::Migration),
Box::new(m20240606_is_last_v5_migration::Migration),
Box::new(m20240607_is_really_last_v5_migration::Migration),
Box::new(m20240608_definitely_final_v5_migration::Migration),
]
}
}

0 comments on commit cf3beb2

Please sign in to comment.