27 lines
855 B
MySQL
27 lines
855 B
MySQL
|
|
BEGIN;
|
||
|
|
|
||
|
|
-- Put the ALSO billing period on its own line for pending order drafts.
|
||
|
|
UPDATE ordre_drafts
|
||
|
|
SET lines_json = (
|
||
|
|
SELECT jsonb_agg(
|
||
|
|
CASE
|
||
|
|
WHEN item->>'source_type' = 'also_cloud'
|
||
|
|
AND COALESCE(item->>'description', '') LIKE '% · Periode: %'
|
||
|
|
THEN jsonb_set(
|
||
|
|
item,
|
||
|
|
'{description}',
|
||
|
|
to_jsonb(replace(item->>'description', ' · Periode: ', E'\nPeriode: '))
|
||
|
|
)
|
||
|
|
ELSE item
|
||
|
|
END
|
||
|
|
ORDER BY ordinality
|
||
|
|
)
|
||
|
|
FROM jsonb_array_elements(lines_json) WITH ORDINALITY AS source(item, ordinality)
|
||
|
|
),
|
||
|
|
updated_at = CURRENT_TIMESTAMP
|
||
|
|
WHERE sync_status = 'pending'
|
||
|
|
AND invoice_aggregate_key LIKE 'also-cloud-%'
|
||
|
|
AND lines_json::text LIKE '% · Periode: %';
|
||
|
|
|
||
|
|
COMMIT;
|