fix: Migration 0034 compatibility with MySQL

`DISTINCT` cannot be used within `JSON_ARRAYAGG` in MySQL, so it was
removed.

Also, the PostgreSQL query was simplified and now generates JSONB
columns, to be consistent with all the other tables.
This commit is contained in:
Michael Manganiello
2025-02-14 00:17:06 -03:00
parent 48bfd76ec6
commit 7ba7da8d34

View File

@@ -115,9 +115,9 @@ def upgrade() -> None:
'Autogenerated ' || collection_type || ' collection' AS description,
NOW() AS created_at,
NOW() AS updated_at,
array_to_json(array_agg(rom_id)) as rom_ids,
array_to_json(array_agg(path_cover_s)) as path_covers_s,
array_to_json(array_agg(path_cover_l)) as path_covers_l
jsonb_agg(rom_id) as rom_ids,
jsonb_agg(path_cover_s) as path_covers_s,
jsonb_agg(path_cover_l) as path_covers_l
FROM (
SELECT * FROM genres_collection
UNION ALL
@@ -149,7 +149,7 @@ def upgrade() -> None:
connection.execute(
sa.text(
"""
CREATE OR REPLACE VIEW virtual_collections AS
CREATE OR REPLACE VIEW virtual_collections AS
WITH genres AS (
SELECT
r.id as rom_id,
@@ -236,9 +236,9 @@ def upgrade() -> None:
CONCAT('Autogenerated ', collection_name, ' collection') AS description,
NOW() AS created_at,
NOW() AS updated_at,
JSON_ARRAYAGG(DISTINCT rom_id) as rom_ids,
JSON_ARRAYAGG(DISTINCT path_cover_s) as path_covers_s,
JSON_ARRAYAGG(DISTINCT path_cover_l) as path_covers_l
JSON_ARRAYAGG(rom_id) as rom_ids,
JSON_ARRAYAGG(path_cover_s) as path_covers_s,
JSON_ARRAYAGG(path_cover_l) as path_covers_l
FROM
(
SELECT * FROM genres