traxxx/migrations/20230104014437_release_show...

23 lines
918 B
JavaScript
Raw Normal View History

2023-01-14 22:44:32 +00:00
const config = require('config');
2023-01-14 22:44:32 +00:00
exports.up = async (knex) => knex.raw(`
2023-01-16 20:32:22 +00:00
CREATE VIEW releases_not_showcased AS (
2023-01-14 22:44:32 +00:00
SELECT releases.id AS release_id FROM releases
2023-06-17 21:31:09 +00:00
LEFT JOIN entities AS channels ON channels.id = releases.entity_id
2023-01-14 22:44:32 +00:00
LEFT JOIN entities AS studios ON studios.id = releases.studio_id
2023-06-17 21:31:09 +00:00
LEFT JOIN entities AS networks ON networks .id = entities.parent_id
WHERE (studios.showcased = false)
OR (channel.showcased = false AND studios.showcased IS NOT true)
OR (network.showcased = false AND channel.showcased IS NOT true AND studios.showcased IS NOT true)
2023-01-14 22:44:32 +00:00
);
2023-01-16 20:32:22 +00:00
COMMENT ON VIEW releases_not_showcased IS E'@foreignKey (release_id) references releases (id)';
GRANT SELECT ON releases_not_showcased TO :visitor;
2023-01-14 22:44:32 +00:00
`, {
visitor: knex.raw(config.database.query.user),
});
exports.down = async (knex) => knex.raw(`
2023-01-16 20:32:22 +00:00
DROP VIEW IF EXISTS releases_not_showcased;
2023-01-14 22:44:32 +00:00
`);