Update models and reset migrations

This commit is contained in:
arjunsalyan
2020-05-23 13:06:10 +05:30
committed by Arjun Salyan
parent cc6c4c3e84
commit 7cac896052
13 changed files with 135 additions and 47 deletions
+21 -11
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
from django.db import migrations, models
import django.db.models.deletion
@@ -16,9 +16,14 @@ class Migration(migrations.Migration):
name='Builder',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(db_index=True, max_length=100)),
('display_name', models.CharField(db_index=True, default='', max_length=20)),
('name', models.CharField(db_index=True, max_length=100, verbose_name='Name of the builder as per Buildbot')),
('display_name', models.CharField(db_index=True, default='', max_length=20, verbose_name='Simplified builder name: 10.XX')),
],
options={
'verbose_name': 'Builder',
'verbose_name_plural': 'Builders',
'db_table': 'builder',
},
),
migrations.CreateModel(
name='BuildHistory',
@@ -32,37 +37,42 @@ class Migration(migrations.Migration):
('watcher_id', models.IntegerField()),
('builder_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='build.Builder')),
],
options={
'verbose_name': 'Build',
'verbose_name_plural': 'Builds',
'db_table': 'builds',
},
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['port_name', 'builder_name', '-build_id'], name='build_build_port_na_ddceed_idx'),
index=models.Index(fields=['port_name', 'builder_name', '-build_id'], name='builds_port_na_690929_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['port_name', 'builder_name', '-time_start'], name='build_build_port_na_946269_idx'),
index=models.Index(fields=['port_name', 'builder_name', '-time_start'], name='builds_port_na_a30f18_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['port_name', 'status', 'builder_name'], name='build_build_port_na_c283d2_idx'),
index=models.Index(fields=['port_name', 'status', 'builder_name'], name='builds_port_na_a1a05a_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['port_name', 'builder_name'], name='build_build_port_na_352e8d_idx'),
index=models.Index(fields=['port_name', 'builder_name'], name='builds_port_na_9b04f4_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['-time_start'], name='build_build_time_st_abd20f_idx'),
index=models.Index(fields=['-time_start'], name='builds_time_st_741e8b_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['port_name'], name='build_build_port_na_e9da42_idx'),
index=models.Index(fields=['port_name'], name='builds_port_na_f9cad8_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['status'], name='build_build_status_6cbfec_idx'),
index=models.Index(fields=['status'], name='builds_status_e27daf_idx'),
),
migrations.AddIndex(
model_name='buildhistory',
index=models.Index(fields=['builder_name'], name='build_build_builder_833711_idx'),
index=models.Index(fields=['builder_name'], name='builds_builder_5931b0_idx'),
),
]
+10 -2
View File
@@ -9,8 +9,13 @@ from config import BUILDERS_JSON_URL, BUILDBOT_URL_PREFIX, BUILDS_FETCHED_COUNT
class Builder(models.Model):
name = models.CharField(max_length=100, db_index=True)
display_name = models.CharField(max_length=20, db_index=True, default='')
name = models.CharField(max_length=100, db_index=True, verbose_name="Name of the builder as per Buildbot")
display_name = models.CharField(max_length=20, db_index=True, default='', verbose_name="Simplified builder name: 10.XX")
class Meta:
db_table = "builder"
verbose_name = "Builder"
verbose_name_plural = "Builders"
class BuildHistory(models.Model):
@@ -23,6 +28,9 @@ class BuildHistory(models.Model):
watcher_id = models.IntegerField()
class Meta:
db_table = "builds"
verbose_name = "Build"
verbose_name_plural = "Builds"
indexes = [
models.Index(fields=['port_name', 'builder_name', '-build_id']),
models.Index(fields=['port_name', 'builder_name', '-time_start']),
+7 -2
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
from django.db import migrations, models
@@ -14,7 +14,12 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='Category',
fields=[
('name', models.TextField(primary_key=True, serialize=False)),
('name', models.TextField(primary_key=True, serialize=False, verbose_name='Name of the category')),
],
options={
'verbose_name': 'Category',
'verbose_name_plural': 'categories',
'db_table': 'category',
},
),
]
+6 -1
View File
@@ -2,4 +2,9 @@ from django.db import models
class Category(models.Model):
name = models.TextField(primary_key=True)
name = models.TextField(primary_key=True, verbose_name="Name of the category")
class Meta:
db_table = "category"
verbose_name = "Category"
verbose_name_plural = "categories"
+8 -3
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
from django.db import migrations, models
@@ -21,14 +21,19 @@ class Migration(migrations.Migration):
('github', models.CharField(default='', max_length=50)),
('ports', models.ManyToManyField(related_name='maintainers', to='port.Port')),
],
options={
'verbose_name': 'Maintainer',
'verbose_name_plural': 'Maintainers',
'db_table': 'maintainer',
},
),
migrations.AddIndex(
model_name='maintainer',
index=models.Index(fields=['github'], name='maintainer__github_a6ca13_idx'),
index=models.Index(fields=['github'], name='maintainer_github_cc300f_idx'),
),
migrations.AddIndex(
model_name='maintainer',
index=models.Index(fields=['name', 'domain'], name='maintainer__name_df4550_idx'),
index=models.Index(fields=['name', 'domain'], name='maintainer_name_106ce4_idx'),
),
migrations.AlterUniqueTogether(
name='maintainer',
+3 -1
View File
@@ -8,8 +8,10 @@ class Maintainer(models.Model):
ports = models.ManyToManyField('port.Port', related_name='maintainers')
class Meta:
db_table = "maintainer"
verbose_name = "Maintainer"
verbose_name_plural = "Maintainers"
unique_together = [['name', 'domain', 'github']]
indexes = [
models.Index(fields=['github']),
models.Index(fields=['name', 'domain'])
+20 -5
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
from django.db import migrations, models
import django.db.models.deletion
@@ -17,9 +17,14 @@ class Migration(migrations.Migration):
name='LastPortIndexUpdate',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('git_commit_hash', models.CharField(max_length=50)),
('updated_at', models.DateTimeField(auto_now=True)),
('git_commit_hash', models.CharField(max_length=50, verbose_name='Commit hash till which update was done')),
('updated_at', models.DateTimeField(auto_now=True, verbose_name='Timestamp when update completed')),
],
options={
'verbose_name': 'PortIndex Update',
'verbose_name_plural': 'PortIndex Updates',
'db_table': 'portindex_update',
},
),
migrations.CreateModel(
name='Port',
@@ -38,8 +43,13 @@ class Migration(migrations.Migration):
('license', models.CharField(default='', max_length=100)),
('replaced_by', models.CharField(max_length=100, null=True)),
('active', models.BooleanField(default=True)),
('categories', models.ManyToManyField(db_index=True, related_name='category', to='category.Category')),
('categories', models.ManyToManyField(db_index=True, related_name='ports', to='category.Category')),
],
options={
'verbose_name': 'Port',
'verbose_name_plural': 'Ports',
'db_table': 'port',
},
),
migrations.CreateModel(
name='Dependency',
@@ -49,10 +59,15 @@ class Migration(migrations.Migration):
('dependencies', models.ManyToManyField(to='port.Port')),
('port_name', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='dependent_port', to='port.Port')),
],
options={
'verbose_name': 'Dependency',
'verbose_name_plural': 'Dependencies',
'db_table': 'dependency',
},
),
migrations.AddIndex(
model_name='dependency',
index=models.Index(fields=['port_name'], name='port_depend_port_na_c730e7_idx'),
index=models.Index(fields=['port_name'], name='dependency_port_na_a6e0f8_idx'),
),
migrations.AlterUniqueTogether(
name='dependency',
+16 -4
View File
@@ -22,7 +22,7 @@ class Port(models.Model):
homepage = models.URLField(default='')
epoch = models.BigIntegerField(default=0)
platforms = models.TextField(null=True)
categories = models.ManyToManyField('category.Category', related_name='category', db_index=True)
categories = models.ManyToManyField('category.Category', related_name='ports', db_index=True)
long_description = models.TextField(default='')
version = models.CharField(max_length=100, default='')
revision = models.IntegerField(default=0)
@@ -35,6 +35,11 @@ class Port(models.Model):
objects = PortManager()
get_active = ActivePortsManager()
class Meta:
db_table = "port"
verbose_name = "Port"
verbose_name_plural = "Ports"
@classmethod
def load(cls, data):
def open_portindex_json(path):
@@ -310,16 +315,23 @@ class Dependency(models.Model):
type = models.CharField(max_length=100)
class Meta:
db_table = "dependency"
verbose_name = "Dependency"
verbose_name_plural = "Dependencies"
unique_together = [['port_name', 'type']]
indexes = [
models.Index(fields=['port_name'])
]
class LastPortIndexUpdate(models.Model):
git_commit_hash = models.CharField(max_length=50)
updated_at = models.DateTimeField(auto_now=True)
git_commit_hash = models.CharField(max_length=50, verbose_name="Commit hash till which update was done")
updated_at = models.DateTimeField(auto_now=True, verbose_name="Timestamp when update completed")
class Meta:
db_table = "portindex_update"
verbose_name = "PortIndex Update"
verbose_name_plural = "PortIndex Updates"
@classmethod
def update_or_create_first_object(cls, commit_hash):
+26 -16
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
import django.contrib.postgres.fields.jsonb
from django.db import migrations, models
@@ -36,6 +36,11 @@ class Migration(migrations.Migration):
('timestamp', models.DateTimeField()),
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stats.UUID')),
],
options={
'verbose_name': 'Statistics Submission',
'verbose_name_plural': 'Statistics Submissions',
'db_table': 'submission',
},
),
migrations.CreateModel(
name='PortInstallation',
@@ -47,65 +52,70 @@ class Migration(migrations.Migration):
('requested', models.BooleanField(default=False)),
('submission', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='stats.Submission')),
],
options={
'verbose_name': 'Installed Port',
'verbose_name_plural': 'Installed Ports',
'db_table': 'installed_ports',
},
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['timestamp'], name='stats_submi_timesta_cdcb72_idx'),
index=models.Index(fields=['timestamp'], name='submission_timesta_0ed555_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['user'], name='stats_submi_user_id_fb754f_idx'),
index=models.Index(fields=['user'], name='submission_user_id_dd4875_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['user', '-timestamp'], name='stats_submi_user_id_10b8e5_idx'),
index=models.Index(fields=['user', '-timestamp'], name='submission_user_id_fa4b00_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['user', 'timestamp'], name='stats_submi_user_id_a349e8_idx'),
index=models.Index(fields=['user', 'timestamp'], name='submission_user_id_f4b6a3_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['os_version'], name='stats_submi_os_vers_f793f1_idx'),
index=models.Index(fields=['os_version'], name='submission_os_vers_5fb150_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['os_version', 'os_arch'], name='stats_submi_os_vers_0cb582_idx'),
index=models.Index(fields=['os_version', 'os_arch'], name='submission_os_vers_1bb250_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['os_version', 'xcode_version'], name='stats_submi_os_vers_5997ef_idx'),
index=models.Index(fields=['os_version', 'xcode_version'], name='submission_os_vers_a02781_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['os_arch'], name='stats_submi_os_arch_088fdd_idx'),
index=models.Index(fields=['os_arch'], name='submission_os_arch_ebd5c3_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['macports_version'], name='stats_submi_macport_1bd1cf_idx'),
index=models.Index(fields=['macports_version'], name='submission_macport_071a1f_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['cxx_stdlib'], name='stats_submi_cxx_std_267d24_idx'),
index=models.Index(fields=['cxx_stdlib'], name='submission_cxx_std_de2798_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['build_arch'], name='stats_submi_build_a_8093ff_idx'),
index=models.Index(fields=['build_arch'], name='submission_build_a_40018f_idx'),
),
migrations.AddIndex(
model_name='submission',
index=models.Index(fields=['clt_version'], name='stats_submi_clt_ver_1a1b8d_idx'),
index=models.Index(fields=['clt_version'], name='submission_clt_ver_5a7a78_idx'),
),
migrations.AddIndex(
model_name='portinstallation',
index=models.Index(fields=['submission'], name='stats_porti_submiss_d2ed90_idx'),
index=models.Index(fields=['submission'], name='installed_p_submiss_b00f1e_idx'),
),
migrations.AddIndex(
model_name='portinstallation',
index=models.Index(fields=['port'], name='stats_porti_port_7817b7_idx'),
index=models.Index(fields=['port'], name='installed_p_port_97f418_idx'),
),
migrations.AddIndex(
model_name='portinstallation',
index=models.Index(fields=['variants'], name='stats_porti_variant_fec07e_idx'),
index=models.Index(fields=['variants'], name='installed_p_variant_789a6f_idx'),
),
]
+6
View File
@@ -22,6 +22,9 @@ class Submission(models.Model):
timestamp = models.DateTimeField()
class Meta:
db_table = "submission"
verbose_name = "Statistics Submission"
verbose_name_plural = "Statistics Submissions"
indexes = [
models.Index(fields=['timestamp']),
models.Index(fields=['user']),
@@ -69,6 +72,9 @@ class PortInstallation(models.Model):
requested = models.BooleanField(default=False)
class Meta:
db_table = "installed_ports"
verbose_name = "Installed Port"
verbose_name_plural = "Installed Ports"
indexes = [
models.Index(fields=['submission']),
models.Index(fields=['port']),
+6 -1
View File
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-04-23 18:06
# Generated by Django 2.2.10 on 2020-04-23 18:49
from django.db import migrations, models
import django.db.models.deletion
@@ -20,5 +20,10 @@ class Migration(migrations.Migration):
('variant', models.CharField(default='', max_length=100)),
('port', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ports', to='port.Port')),
],
options={
'verbose_name': 'Variant',
'verbose_name_plural': 'Variants',
'db_table': 'variant',
},
),
]
+5
View File
@@ -4,3 +4,8 @@ from django.db import models
class Variant(models.Model):
port = models.ForeignKey('port.Port', on_delete=models.CASCADE, related_name='ports')
variant = models.CharField(max_length=100, default='')
class Meta:
db_table = "variant"
verbose_name = "Variant"
verbose_name_plural = "Variants"
+1 -1
View File
@@ -10,7 +10,7 @@ from port.filters import PortFilterByMultiple
def index(request):
categories = Category.objects.all().order_by('name').annotate(ports_count=Count('category', filter=Q(category__active=True)))
categories = Category.objects.all().order_by('name').annotate(ports_count=Count('ports', filter=Q(ports__active=True)))
submissions_unique = Submission.objects.filter(timestamp__gte=datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(days=30)).order_by('user', '-timestamp').distinct('user')
top_ports = PortInstallation.objects.filter(submission_id__in=Subquery(submissions_unique.values('id')), requested=True).exclude(port__icontains='mpstats').values('port').annotate(num=Count('port')).order_by('-num')[:10]