2021-02-10 16:20:01 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-02-10 16:20:01 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
use Override;
|
|
|
|
|
2023-06-13 16:05:02 +00:00
|
|
|
class AddCreditsView extends BaseMigration
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-05-06 14:00:48 +00:00
|
|
|
public function up(): void
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
|
|
|
// Creates View for credit UNION query
|
|
|
|
$viewName = $this->db->prefixTable('credits');
|
2021-05-06 14:00:48 +00:00
|
|
|
$personsTable = $this->db->prefixTable('persons');
|
|
|
|
$podcastPersonsTable = $this->db->prefixTable('podcasts_persons');
|
|
|
|
$episodePersonsTable = $this->db->prefixTable('episodes_persons');
|
|
|
|
$episodesTable = $this->db->prefixTable('episodes');
|
2023-08-26 13:03:01 +00:00
|
|
|
$createQuery = <<<SQL
|
2021-05-06 14:00:48 +00:00
|
|
|
CREATE VIEW `{$viewName}` AS
|
|
|
|
SELECT `person_group`, `person_id`, `full_name`, `person_role`, `podcast_id`, NULL AS `episode_id` FROM `{$podcastPersonsTable}`
|
|
|
|
INNER JOIN `{$personsTable}`
|
|
|
|
ON (`person_id`=`{$personsTable}`.`id`)
|
2021-04-02 17:20:02 +00:00
|
|
|
UNION
|
2021-05-06 14:00:48 +00:00
|
|
|
SELECT `person_group`, `person_id`, `full_name`, `person_role`, {$episodePersonsTable}.`podcast_id`, `episode_id` FROM `{$episodePersonsTable}`
|
|
|
|
INNER JOIN `{$personsTable}`
|
|
|
|
ON (`person_id`=`{$personsTable}`.`id`)
|
|
|
|
INNER JOIN `{$episodesTable}`
|
|
|
|
ON (`episode_id`=`{$episodesTable}`.`id`)
|
2022-04-14 14:33:53 +00:00
|
|
|
WHERE `{$episodesTable}`.published_at <= UTC_TIMESTAMP()
|
2021-04-02 17:20:02 +00:00
|
|
|
ORDER BY `person_group`, `full_name`, `person_role`, `podcast_id`, `episode_id`;
|
2023-08-26 13:03:01 +00:00
|
|
|
SQL;
|
2021-02-10 16:20:01 +00:00
|
|
|
$this->db->query($createQuery);
|
|
|
|
}
|
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-05-06 14:00:48 +00:00
|
|
|
public function down(): void
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
|
|
|
$viewName = $this->db->prefixTable('credits');
|
2021-05-06 14:00:48 +00:00
|
|
|
$this->db->query("DROP VIEW IF EXISTS `{$viewName}`");
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
}
|