Skip to content

Commit

Permalink
refactor(cl.search): More changes for PR
Browse files Browse the repository at this point in the history
  • Loading branch information
flooie committed Sep 26, 2023
1 parent 2e7116f commit 31369f9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 62 deletions.
36 changes: 15 additions & 21 deletions cl/search/migrations/0020_courthouse_and_more.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 4.2.4 on 2023-09-25 22:40
# Generated by Django 4.2.4 on 2023-09-26 02:01

from django.db import migrations, models
import django.db.models.deletion
Expand Down Expand Up @@ -29,75 +29,69 @@ class Migration(migrations.Migration):
"court_seat",
models.BooleanField(
default=False,
help_text="Is this the seat of the Court.",
help_text="Is this the seat of the Court?",
null=True,
),
),
(
"building_name",
models.TextField(
blank=True,
help_text="Ex. John Adams Courthouse",
verbose_name="Courthouse building name.",
blank=True, help_text="Ex. John Adams Courthouse."
),
),
(
"address1",
models.TextField(
blank=True,
db_index=True,
help_text="The normalized address1 of the courthouse.",
),
),
(
"address2",
models.TextField(
blank=True,
db_index=True,
help_text="The normalized address2 of the courthouse.",
),
),
(
"city",
models.TextField(
blank=True,
db_index=True,
help_text="The normalized city of the organization.",
help_text="The normalized city of the courthouse.",
),
),
(
"county",
models.TextField(
blank=True,
help_text="The county, if any, where the court resides.",
help_text="The county, if any, where the courthouse resides.",
),
),
(
"state",
localflavor.us.models.USPostalCodeField(
blank=True,
null=True,
db_index=True,
help_text="The two-letter USPS postal abbreviation for the organization w/ obsolete state options.",
max_length=2,
),
),
(
"zip_code",
localflavor.us.models.USZipCodeField(
null=True,
blank=True,
db_index=True,
help_text="The zip code for the organization, XXXXX or XXXXX-XXXX work.",
max_length=10,
),
),
(
"country_code",
models.CharField(
models.TextField(
choices=[
("GB", "United Kingdom"),
("US", "United States"),
],
default="US",
help_text="The two letter country code",
max_length=2,
help_text="The two letter country code.",
),
),
],
Expand All @@ -115,11 +109,11 @@ class Migration(migrations.Migration):
),
migrations.AddField(
model_name="court",
name="appellate_courts",
name="appeals_to",
field=models.ManyToManyField(
blank=True,
help_text="Appellate courts for this court",
related_name="appellate_courts_to",
related_name="appeals_from",
to="search.court",
),
),
Expand All @@ -131,7 +125,7 @@ class Migration(migrations.Migration):
help_text="Parent court for subdivisions",
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="subcourts",
related_name="child_courts",
to="search.court",
),
),
Expand Down Expand Up @@ -248,7 +242,7 @@ class Migration(migrations.Migration):
model_name="courthouse",
name="court",
field=models.ForeignKey(
help_text="The court object associated with this Courthouse.",
help_text="The court object associated with this courthouse.",
on_delete=django.db.models.deletion.CASCADE,
related_name="courts",
to="search.court",
Expand Down
30 changes: 10 additions & 20 deletions cl/search/migrations/0020_courthouse_and_more.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ BEGIN;
--
-- Create model Courthouse
--
CREATE TABLE "search_courthouse" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "court_seat" boolean NULL, "building_name" text NOT NULL, "address1" text NOT NULL, "address2" text NOT NULL, "city" text NOT NULL, "county" text NOT NULL, "state" varchar(2) NULL, "zip_code" varchar(10) NULL, "country_code" varchar(2) NOT NULL);
CREATE TABLE "search_courthouse" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "court_seat" boolean NULL, "building_name" text NOT NULL, "address1" text NOT NULL, "address2" text NOT NULL, "city" text NOT NULL, "county" text NOT NULL, "state" varchar(2) NOT NULL, "zip_code" varchar(10) NOT NULL, "country_code" text NOT NULL);
--
-- Remove trigger update_or_delete_snapshot_delete from model court
--
Expand All @@ -12,9 +12,9 @@ DROP TRIGGER IF EXISTS pgtrigger_update_or_delete_snapshot_delete_84ec4 ON "sear
--
DROP TRIGGER IF EXISTS pgtrigger_update_or_delete_snapshot_update_c94ab ON "search_court";
--
-- Add field appellate_courts to court
-- Add field appeals_to to court
--
CREATE TABLE "search_court_appellate_courts" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "from_court_id" varchar(15) NOT NULL, "to_court_id" varchar(15) NOT NULL);
CREATE TABLE "search_court_appeals_to" ("id" integer NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, "from_court_id" varchar(15) NOT NULL, "to_court_id" varchar(15) NOT NULL);
--
-- Add field parent_court to court
--
Expand Down Expand Up @@ -139,23 +139,13 @@ ALTER TABLE "search_courtevent" ADD COLUMN "parent_court_id" varchar(15) NULL;
-- Add field court to courthouse
--
ALTER TABLE "search_courthouse" ADD COLUMN "court_id" varchar(15) NOT NULL CONSTRAINT "search_courthouse_court_id_6528f572_fk_search_court_id" REFERENCES "search_court"("id") DEFERRABLE INITIALLY DEFERRED; SET CONSTRAINTS "search_courthouse_court_id_6528f572_fk_search_court_id" IMMEDIATE;
CREATE INDEX "search_courthouse_address1_713c70f8" ON "search_courthouse" ("address1");
CREATE INDEX "search_courthouse_address1_713c70f8_like" ON "search_courthouse" ("address1" text_pattern_ops);
CREATE INDEX "search_courthouse_address2_6344113f" ON "search_courthouse" ("address2");
CREATE INDEX "search_courthouse_address2_6344113f_like" ON "search_courthouse" ("address2" text_pattern_ops);
CREATE INDEX "search_courthouse_city_4a7c0fb2" ON "search_courthouse" ("city");
CREATE INDEX "search_courthouse_city_4a7c0fb2_like" ON "search_courthouse" ("city" text_pattern_ops);
CREATE INDEX "search_courthouse_state_8a5794a6" ON "search_courthouse" ("state");
CREATE INDEX "search_courthouse_state_8a5794a6_like" ON "search_courthouse" ("state" varchar_pattern_ops);
CREATE INDEX "search_courthouse_zip_code_160c45c9" ON "search_courthouse" ("zip_code");
CREATE INDEX "search_courthouse_zip_code_160c45c9_like" ON "search_courthouse" ("zip_code" varchar_pattern_ops);
ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appellate_c_from_court_id_to_court_i_c508e354_uniq" UNIQUE ("from_court_id", "to_court_id");
ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appella_from_court_id_203006c3_fk_search_co" FOREIGN KEY ("from_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "search_court_appellate_courts" ADD CONSTRAINT "search_court_appella_to_court_id_fca7514b_fk_search_co" FOREIGN KEY ("to_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "search_court_appellate_courts_from_court_id_203006c3" ON "search_court_appellate_courts" ("from_court_id");
CREATE INDEX "search_court_appellate_courts_from_court_id_203006c3_like" ON "search_court_appellate_courts" ("from_court_id" varchar_pattern_ops);
CREATE INDEX "search_court_appellate_courts_to_court_id_fca7514b" ON "search_court_appellate_courts" ("to_court_id");
CREATE INDEX "search_court_appellate_courts_to_court_id_fca7514b_like" ON "search_court_appellate_courts" ("to_court_id" varchar_pattern_ops);
ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_to_from_court_id_to_court_id_006ed7af_uniq" UNIQUE ("from_court_id", "to_court_id");
ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_from_court_id_fb09cc1a_fk_search_co" FOREIGN KEY ("from_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED;
ALTER TABLE "search_court_appeals_to" ADD CONSTRAINT "search_court_appeals_to_to_court_id_49ac3d9c_fk_search_court_id" FOREIGN KEY ("to_court_id") REFERENCES "search_court" ("id") DEFERRABLE INITIALLY DEFERRED;
CREATE INDEX "search_court_appeals_to_from_court_id_fb09cc1a" ON "search_court_appeals_to" ("from_court_id");
CREATE INDEX "search_court_appeals_to_from_court_id_fb09cc1a_like" ON "search_court_appeals_to" ("from_court_id" varchar_pattern_ops);
CREATE INDEX "search_court_appeals_to_to_court_id_49ac3d9c" ON "search_court_appeals_to" ("to_court_id");
CREATE INDEX "search_court_appeals_to_to_court_id_49ac3d9c_like" ON "search_court_appeals_to" ("to_court_id" varchar_pattern_ops);
CREATE INDEX "search_court_parent_court_id_51ba1d28" ON "search_court" ("parent_court_id");
CREATE INDEX "search_court_parent_court_id_51ba1d28_like" ON "search_court" ("parent_court_id" varchar_pattern_ops);
CREATE INDEX "search_courtevent_parent_court_id_342036cc" ON "search_courtevent" ("parent_court_id");
Expand Down
36 changes: 15 additions & 21 deletions cl/search/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2034,18 +2034,18 @@ class Court(models.Model):
)
parent_court = models.ForeignKey(
"self",
help_text="Parent court for subdivisions",
on_delete=models.SET_NULL,
blank=True,
null=True,
related_name="subcourts",
help_text="Parent court for subdivisions",
related_name="child_courts",
)
appellate_courts = models.ManyToManyField(
appeals_to = models.ManyToManyField(
"self",
help_text="Appellate courts for this court",
blank=True,
symmetrical=False,
related_name="appellate_courts_to",
help_text="Appellate courts for this court",
related_name="appeals_from",
)
# Pacer fields
pacer_court_id = models.PositiveSmallIntegerField(
Expand Down Expand Up @@ -2174,59 +2174,53 @@ class Meta:
class Courthouse(models.Model):
"""A class to represent the physical location of a court."""

COUNTRY_CHOICES = (("GB", "United Kingdom"), ("US", "United States"))

court = models.ForeignKey(
Court,
help_text="The court object associated with this Courthouse.",
help_text="The court object associated with this courthouse.",
related_name="courts",
on_delete=models.CASCADE,
)
court_seat = models.BooleanField(
help_text="Is this the seat of the Court.",
help_text="Is this the seat of the Court?",
default=False,
null=True,
)
building_name = models.TextField(
verbose_name="Courthouse building name.",
help_text="Ex. John Adams Courthouse",
help_text="Ex. John Adams Courthouse.",
blank=True,
)
address1 = models.TextField(
help_text="The normalized address1 of the courthouse.",
db_index=True,
blank=True,
)
address2 = models.TextField(
help_text="The normalized address2 of the courthouse.",
db_index=True,
blank=True,
)
city = models.TextField(
help_text="The normalized city of the organization.",
db_index=True,
help_text="The normalized city of the courthouse.",
blank=True,
)
county = models.TextField(
help_text="The county, if any, where the court resides.",
help_text="The county, if any, where the courthouse resides.",
blank=True,
)
state = USPostalCodeField(
help_text="The two-letter USPS postal abbreviation for the "
"organization w/ obsolete state options.",
db_index=True,
choices=USPS_CHOICES + OBSOLETE_STATES,
null=True,
blank=True,
)
zip_code = USZipCodeField(
help_text="The zip code for the organization, XXXXX or XXXXX-XXXX "
"work.",
db_index=True,
blank=True,
null=True,
)
country_code = models.CharField(
help_text="The two letter country code",
max_length=2,
country_code = models.TextField(
help_text="The two letter country code.",
choices=COUNTRY_CHOICES,
default="US",
)

Expand Down

0 comments on commit 31369f9

Please sign in to comment.