Skip to content

Commit

Permalink
fix(harvard_merge): adjust havard_id column type, index
Browse files Browse the repository at this point in the history
- Use better indexing approach
- Use IntegerField
- Make nullable
  • Loading branch information
cweider committed Oct 26, 2024
1 parent cb77066 commit 95a512f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
18 changes: 12 additions & 6 deletions cl/search/migrations/0037_add_harvard_id_to_opinioncluster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.2 on 2024-10-25 18:54
# Generated by Django 5.1.2 on 2024-10-25 22:37

import pgtrigger.compiler
import pgtrigger.migrations
Expand All @@ -8,6 +8,7 @@
class Migration(migrations.Migration):

dependencies = [
("people_db", "0017_pghistory_v3_4_0_trigger_update"),
("search", "0036_add_searchquery"),
]

Expand All @@ -23,18 +24,23 @@ class Migration(migrations.Migration):
migrations.AddField(
model_name="opinioncluster",
name="harvard_id",
field=models.CharField(
db_index=True,
default=0,
field=models.IntegerField(
help_text="The ID of the item in the Caselaw Access Project (Harvard)",
null=True,
),
),
migrations.AddField(
model_name="opinionclusterevent",
name="harvard_id",
field=models.CharField(
default=0,
field=models.IntegerField(
help_text="The ID of the item in the Caselaw Access Project (Harvard)",
null=True,
),
),
migrations.AddIndex(
model_name="opinioncluster",
index=models.Index(
fields=["harvard_id"], name="search_opin_harvard_9f1d7e_idx"
),
),
pgtrigger.migrations.AddTrigger(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
BEGIN;
ALTER TABLE "search_opinioncluster" ADD COLUMN "harvard_id" varchar DEFAULT '0' NOT NULL;
ALTER TABLE "search_opinioncluster" ALTER COLUMN "harvard_id" DROP DEFAULT;
ALTER TABLE "search_opinionclusterevent" ADD COLUMN "harvard_id" varchar DEFAULT '0' NOT NULL;
ALTER TABLE "search_opinionclusterevent" ALTER COLUMN "harvard_id" DROP DEFAULT;
CREATE INDEX "search_opinioncluster_harvard_id_b7c3eb52" ON "search_opinioncluster" ("harvard_id");
CREATE INDEX "search_opinioncluster_harvard_id_b7c3eb52_like" ON "search_opinioncluster" ("harvard_id" varchar_pattern_ops);
ALTER TABLE "search_opinioncluster" ADD COLUMN "harvard_id" integer NULL;
ALTER TABLE "search_opinionclusterevent" ADD COLUMN "harvard_id" integer NULL;
CREATE INDEX "search_opin_harvard_9f1d7e_idx" ON "search_opinioncluster" ("harvard_id");
COMMIT;
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
BEGIN;
ALTER TABLE "search_opinioncluster" ADD COLUMN "harvard_id" varchar DEFAULT '0' NOT NULL;
ALTER TABLE "search_opinioncluster" ALTER COLUMN "harvard_id" DROP DEFAULT;
CREATE INDEX "search_opinioncluster_harvard_id_b7c3eb52" ON "search_opinioncluster" ("harvard_id");
CREATE INDEX "search_opinioncluster_harvard_id_b7c3eb52_like" ON "search_opinioncluster" ("harvard_id" varchar_pattern_ops);
ALTER TABLE "search_opinioncluster" ADD COLUMN "harvard_id" integer NULL;
CREATE INDEX "search_opin_harvard_9f1d7e_idx" ON "search_opinioncluster" ("harvard_id");
COMMIT;
10 changes: 7 additions & 3 deletions cl/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2731,10 +2731,9 @@ class OpinionCluster(AbstractDateTimeModel):
storage=IncrementingAWSMediaStorage(),
blank=True,
)
harvard_id = models.CharField(
harvard_id = models.IntegerField(
help_text="The ID of the item in the Caselaw Access Project (Harvard)",
default=0,
db_index=True,
null=True,
)
arguments = models.TextField(
help_text="The attorney(s) and legal arguments presented as HTML text. "
Expand Down Expand Up @@ -2784,6 +2783,11 @@ class OpinionCluster(AbstractDateTimeModel):
]
)

class Meta:
indexes = [
models.Index(fields=["harvard_id"]),
]

async def acaption(self):
"""Make a proper caption
Expand Down
2 changes: 1 addition & 1 deletion cl/search/tests/test_import_harvard_pdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,4 @@ def test_assign_harvard_id(

# Verify that the cluster's harvard_id field was updated
self.cluster.refresh_from_db()
self.assertEqual(self.cluster.harvard_id, "1")
self.assertEqual(self.cluster.harvard_id, 1)

0 comments on commit 95a512f

Please sign in to comment.