diff --git a/Cargo.lock b/Cargo.lock index 94b837532f..421a6f4371 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4969,7 +4969,7 @@ checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" [[package]] name = "ryot" -version = "5.5.5" +version = "5.5.6" dependencies = [ "anyhow", "apalis", diff --git a/apps/backend/Cargo.toml b/apps/backend/Cargo.toml index 840e48e362..80ad63a0fb 100644 --- a/apps/backend/Cargo.toml +++ b/apps/backend/Cargo.toml @@ -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" diff --git a/libs/database/src/migrations/m20240608_definitely_final_v5_migration.rs b/libs/database/src/migrations/m20240608_definitely_final_v5_migration.rs new file mode 100644 index 0000000000..1e92e9349d --- /dev/null +++ b/libs/database/src/migrations/m20240608_definitely_final_v5_migration.rs @@ -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(()) + } +} diff --git a/libs/database/src/migrations/mod.rs b/libs/database/src/migrations/mod.rs index e6d2603628..50dc7da9ab 100644 --- a/libs/database/src/migrations/mod.rs +++ b/libs/database/src/migrations/mod.rs @@ -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; @@ -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), ] } }