2023-07-16 23:59:26 +00:00
|
|
|
const config = require('config');
|
|
|
|
|
|
|
|
exports.up = async (knex) => {
|
|
|
|
await knex.raw(`
|
|
|
|
CREATE MATERIALIZED VIEW releases_summaries AS (
|
|
|
|
SELECT
|
|
|
|
releases.id as release_id,
|
|
|
|
channels.slug as channel_slug,
|
|
|
|
channels.type as channel_type,
|
|
|
|
networks.slug as network_slug,
|
|
|
|
networks.type as network_type,
|
|
|
|
parent_networks.slug as parent_network_slug,
|
|
|
|
parent_networks.type as parent_network_type,
|
|
|
|
studios.showcased IS NOT false
|
|
|
|
AND (channels.showcased IS NOT false OR COALESCE(studios.showcased, false) = true)
|
|
|
|
AND (networks.showcased IS NOT false OR COALESCE(channels.showcased, false) = true OR COALESCE(studios.showcased, false) = true)
|
|
|
|
AS showcased,
|
2023-07-25 02:23:10 +00:00
|
|
|
batches.showcased AS batch_showcased,
|
2023-07-16 23:59:26 +00:00
|
|
|
releases.effective_date,
|
|
|
|
releases.created_at,
|
2023-07-22 23:02:18 +00:00
|
|
|
array_agg(tags.slug ORDER BY tags.priority DESC) FILTER (WHERE tags.slug IS NOT NULL) AS tags
|
2023-07-16 23:59:26 +00:00
|
|
|
FROM releases
|
|
|
|
LEFT JOIN releases_tags ON releases_tags.release_id = releases.id
|
|
|
|
LEFT JOIN tags ON tags.id = releases_tags.tag_id
|
|
|
|
LEFT JOIN entities AS channels ON channels.id = releases.entity_id
|
|
|
|
LEFT JOIN entities AS studios ON studios.id = releases.studio_id
|
|
|
|
LEFT JOIN entities AS networks ON networks.id = channels.parent_id
|
|
|
|
LEFT JOIN entities AS parent_networks ON parent_networks.id = networks.parent_id
|
2023-07-25 02:23:10 +00:00
|
|
|
LEFT JOIN batches ON batches.id = releases.updated_batch_id
|
|
|
|
GROUP BY releases.id, studios.showcased, batches.showcased,
|
2023-07-16 23:59:26 +00:00
|
|
|
channels.showcased, channels.slug, channels.type,
|
|
|
|
networks.showcased, networks.slug, networks.type,
|
|
|
|
parent_networks.slug, parent_networks.type
|
|
|
|
);
|
|
|
|
|
|
|
|
COMMENT ON MATERIALIZED VIEW releases_summaries IS E'@foreignKey (release_id) references releases (id)';
|
2023-07-25 02:23:10 +00:00
|
|
|
GRANT ALL ON releases_summaries TO :visitor;
|
2023-07-16 23:59:26 +00:00
|
|
|
`, {
|
|
|
|
visitor: knex.raw(config.database.query.user),
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.down = async (knex) => {
|
|
|
|
await knex.raw(`
|
|
|
|
DROP MATERIALIZED VIEW IF EXISTS releases_summaries;
|
|
|
|
`);
|
|
|
|
};
|