Skip to content

Commit cf3beb2

Browse files
committed
fix(database,backend): correct lot for import reports
Also bump version.
1 parent 03d1905 commit cf3beb2

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/backend/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "ryot"
3-
version = "5.5.5"
3+
version = "5.5.6"
44
edition = "2021"
55
repository = "https://github.com/IgnisDa/ryot"
66
license = "GPL-3.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
use sea_orm_migration::prelude::*;
2+
3+
#[derive(DeriveMigrationName)]
4+
pub struct Migration;
5+
6+
#[async_trait::async_trait]
7+
impl MigrationTrait for Migration {
8+
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
9+
let db = manager.get_connection();
10+
db.execute_unprepared(
11+
r#"
12+
DO $$
13+
DECLARE
14+
record RECORD;
15+
item JSONB;
16+
new_failed_items JSONB;
17+
new_lot TEXT;
18+
BEGIN
19+
FOR record IN SELECT id, details FROM import_report LOOP
20+
new_failed_items := '[]'::jsonb;
21+
FOR item IN SELECT jsonb_array_elements(record.details->'failed_items') LOOP
22+
new_lot := CASE item->>'lot'
23+
WHEN 'AudioBook' THEN 'audio_book'
24+
WHEN 'Anime' THEN 'anime'
25+
WHEN 'Book' THEN 'book'
26+
WHEN 'Podcast' THEN 'podcast'
27+
WHEN 'Manga' THEN 'manga'
28+
WHEN 'Movie' THEN 'movie'
29+
WHEN 'Show' THEN 'show'
30+
WHEN 'VideoGame' THEN 'video_game'
31+
WHEN 'VisualNovel' THEN 'visual_novel'
32+
ELSE item->>'lot'
33+
END;
34+
35+
IF new_lot IS NOT NULL THEN
36+
item := jsonb_set(item, '{lot}', to_jsonb(new_lot));
37+
END IF;
38+
39+
new_failed_items := new_failed_items || item;
40+
END LOOP;
41+
42+
UPDATE import_report
43+
SET details = jsonb_set(record.details, '{failed_items}', new_failed_items)
44+
WHERE id = record.id;
45+
END LOOP;
46+
END;
47+
$$ LANGUAGE plpgsql;
48+
"#,
49+
)
50+
.await?;
51+
Ok(())
52+
}
53+
54+
async fn down(&self, _manager: &SchemaManager) -> Result<(), DbErr> {
55+
Ok(())
56+
}
57+
}

libs/database/src/migrations/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ mod m20240601_10_change_enums_to_snake_case;
4747
mod m20240601_11_workout_table_changes;
4848
mod m20240606_is_last_v5_migration;
4949
mod m20240607_is_really_last_v5_migration;
50+
mod m20240608_definitely_final_v5_migration;
5051

5152
pub use m20230410_create_metadata::Metadata as AliasedMetadata;
5253
pub use m20230413_create_person::Person as AliasedPerson;
@@ -128,6 +129,7 @@ impl MigratorTrait for Migrator {
128129
Box::new(m20240601_11_workout_table_changes::Migration),
129130
Box::new(m20240606_is_last_v5_migration::Migration),
130131
Box::new(m20240607_is_really_last_v5_migration::Migration),
132+
Box::new(m20240608_definitely_final_v5_migration::Migration),
131133
]
132134
}
133135
}

0 commit comments

Comments
 (0)