Repository: mozmeao/snippets-service

Issue:
Create db indices for Daily metrics



Discussion:

Resolving patch:
diff --git a/snippets/base/migrations/0027_auto_20191213_1028.py b/snippets/base/migrations/0027_auto_20191213_1028.py
new file mode 100644
--- /dev/null
+++ b/snippets/base/migrations/0027_auto_20191213_1028.py
@@ -0,0 +1,43 @@
+# Generated by Django 2.2.6 on 2019-12-13 10:28
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('base', '0026_auto_20191211_0815'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='dailychannelmetrics',
+            name='channel',
+            field=models.CharField(db_index=True, max_length=255),
+        ),
+        migrations.AlterField(
+            model_name='dailychannelmetrics',
+            name='date',
+            field=models.DateField(db_index=True, editable=False),
+        ),
+        migrations.AlterField(
+            model_name='dailycountrymetrics',
+            name='country',
+            field=models.CharField(db_index=True, max_length=255),
+        ),
+        migrations.AlterField(
+            model_name='dailycountrymetrics',
+            name='date',
+            field=models.DateField(db_index=True, editable=False),
+        ),
+        migrations.AlterField(
+            model_name='dailyjobmetrics',
+            name='date',
+            field=models.DateField(db_index=True, editable=False),
+        ),
+        migrations.AlterField(
+            model_name='dailysnippetmetrics',
+            name='date',
+            field=models.DateField(db_index=True, editable=False),
+        ),
+    ]
diff --git a/snippets/base/models.py b/snippets/base/models.py
--- a/snippets/base/models.py
+++ b/snippets/base/models.py
@@ -2221,7 +2221,7 @@ class DailyJobMetrics(models.Model):
     data_fetched_on = models.DateTimeField(auto_now_add=True)
 
     job = models.ForeignKey(Job, on_delete=models.PROTECT)
-    date = models.DateField(editable=False)
+    date = models.DateField(editable=False, db_index=True)
 
     impressions = models.PositiveIntegerField(default=0, editable=False)
     clicks = models.PositiveIntegerField(default=0, editable=False)
@@ -2239,7 +2239,7 @@ class DailySnippetMetrics(models.Model):
     data_fetched_on = models.DateTimeField(auto_now_add=True)
 
     snippet = models.ForeignKey(ASRSnippet, on_delete=models.PROTECT)
-    date = models.DateField(editable=False)
+    date = models.DateField(editable=False, db_index=True)
 
     impressions = models.PositiveIntegerField(default=0, editable=False)
     clicks = models.PositiveIntegerField(default=0, editable=False)
@@ -2256,8 +2256,8 @@ def __str__(self):
 class DailyChannelMetrics(models.Model):
     data_fetched_on = models.DateTimeField(auto_now_add=True)
 
-    channel = models.CharField(max_length=255)
-    date = models.DateField(editable=False)
+    channel = models.CharField(max_length=255, db_index=True)
+    date = models.DateField(editable=False, db_index=True)
 
     impressions = models.PositiveIntegerField(default=0, editable=False)
     clicks = models.PositiveIntegerField(default=0, editable=False)
@@ -2274,8 +2274,8 @@ def __str__(self):
 class DailyCountryMetrics(models.Model):
     data_fetched_on = models.DateTimeField(auto_now_add=True)
 
-    country = models.CharField(max_length=255)
-    date = models.DateField(editable=False)
+    country = models.CharField(max_length=255, db_index=True)
+    date = models.DateField(editable=False, db_index=True)
 
     impressions = models.PositiveIntegerField(default=0, editable=False)
     clicks = models.PositiveIntegerField(default=0, editable=False)


Test patch: