Files
Jellystat/backend/migrations/056_js_library_metadata.js
Thegan Govender c284d59454 Fix for incorrect stat count
Forgot to add archived items exclusion when tallying stats
This feature has been extended to seasons and seasons/episodes as some episodes may be archived but not the entire show
2023-11-26 20:06:33 +02:00

40 lines
1.1 KiB
JavaScript

exports.up = async function(knex) {
try
{
await knex.schema.raw(`
CREATE OR REPLACE VIEW public.js_library_metadata
AS
SELECT l."Id",
l."Name",
sum(ii."Size") AS "Size",
count(*) AS files
FROM jf_libraries l
JOIN jf_library_items i ON i."ParentId" = l."Id" AND i.archived=false
LEFT JOIN jf_library_episodes e ON e."SeriesId" = i."Id" AND e.archived=false
LEFT JOIN jf_item_info ii ON ii."Id" = i."Id" OR ii."Id" = e."EpisodeId"
GROUP BY l."Id", l."Name";`);
}catch (error) {
console.error(error);
}
};
exports.down = async function(knex) {
try {
await knex.schema.raw(`
CREATE OR REPLACE VIEW public.js_library_metadata
AS
SELECT l."Id",
l."Name",
sum(ii."Size") AS "Size",
count(*) AS files
FROM jf_libraries l
JOIN jf_library_items i ON i."ParentId" = l."Id"
LEFT JOIN jf_library_episodes e ON e."SeriesId" = i."Id"
LEFT JOIN jf_item_info ii ON ii."Id" = i."Id" OR ii."Id" = e."EpisodeId"
GROUP BY l."Id", l."Name";`);
} catch (error) {
console.error(error);
}
};