2022-01-19 23:54:10 +00:00
|
|
|
exports.up = async (knex) => knex.raw(`
|
2021-10-30 20:41:58 +00:00
|
|
|
CREATE FUNCTION entities_scenes(entity entities) RETURNS SETOF releases AS $$
|
|
|
|
WITH RECURSIVE children AS (
|
|
|
|
SELECT entities.id
|
|
|
|
FROM entities
|
|
|
|
WHERE entities.id = entity.id
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
SELECT entities.id
|
|
|
|
FROM entities
|
|
|
|
INNER JOIN children ON children.id = entities.parent_id
|
|
|
|
)
|
|
|
|
|
|
|
|
SELECT releases FROM releases
|
2022-02-24 23:00:18 +00:00
|
|
|
INNER JOIN children ON children.id = releases.entity_id
|
|
|
|
|
|
|
|
UNION
|
|
|
|
|
|
|
|
SELECT releases FROM releases
|
|
|
|
INNER JOIN children ON children.id = releases.studio_id;
|
2021-10-30 20:41:58 +00:00
|
|
|
$$ LANGUAGE SQL STABLE;
|
|
|
|
|
|
|
|
COMMENT ON FUNCTION entities_scenes IS E'@sortable';
|
|
|
|
`);
|
|
|
|
|
2022-01-19 23:54:10 +00:00
|
|
|
exports.down = async (knex) => knex.raw(`
|
2021-10-30 20:41:58 +00:00
|
|
|
DROP FUNCTION IF EXISTS entities_scenes;
|
|
|
|
`);
|