# 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');"),
    ]
