Skip to content

Commit

Permalink
feat(orpd-217): add source date fields for tracking raw date inputs
Browse files Browse the repository at this point in the history
Introduce `source_date_issued`, `source_date_modified`, and `source_date_valid` fields to retain unnormalized date inputs in cache and database models. This ensures raw date values are preserved alongside normalized versions for better traceability. Includes corresponding database migrations to support these additions.
  • Loading branch information
hareshkainthdbt committed Feb 27, 2025
1 parent cac5241 commit 26c8bf6
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/cache/legislation.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ def _to_json(
"date_issued": convert_date_string_to_obj(valid_sort_date),
"date_modified": convert_date_string_to_obj(modified),
"date_valid": valid_sort_date,
"source_date_modified": modified,
"source_date_valid": valid,
"sort_date": valid_sort_date,
"type": "Legislation",
}
7 changes: 7 additions & 0 deletions app/cache/public_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,13 @@ def build_cache(self, config):
f"{inserted_document_count} / ({total_documents})..."
)

# Unnormalized date fields
row["source_date_issued"] = row.get("date_issued")

row["source_date_modified"] = row.get("date_modified")

row["source_date_valid"] = row.get("date_valid")

# Normalize the date fields
row["date_issued"] = convert_date_string_to_obj(
row.get("date_issued")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Generated by Django 4.2.19 on 2025-02-27 13:05

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("search", "0001_initial"),
]

operations = [
migrations.AddField(
model_name="dataresponsemodel",
name="source_date_issued",
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name="dataresponsemodel",
name="source_date_modified",
field=models.TextField(blank=True, null=True),
),
migrations.AddField(
model_name="dataresponsemodel",
name="source_date_valid",
field=models.TextField(blank=True, null=True),
),
]
3 changes: 3 additions & 0 deletions app/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ class DataResponseModel(models.Model):
date_issued = models.DateField(null=True, blank=True)
date_modified = models.DateField(null=True, blank=True)
date_valid = models.TextField(null=True, blank=True)
source_date_issued = models.TextField(null=True, blank=True)
source_date_modified = models.TextField(null=True, blank=True)
source_date_valid = models.TextField(null=True, blank=True)
sort_date = models.DateField(null=True, blank=True)
audience = models.TextField(null=True, blank=True)
coverage = models.TextField(null=True, blank=True)
Expand Down

0 comments on commit 26c8bf6

Please sign in to comment.