From 58bb2c22c35519d4d7356d08dfc45812203bd094 Mon Sep 17 00:00:00 2001 From: nkanaev Date: Mon, 24 Mar 2025 02:27:07 +0000 Subject: [PATCH] rewrite migration --- src/storage/migration.go | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/src/storage/migration.go b/src/storage/migration.go index 2dac555..abe13b1 100644 --- a/src/storage/migration.go +++ b/src/storage/migration.go @@ -310,22 +310,19 @@ func m09_change_item_index(tx *sql.Tx) error { func m10_add_item_medialinks(tx *sql.Tx) error { sql := ` - alter table items add column media_links blob; - update items set media_links = - iif( - coalesce(image, '') != '' and coalesce(podcast_url, '') != '', - json_array(json_object('type', 'image', 'url', image), json_object('type', 'audio', 'url', podcast_url)), - iif( - coalesce(image, '') != '', - json_array(json_object('type', 'image', 'url', image)), - iif( - coalesce(podcast_url, '') != '', - json_array(json_object('type', 'audio', 'url', podcast_url)), - null - ) - ) - ); + alter table items add column media_links json; + update items set media_links = case + when coalesce(image, '') != '' and coalesce(podcast_url, '') != '' + then json_array(json_object('type', 'image', 'url', image), json_object('type', 'audio', 'url', podcast_url)) + when coalesce(image, '') != '' + then json_array(json_object('type', 'image', 'url', image)) + + when coalesce(podcast_url, '') != '' + then json_array(json_object('type', 'audio', 'url', podcast_url)) + + else null + end; alter table items drop column image; alter table items drop column podcast_url; `