From bef25f6f5abed2b597fe5358f52eba9b21587c82 Mon Sep 17 00:00:00 2001 From: Adrien Hamraoui Date: Tue, 17 Oct 2023 12:03:57 +0200 Subject: [PATCH] chore: use indexes instead of index_together in models index_together is deprecated and will be removed in django future --- dalec/models.py | 2 +- .../0001_squashed_0005_auto_20231017_1208.py | 172 ++++++++++++++++++ .../0005_auto_20231017_1208 copy.py | 23 +++ 3 files changed, 196 insertions(+), 1 deletion(-) create mode 100644 dalec_prime/migrations/0001_squashed_0005_auto_20231017_1208.py create mode 100644 dalec_prime/migrations/0005_auto_20231017_1208 copy.py diff --git a/dalec/models.py b/dalec/models.py index 02db8dd..7599373 100644 --- a/dalec/models.py +++ b/dalec/models.py @@ -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"])] diff --git a/dalec_prime/migrations/0001_squashed_0005_auto_20231017_1208.py b/dalec_prime/migrations/0001_squashed_0005_auto_20231017_1208.py new file mode 100644 index 0000000..287abcc --- /dev/null +++ b/dalec_prime/migrations/0001_squashed_0005_auto_20231017_1208.py @@ -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, + "indexes": [ + models.Index( + fields=["app", "content_type", "channel", "channel_object"], + name="dalec_prime_app_636e7d_idx", + ) + ], + }, + ), + ] diff --git a/dalec_prime/migrations/0005_auto_20231017_1208 copy.py b/dalec_prime/migrations/0005_auto_20231017_1208 copy.py new file mode 100644 index 0000000..91b6294 --- /dev/null +++ b/dalec_prime/migrations/0005_auto_20231017_1208 copy.py @@ -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", + ), + ), + ]