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 AddCreatedByToPosts Adds created_by 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;
|
|
|
|
|
2023-06-13 16:05:02 +00:00
|
|
|
class AddCreatedByToPosts extends BaseMigration
|
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();
|
|
|
|
|
2023-08-26 13:03:01 +00:00
|
|
|
$this->forge->addColumn('fediverse_posts', [
|
2022-07-03 16:42:20 +00:00
|
|
|
'created_by' => [
|
2023-06-12 14:47:38 +00:00
|
|
|
'type' => 'INT',
|
2022-07-03 16:42:20 +00:00
|
|
|
'unsigned' => true,
|
2023-06-12 14:47:38 +00:00
|
|
|
'null' => true,
|
|
|
|
'after' => 'episode_id',
|
2022-07-03 16:42:20 +00:00
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
2023-08-26 13:03:01 +00:00
|
|
|
$this->forge->addForeignKey(
|
|
|
|
'created_by',
|
|
|
|
'users',
|
|
|
|
'id',
|
|
|
|
'',
|
|
|
|
'CASCADE',
|
|
|
|
$prefix . 'fediverse_posts_created_by_foreign'
|
|
|
|
);
|
|
|
|
$this->forge->processIndexes('fediverse_posts');
|
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
|
|
|
{
|
2023-08-26 13:03:01 +00:00
|
|
|
$prefix = $this->db->getPrefix();
|
2021-08-27 10:58:22 +00:00
|
|
|
|
2023-08-26 13:03:01 +00:00
|
|
|
$this->forge->dropForeignKey('fediverse_posts', $prefix . 'fediverse_posts_created_by_foreign');
|
|
|
|
$this->forge->dropColumn('fediverse_posts', 'created_by');
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
}
|