mirror of
https://github.com/daniviga/bite.git
synced 2025-04-20 14:31:20 +02:00
Fix a regression in the hyperscale creation
This commit is contained in:
parent
5cff8b9c2c
commit
f4d1387f32
@ -1,4 +1,4 @@
|
||||
# Generated by Django 3.1.3 on 2021-03-19 08:08
|
||||
# Generated by Django 3.1.7 on 2021-03-25 10:55
|
||||
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
@ -18,7 +18,7 @@ class Migration(migrations.Migration):
|
||||
migrations.CreateModel(
|
||||
name='Telemetry',
|
||||
fields=[
|
||||
('id', models.AutoField(primary_key=True, serialize=False)),
|
||||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('time', models.DateTimeField(auto_now_add=True, db_index=True)),
|
||||
('transport', models.CharField(choices=[('http', 'http'), ('mqtt', 'mqtt')], default='http', max_length=4)),
|
||||
('clock', models.IntegerField(null=True, validators=[django.core.validators.MinValueValidator(0)])),
|
||||
@ -28,6 +28,7 @@ class Migration(migrations.Migration):
|
||||
options={
|
||||
'verbose_name_plural': 'Telemetry',
|
||||
'ordering': ['-time', 'device'],
|
||||
'unique_together': {('time', 'device')},
|
||||
},
|
||||
),
|
||||
]
|
||||
|
24
bite/telemetry/migrations/0002_timescale.py
Normal file
24
bite/telemetry/migrations/0002_timescale.py
Normal file
@ -0,0 +1,24 @@
|
||||
# Generated by Django 3.1.7 on 2021-03-25 10:55
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('telemetry', '0001_initial'),
|
||||
]
|
||||
|
||||
# Timescale requires an hyperscale table to have the field used for the
|
||||
# partitioning ('time') to be in the any UNIQUE constraint.
|
||||
# Because of that we have a unique_together on 'time' and 'device_id',
|
||||
# however Django always adds an 'id' as PRIMARY_KEY.
|
||||
# Django's 'id' isn't used as a foreign key, so we are dropping
|
||||
# the contraint and simply adding an index to the 'id' columns.
|
||||
# We can now create the hypertable.
|
||||
operations = [
|
||||
migrations.RunSQL(
|
||||
"ALTER TABLE telemetry_telemetry DROP CONSTRAINT telemetry_telemetry_pkey ;" # noqa: E501
|
||||
"CREATE INDEX telemetry_telemetry_id_idx ON telemetry_telemetry(id);" # noqa: E501
|
||||
"SELECT create_hypertable('telemetry_telemetry', 'time');"),
|
||||
]
|
@ -30,7 +30,6 @@ def telemetry_validation(value):
|
||||
|
||||
|
||||
class Telemetry(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
device = models.ForeignKey(Device, on_delete=models.CASCADE)
|
||||
time = models.DateTimeField(db_index=True, auto_now_add=True)
|
||||
transport = models.CharField(max_length=4,
|
||||
@ -43,6 +42,7 @@ class Telemetry(models.Model):
|
||||
|
||||
class Meta:
|
||||
ordering = ['-time', 'device']
|
||||
unique_together = ['time', 'device']
|
||||
verbose_name_plural = "Telemetry"
|
||||
|
||||
def __str__(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user