Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Kipchirchir Sigei <[email protected]>
  • Loading branch information
KipSigei committed Aug 6, 2023
1 parent d8d1feb commit fa6f2de
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 50 deletions.
54 changes: 54 additions & 0 deletions onadata/apps/logger/migrations/0005_add_date_fields_indexing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Generated by Django 3.2.18 on 2023-03-14 12:22

from django.db import migrations, models


class Migration(migrations.Migration):
atomic = False

dependencies = [
('logger', '0004_update_instance_geoms'),
]

operations = [
migrations.SeparateDatabaseAndState(
database_operations=[
migrations.RunSQL(
sql='CREATE INDEX CONCURRENTLY "logger_inst_date_cr_42899d_idx" ON "logger_instance" ("date_created");',
reverse_sql='DROP INDEX "logger_inst_date_cr_42899d_idx";',
),
migrations.RunSQL(
sql='CREATE INDEX CONCURRENTLY "logger_inst_date_mo_5a1bd3_idx" ON "logger_instance" ("date_modified");',
reverse_sql='DROP INDEX "logger_inst_date_mo_5a1bd3_idx";',
),
migrations.RunSQL(
sql='CREATE INDEX CONCURRENTLY "logger_inst_deleted_da31a3_idx" ON "logger_instance" ("deleted_at");',
reverse_sql='DROP INDEX "logger_inst_deleted_da31a3_idx";',
),
],
state_operations=[
migrations.AddIndex(
model_name="instance",
index=models.Index(
fields=["date_created"], name="logger_inst_date_cr_42899d_idx"
),
),
migrations.AddIndex(
model_name="instance",
index=models.Index(
fields=["date_modified"], name="logger_inst_date_mo_5a1bd3_idx"
),
),
migrations.AddIndex(
model_name="instance",
index=models.Index(
fields=["deleted_at"], name="logger_inst_deleted_da31a3_idx"
),
),
],
)
]




48 changes: 0 additions & 48 deletions onadata/apps/logger/migrations/0005_auto_20230308_0252.py

This file was deleted.

9 changes: 7 additions & 2 deletions onadata/apps/logger/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ class Instance(models.Model, InstanceBaseClass):
survey_type = models.ForeignKey("logger.SurveyType", on_delete=models.PROTECT)

# shows when we first received this instance
date_created = models.DateTimeField(auto_now_add=True, db_index=True)
date_created = models.DateTimeField(auto_now_add=True)

# this will end up representing "date last parsed"
date_modified = models.DateTimeField(auto_now=True, db_index=True)
date_modified = models.DateTimeField(auto_now=True)

# this will end up representing "date instance was deleted"
deleted_at = models.DateTimeField(null=True, default=None)
Expand Down Expand Up @@ -697,6 +697,11 @@ class Instance(models.Model, InstanceBaseClass):
class Meta:
app_label = "logger"
unique_together = ("xform", "uuid")
indexes = [
models.Index(fields=['date_created']),
models.Index(fields=['date_modified']),
models.Index(fields=['deleted_at']),
]

@classmethod
def set_deleted_at(cls, instance_id, deleted_at=timezone.now(), user=None):
Expand Down

0 comments on commit fa6f2de

Please sign in to comment.