2020-06-12 22:41:09 +02:00
|
|
|
<?php
|
2020-08-04 13:25:22 +02:00
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-06-12 22:41:09 +02:00
|
|
|
/**
|
2021-05-19 18:35:13 +02:00
|
|
|
* Class AddAnalyticsPodcasts Creates analytics_podcasts table in database
|
2021-04-02 19:20:02 +02:00
|
|
|
*
|
2022-02-19 17:06:11 +01:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-06-12 22:41:09 +02:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-08-04 13:25:22 +02:00
|
|
|
|
2021-08-23 13:05:16 +02:00
|
|
|
namespace Modules\Analytics\Database\Migrations;
|
2020-06-12 22:41:09 +02:00
|
|
|
|
2023-06-13 18:05:02 +02:00
|
|
|
use App\Database\Migrations\BaseMigration;
|
2020-06-12 22:41:09 +02:00
|
|
|
|
2023-06-13 18:05:02 +02:00
|
|
|
class AddAnalyticsPodcasts extends BaseMigration
|
2020-06-12 22:41:09 +02:00
|
|
|
{
|
2021-05-06 16:00:48 +02:00
|
|
|
public function up(): void
|
2020-06-12 22:41:09 +02:00
|
|
|
{
|
|
|
|
$this->forge->addField([
|
|
|
|
'podcast_id' => [
|
2023-06-12 16:47:38 +02:00
|
|
|
'type' => 'INT',
|
2020-06-12 22:41:09 +02:00
|
|
|
'unsigned' => true,
|
|
|
|
],
|
|
|
|
'date' => [
|
2020-10-29 16:45:19 +01:00
|
|
|
'type' => 'DATE',
|
2020-06-12 22:41:09 +02:00
|
|
|
],
|
2020-10-29 16:45:19 +01:00
|
|
|
'duration' => [
|
2021-06-11 16:51:14 +02:00
|
|
|
// a hit in analytics podcast increments this value when a podcast is listened to in a given date.
|
|
|
|
// Here, the "cumulative listening time" on a podcast per day
|
|
|
|
// cannot surpass 999,999,999,999.999 seconds (~277,777,777 hours) - should be enough.
|
2023-06-12 16:47:38 +02:00
|
|
|
'type' => 'DECIMAL(15,3)',
|
2020-10-29 16:45:19 +01:00
|
|
|
'unsigned' => true,
|
|
|
|
],
|
|
|
|
'bandwidth' => [
|
2023-06-12 16:47:38 +02:00
|
|
|
'type' => 'BIGINT',
|
2020-10-29 16:45:19 +01:00
|
|
|
'unsigned' => true,
|
2020-06-12 22:41:09 +02:00
|
|
|
],
|
2020-10-08 16:45:46 +02:00
|
|
|
'unique_listeners' => [
|
2023-06-12 16:47:38 +02:00
|
|
|
'type' => 'INT',
|
2020-10-29 16:45:19 +01:00
|
|
|
'unsigned' => true,
|
2023-06-12 16:47:38 +02:00
|
|
|
'default' => 1,
|
2020-10-29 16:45:19 +01:00
|
|
|
],
|
|
|
|
'hits' => [
|
2023-06-12 16:47:38 +02:00
|
|
|
'type' => 'INT',
|
2020-10-29 16:45:19 +01:00
|
|
|
'unsigned' => true,
|
2023-06-12 16:47:38 +02:00
|
|
|
'default' => 1,
|
2020-10-08 16:45:46 +02:00
|
|
|
],
|
2020-06-12 22:41:09 +02:00
|
|
|
]);
|
2020-10-06 17:39:27 +02:00
|
|
|
$this->forge->addPrimaryKey(['podcast_id', 'date']);
|
2021-06-08 11:52:11 +02:00
|
|
|
$this->forge->addField('`created_at` timestamp NOT NULL DEFAULT current_timestamp()');
|
2020-06-12 22:41:09 +02:00
|
|
|
$this->forge->addField(
|
2021-04-02 19:20:02 +02:00
|
|
|
'`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()',
|
2020-06-12 22:41:09 +02:00
|
|
|
);
|
2020-10-06 17:39:27 +02:00
|
|
|
$this->forge->createTable('analytics_podcasts');
|
2020-06-12 22:41:09 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
public function down(): void
|
2020-06-12 22:41:09 +02:00
|
|
|
{
|
2020-10-06 17:39:27 +02:00
|
|
|
$this->forge->dropTable('analytics_podcasts');
|
2020-06-12 22:41:09 +02:00
|
|
|
}
|
|
|
|
}
|