From 9660aa97c8ffd4fe61f3a388d52b9ac5dd8e1d63 Mon Sep 17 00:00:00 2001
From: Benjamin Bellamy <ben@podlibre.org>
Date: Wed, 7 Oct 2020 13:38:15 +0200
Subject: [PATCH] fix: reorder fields as composite primary keys for analytics
 tables

---
 .../2020-06-08-130000_add_analytics_podcasts_by_episode.php     | 2 +-
 .../2020-06-08-140000_add_analytics_podcasts_by_player.php      | 2 +-
 .../2020-06-08-150000_add_analytics_podcasts_by_country.php     | 2 +-
 .../2020-06-08-160000_add_analytics_podcasts_by_region.php      | 2 +-
 .../2020-06-08-170000_add_analytics_website_by_browser.php      | 2 +-
 .../2020-06-08-180000_add_analytics_website_by_referer.php      | 2 +-
 .../2020-06-08-190000_add_analytics_website_by_entry_page.php   | 2 +-
 7 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/app/Database/Migrations/2020-06-08-130000_add_analytics_podcasts_by_episode.php b/app/Database/Migrations/2020-06-08-130000_add_analytics_podcasts_by_episode.php
index b189ef062b..f26977ac01 100644
--- a/app/Database/Migrations/2020-06-08-130000_add_analytics_podcasts_by_episode.php
+++ b/app/Database/Migrations/2020-06-08-130000_add_analytics_podcasts_by_episode.php
@@ -41,7 +41,7 @@ class AddAnalyticsPodcastsByEpisode extends Migration
                 'default' => 1,
             ],
         ]);
-        $this->forge->addPrimaryKey(['podcast_id', 'episode_id', 'date']);
+        $this->forge->addPrimaryKey(['podcast_id', 'date', 'episode_id']);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
         );
diff --git a/app/Database/Migrations/2020-06-08-140000_add_analytics_podcasts_by_player.php b/app/Database/Migrations/2020-06-08-140000_add_analytics_podcasts_by_player.php
index c1bc04af88..a8f8d32d7d 100644
--- a/app/Database/Migrations/2020-06-08-140000_add_analytics_podcasts_by_player.php
+++ b/app/Database/Migrations/2020-06-08-140000_add_analytics_podcasts_by_player.php
@@ -50,11 +50,11 @@ class AddAnalyticsPodcastsByPlayer extends Migration
         ]);
         $this->forge->addPrimaryKey([
             'podcast_id',
+            'date',
             'app',
             'device',
             'os',
             'bot',
-            'date',
         ]);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
diff --git a/app/Database/Migrations/2020-06-08-150000_add_analytics_podcasts_by_country.php b/app/Database/Migrations/2020-06-08-150000_add_analytics_podcasts_by_country.php
index e5f045e6ef..8133537570 100644
--- a/app/Database/Migrations/2020-06-08-150000_add_analytics_podcasts_by_country.php
+++ b/app/Database/Migrations/2020-06-08-150000_add_analytics_podcasts_by_country.php
@@ -36,7 +36,7 @@ class AddAnalyticsPodcastsByCountry extends Migration
                 'default' => 1,
             ],
         ]);
-        $this->forge->addPrimaryKey(['podcast_id', 'country_code', 'date']);
+        $this->forge->addPrimaryKey(['podcast_id', 'date', 'country_code']);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
         );
diff --git a/app/Database/Migrations/2020-06-08-160000_add_analytics_podcasts_by_region.php b/app/Database/Migrations/2020-06-08-160000_add_analytics_podcasts_by_region.php
index 7b787878de..fa317996d5 100644
--- a/app/Database/Migrations/2020-06-08-160000_add_analytics_podcasts_by_region.php
+++ b/app/Database/Migrations/2020-06-08-160000_add_analytics_podcasts_by_region.php
@@ -51,9 +51,9 @@ class AddAnalyticsPodcastsByRegion extends Migration
         ]);
         $this->forge->addPrimaryKey([
             'podcast_id',
+            'date',
             'country_code',
             'region_code',
-            'date',
         ]);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
diff --git a/app/Database/Migrations/2020-06-08-170000_add_analytics_website_by_browser.php b/app/Database/Migrations/2020-06-08-170000_add_analytics_website_by_browser.php
index 21724af709..a99ebf1985 100644
--- a/app/Database/Migrations/2020-06-08-170000_add_analytics_website_by_browser.php
+++ b/app/Database/Migrations/2020-06-08-170000_add_analytics_website_by_browser.php
@@ -36,7 +36,7 @@ class AddAnalyticsWebsiteByBrowser extends Migration
                 'default' => 1,
             ],
         ]);
-        $this->forge->addPrimaryKey(['podcast_id', 'browser', 'date']);
+        $this->forge->addPrimaryKey(['podcast_id', 'date', 'browser']);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
         );
diff --git a/app/Database/Migrations/2020-06-08-180000_add_analytics_website_by_referer.php b/app/Database/Migrations/2020-06-08-180000_add_analytics_website_by_referer.php
index 579024b02b..4addc2e25c 100644
--- a/app/Database/Migrations/2020-06-08-180000_add_analytics_website_by_referer.php
+++ b/app/Database/Migrations/2020-06-08-180000_add_analytics_website_by_referer.php
@@ -46,7 +46,7 @@ class AddAnalyticsWebsiteByReferer extends Migration
                 'default' => 1,
             ],
         ]);
-        $this->forge->addPrimaryKey(['podcast_id', 'referer', 'date']);
+        $this->forge->addPrimaryKey(['podcast_id', 'date', 'referer']);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
         );
diff --git a/app/Database/Migrations/2020-06-08-190000_add_analytics_website_by_entry_page.php b/app/Database/Migrations/2020-06-08-190000_add_analytics_website_by_entry_page.php
index 19bce6de19..426783c290 100644
--- a/app/Database/Migrations/2020-06-08-190000_add_analytics_website_by_entry_page.php
+++ b/app/Database/Migrations/2020-06-08-190000_add_analytics_website_by_entry_page.php
@@ -36,7 +36,7 @@ class AddAnalyticsWebsiteByEntryPage extends Migration
                 'default' => 1,
             ],
         ]);
-        $this->forge->addPrimaryKey(['podcast_id', 'entry_page', 'date']);
+        $this->forge->addPrimaryKey(['podcast_id', 'date', 'entry_page']);
         $this->forge->addField(
             '`created_at` timestamp NOT NULL DEFAULT current_timestamp()'
         );
-- 
GitLab