2021-04-02 17:20:02 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
/**
|
2021-08-27 10:58:22 +00:00
|
|
|
* Class AddEpisodeIdToPosts Adds episode_id field to posts table in database
|
2021-04-02 17:20:02 +00:00
|
|
|
*
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-04-02 17:20:02 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Database\Migrations;
|
|
|
|
|
|
|
|
use CodeIgniter\Database\Migration;
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
class AddEpisodeIdToPosts extends Migration
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
public function up(): void
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$prefix = $this->db->getPrefix();
|
2021-08-27 10:58:22 +00:00
|
|
|
$fediverseTablesPrefix = config('Fediverse')
|
|
|
|
->tablesPrefix;
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2022-07-03 16:42:20 +00:00
|
|
|
$this->forge->addColumn("{$fediverseTablesPrefix}posts", [
|
|
|
|
'episode_id' => [
|
|
|
|
'type' => 'INT',
|
|
|
|
'unsigned' => true,
|
|
|
|
'null' => true,
|
|
|
|
'after' => 'replies_count',
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$alterQuery = <<<CODE_SAMPLE
|
2021-08-27 10:58:22 +00:00
|
|
|
ALTER TABLE {$prefix}{$fediverseTablesPrefix}posts
|
|
|
|
ADD FOREIGN KEY {$prefix}{$fediverseTablesPrefix}posts_episode_id_foreign(episode_id) REFERENCES {$prefix}episodes(id) ON DELETE CASCADE;
|
2021-05-19 16:35:13 +00:00
|
|
|
CODE_SAMPLE;
|
2022-07-03 16:42:20 +00:00
|
|
|
$this->db->query($alterQuery);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function down(): void
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-08-27 10:58:22 +00:00
|
|
|
$fediverseTablesPrefix = config('Fediverse')
|
|
|
|
->tablesPrefix;
|
|
|
|
|
|
|
|
$this->forge->dropForeignKey(
|
|
|
|
$fediverseTablesPrefix . 'posts',
|
|
|
|
$fediverseTablesPrefix . 'posts_episode_id_foreign'
|
|
|
|
);
|
|
|
|
$this->forge->dropColumn($fediverseTablesPrefix . 'posts', 'episode_id');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|