Skip to content

Commit

Permalink
chore: use indexes instead of index_together in models
Browse files Browse the repository at this point in the history
index_together is deprecated and will be removed in django future
  • Loading branch information
hamadr committed Oct 17, 2023
1 parent 2eb70f7 commit 2715925
Show file tree
Hide file tree
Showing 3 changed files with 196 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dalec/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,4 @@ class Meta:
ordering = ("-last_update_dt",)
get_latest_by = "last_update_dt"
abstract = True
index_together = (("app", "content_type", "channel", "channel_object"),)
indexes = [models.Index(fields=["app", "content_type", "channel", "channel_object"])]
172 changes: 172 additions & 0 deletions dalec_prime/migrations/0001_squashed_0005_auto_20231017_1208.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
# Generated by Django 4.2.5 on 2023-10-17 10:26

import django.core.serializers.json
from django.db import migrations, models
import django.db.models.deletion

try:
# Django imports
from django.db.models import JSONField # type: ignore
except ImportError:
from django_jsonfield_backport.models import JSONField # type: ignore


class Migration(migrations.Migration):
replaces = [
("dalec_prime", "0001_initial"),
("dalec_prime", "0002_auto_20211109_1546"),
("dalec_prime", "0003_auto_20211109_1615"),
("dalec_prime", "0004_alter_content_id_alter_fetchhistory_id"),
("dalec_prime", "0005_auto_20231017_1208"),
]

initial = True

dependencies = [
("contenttypes", "0002_remove_content_type_name"),
]

operations = [
migrations.CreateModel(
name="FetchHistory",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
"last_fetch_dt",
models.DateTimeField(auto_now=True, verbose_name="last fetch datetime"),
),
("app", models.CharField(max_length=50, verbose_name="dalec app")),
(
"content_type",
models.CharField(
blank=True, max_length=50, null=True, verbose_name="content type"
),
),
(
"channel",
models.CharField(blank=True, max_length=50, null=True, verbose_name="channel"),
),
(
"channel_object",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="channel app object id"
),
),
],
options={
"verbose_name": "Content fetch history line",
"verbose_name_plural": "Content fetch history lines",
"ordering": ("-last_fetch_dt",),
"get_latest_by": "last_fetch_dt",
"abstract": False,
},
),
migrations.CreateModel(
name="Content",
fields=[
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
(
"last_update_dt",
models.DateTimeField(
db_index=True, verbose_name="last update datetime (on external source)"
),
),
(
"creation_dt",
models.DateTimeField(
db_index=True, verbose_name="created datetime (on external source)"
),
),
("app", models.CharField(max_length=50, verbose_name="dalec app")),
(
"content_type",
models.CharField(
blank=True, max_length=50, null=True, verbose_name="content type"
),
),
(
"channel",
models.CharField(blank=True, max_length=50, null=True, verbose_name="channel"),
),
(
"channel_object",
models.CharField(
blank=True, max_length=255, null=True, verbose_name="channel app object id"
),
),
(
"dj_channel_id",
models.PositiveIntegerField(
blank=True,
help_text="The django's model's instance which is concerned.(eg. could be an instance of model `Project` for app=gitlab, content_type=issue, channel=project)",
null=True,
verbose_name="related object",
),
),
(
"dj_content_id",
models.PositiveIntegerField(
blank=True,
help_text="The django's model's instance which is concerned (eg. could be an instance of model `Issue` for dalec-gitlab)",
null=True,
verbose_name="content",
),
),
(
"content_id",
models.CharField(
help_text="ID of the content inside the external app.",
max_length=255,
verbose_name="app's content id",
),
),
(
"content_data",
JSONField(encoder=django.core.serializers.json.DjangoJSONEncoder),
),
(
"dj_channel_content_type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="contenttypes.contenttype",
),
),
(
"dj_content_content_type",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="+",
to="contenttypes.contenttype",
),
),
],
options={
"verbose_name": "Content",
"verbose_name_plural": "Contents",
"ordering": ("-last_update_dt",),
"get_latest_by": "last_update_dt",
"abstract": False,
"index_together": set(),
"indexes": [
models.Index(
fields=["app", "content_type", "channel", "channel_object"], name="content"
)
],
},
),
]
23 changes: 23 additions & 0 deletions dalec_prime/migrations/0005_auto_20231017_1208 copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Generated by Django 3.2.21 on 2023-10-17 10:08

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("dalec_prime", "0004_alter_content_id_alter_fetchhistory_id"),
]

operations = [
migrations.AlterIndexTogether(
name="content",
index_together=set(),
),
migrations.AddIndex(
model_name="content",
index=models.Index(
fields=["app", "content_type", "channel", "channel_object"],
name="dalec_prime_app_636e7d_idx",
),
),
]

0 comments on commit 2715925

Please sign in to comment.