Skip to content
Snippets Groups Projects
Commit 391c349d authored by Yassine Doghri's avatar Yassine Doghri
Browse files

refactor(database): add / update fields to optimize storage

- harmonize field types and use explicit names
- store html value alongside markdown descriptions for better performance
- add duration and bandwidth to podcast analytics
- add new analytics table for podcast hits by hour
- replace visible MAXMIND_LICENCE_KEY with variable
parent 21da91eb
No related branches found
No related tags found
No related merge requests found
Showing
with 217 additions and 164 deletions
......@@ -59,10 +59,10 @@ $routes->group(config('App')->installGateway, function ($routes) {
]);
});
// Route for podcast audio file analytics (/audio/podcast_id/episode_id/bytes_threshold/filesize/podcast_folder/filename.mp3)
// Route for podcast audio file analytics (/audio/podcast_id/episode_id/bytes_threshold/filesize/duration/podcast_folder/filename.mp3)
$routes->add(
'audio/(:num)/(:num)/(:num)/(:num)/(:any)',
'Analytics::hit/$1/$2/$3/$4/$5',
'audio/(:num)/(:num)/(:num)/(:num)/(:num)/(:any)',
'Analytics::hit/$1/$2/$3/$4/$5/$6',
[
'as' => 'analytics_hit',
]
......
......@@ -112,7 +112,7 @@ class Episode extends BaseController
'slug' => $this->request->getPost('slug'),
'guid' => '',
'enclosure' => $this->request->getFile('enclosure'),
'description' => $this->request->getPost('description'),
'description_markdown' => $this->request->getPost('description'),
'image' => $this->request->getFile('image'),
'parental_advisory' =>
$this->request->getPost('parental_advisory') !== 'undefined'
......@@ -121,7 +121,7 @@ class Episode extends BaseController
'number' => $this->request->getPost('episode_number'),
'season_number' => $this->request->getPost('season_number'),
'type' => $this->request->getPost('type'),
'block' => $this->request->getPost('block') == 'yes',
'is_blocked' => $this->request->getPost('block') == 'yes',
'created_by' => user(),
'updated_by' => user(),
'published_at' => Time::createFromFormat(
......@@ -140,11 +140,11 @@ class Episode extends BaseController
->with('errors', $episodeModel->errors());
}
// update podcast's episode_description_footer if changed
// update podcast's episode_description_footer_markdown if changed
$podcastModel = new PodcastModel();
if ($this->podcast->hasChanged('episode_description_footer')) {
$this->podcast->episode_description_footer = $this->request->getPost(
if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
'description_footer'
);
......@@ -197,7 +197,9 @@ class Episode extends BaseController
$this->episode->title = $this->request->getPost('title');
$this->episode->slug = $this->request->getPost('slug');
$this->episode->description = $this->request->getPost('description');
$this->episode->description_markdown = $this->request->getPost(
'description'
);
$this->episode->parental_advisory =
$this->request->getPost('parental_advisory') !== 'undefined'
? $this->request->getPost('parental_advisory')
......@@ -207,7 +209,7 @@ class Episode extends BaseController
? $this->request->getPost('season_number')
: null;
$this->episode->type = $this->request->getPost('type');
$this->episode->block = $this->request->getPost('block') == 'yes';
$this->episode->is_blocked = $this->request->getPost('block') == 'yes';
$this->episode->published_at = Time::createFromFormat(
'Y-m-d H:i',
$this->request->getPost('publication_date'),
......@@ -233,12 +235,12 @@ class Episode extends BaseController
->with('errors', $episodeModel->errors());
}
// update podcast's episode_description_footer if changed
$this->podcast->episode_description_footer = $this->request->getPost(
// update podcast's episode_description_footer_markdown if changed
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
'description_footer'
);
if ($this->podcast->hasChanged('episode_description_footer')) {
if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
$podcastModel = new PodcastModel();
if (!$podcastModel->update($this->podcast->id, $this->podcast)) {
return redirect()
......
......@@ -95,7 +95,7 @@ class Podcast extends BaseController
$data = ['podcast' => $this->podcast];
replace_breadcrumb_params([0 => $this->podcast->title]);
return view('admin/podcast/analytics/listening-time', $data);
return view('admin/podcast/analytics/listening_time', $data);
}
public function viewAnalyticsPlayers()
......@@ -141,9 +141,9 @@ class Podcast extends BaseController
$podcast = new \App\Entities\Podcast([
'title' => $this->request->getPost('title'),
'name' => $this->request->getPost('name'),
'description' => $this->request->getPost('description'),
'description_markdown' => $this->request->getPost('description'),
'image' => $this->request->getFile('image'),
'language' => $this->request->getPost('language'),
'language_code' => $this->request->getPost('language'),
'category_id' => $this->request->getPost('category'),
'parental_advisory' =>
$this->request->getPost('parental_advisory') !== 'undefined'
......@@ -154,9 +154,9 @@ class Podcast extends BaseController
'publisher' => $this->request->getPost('publisher'),
'type' => $this->request->getPost('type'),
'copyright' => $this->request->getPost('copyright'),
'block' => $this->request->getPost('block') === 'yes',
'complete' => $this->request->getPost('complete') === 'yes',
'lock' => $this->request->getPost('lock') === 'yes',
'is_blocked' => $this->request->getPost('is_blocked') === 'yes',
'is_completed' => $this->request->getPost('complete') === 'yes',
'is_locked' => $this->request->getPost('lock') === 'yes',
'created_by' => user(),
'updated_by' => user(),
]);
......@@ -259,6 +259,10 @@ class Podcast extends BaseController
->with('errors', [lang('PodcastImport.lock_import')]);
}
$converter = new HtmlConverter();
$channelDescriptionHtml = $feed->channel[0]->description;
$podcast = new \App\Entities\Podcast([
'name' => $this->request->getPost('name'),
'imported_feed_url' => $this->request->getPost('imported_feed_url'),
......@@ -266,9 +270,12 @@ class Podcast extends BaseController
route_to('podcast_feed', $this->request->getPost('name'))
),
'title' => $feed->channel[0]->title,
'description' => $feed->channel[0]->description,
'description_markdown' => $converter->convert(
$channelDescriptionHtml
),
'description_html' => $channelDescriptionHtml,
'image' => download_file($nsItunes->image->attributes()),
'language' => $this->request->getPost('language'),
'language_code' => $this->request->getPost('language'),
'category_id' => $this->request->getPost('category'),
'parental_advisory' => empty($nsItunes->explicit)
? null
......@@ -282,10 +289,10 @@ class Podcast extends BaseController
'publisher' => $nsItunes->author,
'type' => empty($nsItunes->type) ? 'episodic' : $nsItunes->type,
'copyright' => $feed->channel[0]->copyright,
'block' => empty($nsItunes->block)
'is_blocked' => empty($nsItunes->block)
? false
: $nsItunes->block === 'yes',
'complete' => empty($nsItunes->complete)
'is_completed' => empty($nsItunes->complete)
? false
: $nsItunes->complete === 'yes',
'created_by' => user(),
......@@ -314,8 +321,6 @@ class Podcast extends BaseController
$podcastAdminGroup->id
);
$converter = new HtmlConverter();
$numberItems = $feed->channel[0]->item->count();
$lastItem =
!empty($this->request->getPost('max_episodes')) &&
......@@ -347,20 +352,24 @@ class Podcast extends BaseController
}
$slugs[] = $slug;
$itemDescriptionHtml =
$this->request->getPost('description_field') === 'summary'
? $nsItunes->summary
: ($this->request->getPost('description_field') ===
'subtitle_summary'
? $nsItunes->subtitle . '<br/>' . $nsItunes->summary
: $item->description);
$newEpisode = new \App\Entities\Episode([
'podcast_id' => $newPodcastId,
'guid' => empty($item->guid) ? null : $item->guid,
'title' => $item->title,
'slug' => $slug,
'enclosure' => download_file($item->enclosure->attributes()),
'description' => $converter->convert(
$this->request->getPost('description_field') === 'summary'
? $nsItunes->summary
: ($this->request->getPost('description_field') ===
'subtitle_summary'
? $nsItunes->subtitle . "\n" . $nsItunes->summary
: $item->description)
'description_markdown' => $converter->convert(
$itemDescriptionHtml
),
'description_html' => $itemDescriptionHtml,
'image' =>
!$nsItunes->image || empty($nsItunes->image->attributes())
? null
......@@ -379,12 +388,14 @@ class Podcast extends BaseController
'season_number' => empty(
$this->request->getPost('season_number')
)
? $nsItunes->season
? (!empty($nsItunes->season)
? $nsItunes->season
: null)
: $this->request->getPost('season_number'),
'type' => empty($nsItunes->episodeType)
? 'full'
: $nsItunes->episodeType,
'block' => empty($nsItunes->block)
'is_blocked' => empty($nsItunes->block)
? false
: $nsItunes->block === 'yes',
'created_by' => user(),
......@@ -441,13 +452,15 @@ class Podcast extends BaseController
$this->podcast->title = $this->request->getPost('title');
$this->podcast->name = $this->request->getPost('name');
$this->podcast->description = $this->request->getPost('description');
$this->podcast->description_markdown = $this->request->getPost(
'description'
);
$image = $this->request->getFile('image');
if ($image->isValid()) {
$this->podcast->image = $image;
}
$this->podcast->language = $this->request->getPost('language');
$this->podcast->language_code = $this->request->getPost('language');
$this->podcast->category_id = $this->request->getPost('category');
$this->podcast->parental_advisory =
$this->request->getPost('parental_advisory') !== 'undefined'
......@@ -458,10 +471,11 @@ class Podcast extends BaseController
$this->podcast->owner_email = $this->request->getPost('owner_email');
$this->podcast->type = $this->request->getPost('type');
$this->podcast->copyright = $this->request->getPost('copyright');
$this->podcast->block = $this->request->getPost('block') === 'yes';
$this->podcast->complete =
$this->podcast->is_blocked =
$this->request->getPost('is_blocked') === 'yes';
$this->podcast->is_completed =
$this->request->getPost('complete') === 'yes';
$this->podcast->lock = $this->request->getPost('lock') === 'yes';
$this->podcast->is_lock = $this->request->getPost('lock') === 'yes';
$this->updated_by = user();
$db = \Config\Database::connect();
......
......@@ -71,14 +71,14 @@ class PodcastSettings extends BaseController
'platform_id' => $platformId,
'podcast_id' => $this->podcast->id,
'link_url' => $platformLinkUrl,
'visible' => array_key_exists('visible', $platformLink)
'is_visible' => array_key_exists('visible', $platformLink)
? $platformLink['visible'] == 'yes'
: false,
]);
}
}
$platformModel->savePlatformLinks(
$platformModel->savePodcastPlatforms(
$this->podcast->id,
$platformLinksData
);
......
......@@ -51,6 +51,7 @@ class Analytics extends Controller
$episodeId,
$bytesThreshold,
$fileSize,
$duration,
...$filename
) {
helper('media');
......@@ -62,6 +63,7 @@ class Analytics extends Controller
$episodeId,
$bytesThreshold,
$fileSize,
$duration,
$serviceName
);
return redirect()->to(media_base_url($filename));
......
......@@ -20,25 +20,23 @@ class AddCategories extends Migration
$this->forge->addField([
'id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
],
'parent_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
],
'code' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 32,
],
'apple_category' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 32,
],
'google_category' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 32,
],
]);
$this->forge->addKey('id', true);
......
......@@ -20,17 +20,12 @@ class AddLanguages extends Migration
$this->forge->addField([
'code' => [
'type' => 'VARCHAR',
'comment' => 'ISO 639-1 language code.',
'comment' => 'ISO 639-1 language code',
'constraint' => 2,
],
'name' => [
'type' => 'VARCHAR',
'comment' => 'English language name.',
'constraint' => 191,
],
'native_name' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 128,
],
]);
$this->forge->addKey('code', true);
......
......@@ -19,34 +19,35 @@ class AddPodcasts extends Migration
{
$this->forge->addField([
'id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 128,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 32,
'unique' => true,
],
'description' => [
'description_markdown' => [
'type' => 'TEXT',
],
'description_html' => [
'type' => 'TEXT',
],
'image_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 255,
],
'language' => [
'language_code' => [
'type' => 'VARCHAR',
'constraint' => 2,
],
'category_id' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 0,
],
......@@ -58,15 +59,15 @@ class AddPodcasts extends Migration
],
'owner_name' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 128,
],
'owner_email' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 255,
],
'publisher' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 128,
'null' => true,
],
'type' => [
......@@ -76,67 +77,69 @@ class AddPodcasts extends Migration
],
'copyright' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 128,
'null' => true,
],
'episode_description_footer_markdown' => [
'type' => 'TEXT',
'null' => true,
],
'episode_description_footer' => [
'episode_description_footer_html' => [
'type' => 'TEXT',
'null' => true,
],
'block' => [
'is_blocked' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'complete' => [
'is_completed' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'lock' => [
'is_locked' => [
'type' => 'TINYINT',
'constraint' => 1,
'comment' =>
'This tells other podcast platforms whether they are allowed to import this feed.',
'default' => 1,
],
'imported_feed_url' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 512,
'comment' =>
'The RSS feed URL if this podcast was imported, NULL otherwise.',
'null' => true,
],
'new_feed_url' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 512,
'comment' =>
'The RSS new feed URL if this podcast is moving out, NULL otherwise.',
'null' => true,
],
'created_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'updated_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'created_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'updated_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'deleted_at' => [
'type' => 'DATETIME',
'null' => true,
],
]);
$this->forge->addKey('id', true);
$this->forge->addForeignKey('category_id', 'categories', 'id');
$this->forge->addForeignKey('language_code', 'languages', 'code');
$this->forge->addForeignKey('created_by', 'users', 'id');
$this->forge->addForeignKey('updated_by', 'users', 'id');
$this->forge->createTable('podcasts');
......
......@@ -19,23 +19,21 @@ class AddEpisodes extends Migration
{
$this->forge->addField([
'id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'guid' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 255,
],
'title' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 128,
],
'slug' => [
'type' => 'VARCHAR',
......@@ -43,11 +41,10 @@ class AddEpisodes extends Migration
],
'enclosure_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 255,
],
'enclosure_duration' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'comment' => 'Playtime in seconds',
],
......@@ -57,23 +54,25 @@ class AddEpisodes extends Migration
],
'enclosure_filesize' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'comment' => 'File size in bytes',
],
'enclosure_headersize' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'comment' => 'Header size in bytes',
],
'description' => [
'description_markdown' => [
'type' => 'TEXT',
'null' => true,
],
'description_html' => [
'type' => 'TEXT',
'null' => true,
],
'image_uri' => [
'type' => 'VARCHAR',
'constraint' => 1024,
'constraint' => 255,
'null' => true,
],
'parental_advisory' => [
......@@ -84,13 +83,11 @@ class AddEpisodes extends Migration
],
'number' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
],
'season_number' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'null' => true,
],
......@@ -99,19 +96,17 @@ class AddEpisodes extends Migration
'constraint' => ['trailer', 'full', 'bonus'],
'default' => 'full',
],
'block' => [
'is_blocked' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'created_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'updated_by' => [
'type' => 'INT',
'constraint' => 11,
'unsigned' => true,
],
'published_at' => [
......@@ -119,10 +114,10 @@ class AddEpisodes extends Migration
'null' => true,
],
'created_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'updated_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'deleted_at' => [
'type' => 'DATETIME',
......
......@@ -19,39 +19,34 @@ class AddPlatforms extends Migration
{
$this->forge->addField([
'id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
'auto_increment' => true,
],
'name' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 32,
'unique' => true,
],
'label' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 32,
],
'home_url' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 255,
],
'submit_url' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 512,
'null' => true,
'default' => null,
],
'icon_filename' => [
'type' => 'VARCHAR',
'constraint' => 1024,
],
'created_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'updated_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
]);
$this->forge->addKey('id', true);
......
......@@ -18,21 +18,28 @@ class AddAnalyticsPodcasts extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'hits' => [
'duration' => [
'type' => 'INT',
'constraint' => 10,
'default' => 1,
'unsigned' => true,
],
'bandwidth' => [
'type' => 'BIGINT',
'unsigned' => true,
],
'unique_listeners' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
'hits' => [
'type' => 'INT',
'unsigned' => true,
'default' => 1,
],
]);
......
......@@ -18,26 +18,24 @@ class AddAnalyticsPodcastsByEpisode extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'episode_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'age' => [
'type' => 'INT',
'constraint' => 10,
'comment' => 'Days since episode publication date',
'unsigned' => true,
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
......
<?php
/**
* Class AddAnalyticsPodcastsByHour
* Creates analytics_podcasts_by_hour table in database
* @copyright 2020 Podlibre
* @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 AddAnalyticsPodcastsByHour extends Migration
{
public function up()
{
$this->forge->addField([
'podcast_id' => [
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'DATE',
],
'hour' => [
'type' => 'INT',
'unsigned' => true,
],
'hits' => [
'type' => 'INT',
'unsigned' => true,
'default' => 1,
],
]);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'hour']);
$this->forge->addField(
'`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
);
$this->forge->addField(
'`updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()'
);
$this->forge->addForeignKey('podcast_id', 'podcasts', 'id');
$this->forge->createTable('analytics_podcasts_by_hour');
}
public function down()
{
$this->forge->dropTable('analytics_podcasts_by_hour');
}
}
......@@ -18,12 +18,11 @@ class AddAnalyticsPodcastsByPlayer extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'service' => [
'type' => 'VARCHAR',
......@@ -41,14 +40,14 @@ class AddAnalyticsPodcastsByPlayer extends Migration
'type' => 'VARCHAR',
'constraint' => 32,
],
'bot' => [
'is_bot' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
......@@ -59,7 +58,7 @@ class AddAnalyticsPodcastsByPlayer extends Migration
'app',
'device',
'os',
'bot',
'is_bot',
]);
$this->forge->addField(
'`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
......
......@@ -18,12 +18,11 @@ class AddAnalyticsPodcastsByCountry extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'country_code' => [
'type' => 'VARCHAR',
......@@ -32,7 +31,7 @@ class AddAnalyticsPodcastsByCountry extends Migration
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
......
......@@ -18,12 +18,11 @@ class AddAnalyticsPodcastsByRegion extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'country_code' => [
'type' => 'VARCHAR',
......@@ -45,7 +44,7 @@ class AddAnalyticsPodcastsByRegion extends Migration
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
......
......@@ -13,37 +13,36 @@ namespace App\Database\Migrations;
use CodeIgniter\Database\Migration;
class AddPlatformLinks extends Migration
class AddPodcastsPlatforms extends Migration
{
public function up()
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'platform_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'link_url' => [
'type' => 'VARCHAR',
'constraint' => 191,
'constraint' => 512,
],
'visible' => [
'is_visible' => [
'type' => 'TINYINT',
'constraint' => 1,
'default' => 0,
],
'created_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
'updated_at' => [
'type' => 'TIMESTAMP',
'type' => 'DATETIME',
],
]);
$this->forge->addPrimaryKey(['podcast_id', 'platform_id']);
$this->forge->addForeignKey('podcast_id', 'podcasts', 'id');
$this->forge->addForeignKey('platform_id', 'platforms', 'id');
......
......@@ -18,12 +18,11 @@ class AddAnalyticsWebsiteByBrowser extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'browser' => [
'type' => 'VARCHAR',
......@@ -32,10 +31,11 @@ class AddAnalyticsWebsiteByBrowser extends Migration
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'browser']);
$this->forge->addField(
'`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
......
......@@ -18,17 +18,15 @@ class AddAnalyticsWebsiteByReferer extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'referer' => [
'referer_url' => [
'type' => 'VARCHAR',
'constraint' => 512,
'comment' => 'Referer URL.',
],
'domain' => [
'type' => 'VARCHAR',
......@@ -37,16 +35,16 @@ class AddAnalyticsWebsiteByReferer extends Migration
],
'keywords' => [
'type' => 'VARCHAR',
'constraint' => 384,
'constraint' => 384, // length of referer_url (512) - domain (128)
'null' => true,
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'referer']);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'referer_url']);
$this->forge->addField(
'`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
);
......
......@@ -18,25 +18,23 @@ class AddAnalyticsWebsiteByEntryPage extends Migration
{
$this->forge->addField([
'podcast_id' => [
'type' => 'BIGINT',
'constraint' => 20,
'type' => 'INT',
'unsigned' => true,
],
'date' => [
'type' => 'date',
'type' => 'DATE',
],
'entry_page' => [
'entry_page_url' => [
'type' => 'VARCHAR',
'constraint' => 512,
'comment' => 'Entry page URL.',
],
'hits' => [
'type' => 'INT',
'constraint' => 10,
'unsigned' => true,
'default' => 1,
],
]);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'entry_page']);
$this->forge->addPrimaryKey(['podcast_id', 'date', 'entry_page_url']);
$this->forge->addField(
'`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment