mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-08-31 16:07:19 +02:00
48 lines
1.8 KiB
PHP
48 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* @copyright 2020 Ad Aures
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
* @link https://castopod.org/
|
|
*/
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
class AddCreditsView extends Migration
|
|
{
|
|
public function up(): void
|
|
{
|
|
// Creates View for credit UNION query
|
|
$viewName = $this->db->prefixTable('credits');
|
|
$personsTable = $this->db->prefixTable('persons');
|
|
$podcastPersonsTable = $this->db->prefixTable('podcasts_persons');
|
|
$episodePersonsTable = $this->db->prefixTable('episodes_persons');
|
|
$episodesTable = $this->db->prefixTable('episodes');
|
|
$createQuery = <<<CODE_SAMPLE
|
|
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`)
|
|
UNION
|
|
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`)
|
|
WHERE `{$episodesTable}`.published_at <= UTC_TIMESTAMP()
|
|
ORDER BY `person_group`, `full_name`, `person_role`, `podcast_id`, `episode_id`;
|
|
CODE_SAMPLE;
|
|
$this->db->query($createQuery);
|
|
}
|
|
|
|
public function down(): void
|
|
{
|
|
$viewName = $this->db->prefixTable('credits');
|
|
$this->db->query("DROP VIEW IF EXISTS `{$viewName}`");
|
|
}
|
|
}
|