After fixing the initial data.

In the Hearing table made the changes
1. Unique constraint on next_hearing_date & case_id
2. Made case_id non nullable as without it the data is garbage
3. Made the court_status_id in hearing non nullable
This commit is contained in:
Amritanshu Agrawal 2021-01-20 09:56:39 +05:30
parent e4783bc64e
commit 78e1ccd756
12 changed files with 22 additions and 47 deletions

View File

@ -256,8 +256,7 @@ def upgrade():
sa.Column("bench", sa.Unicode(length=255), nullable=True),
sa.Column("proceedings", sa.Unicode(length=2000), nullable=True),
sa.Column("compliance_date", sa.Date(), nullable=True),
# sa.Column("next_hearing_date", sa.Date(), nullable=False),
sa.Column("next_hearing_date", sa.Date(), nullable=True),
sa.Column("next_hearing_date", sa.Date(), nullable=False),
sa.Column("court_status_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("old_court_status_id", sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(["case_id"], ["cases.id"], name=op.f("fk_hearings_case_id_cases")),

View File

@ -98,7 +98,7 @@ def update_court_statuses():
op.drop_column("hearings", "old_court_status_id")
op.drop_column("court_statuses", "old_id")
# op.alter_column('cases', 'court_status_id', existing_type=postgresql.UUID(), nullable=False)
# op.alter_column('hearings', 'case_id', existing_type=postgresql.UUID(), nullable=False)
op.alter_column('hearings', 'court_status_id', existing_type=postgresql.UUID(), nullable=False)
def update_courts():
@ -213,6 +213,8 @@ def update_cases():
)
op.drop_column("hearings", "old_case_id")
op.drop_column("cases", "old_id")
op.alter_column('hearings', 'case_id', existing_type=postgresql.UUID(), nullable=False)
op.create_unique_constraint(op.f("uq_hearings_next_hearing_date"), "hearings", ["next_hearing_date", "case_id"])
def update_auth():

View File

@ -1,6 +1,6 @@
import uuid
from sqlalchemy import Column, Date, ForeignKey, Unicode, text
from sqlalchemy import Column, Date, ForeignKey, Unicode, UniqueConstraint, text
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
@ -9,6 +9,7 @@ from .meta import Base
class Hearing(Base):
__tablename__ = "hearings"
__table_args__ = (UniqueConstraint("next_hearing_date", "case_id"),)
id = Column(
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), default=uuid.uuid4
@ -26,7 +27,7 @@ class Hearing(Base):
proceedings = Column("proceedings", Unicode(255), nullable=False, unique=True)
next_hearing_date = Column("next_hearing_date", Date, nullable=False, index=True)
compliance_date = Column("compliance_date", Date, nullable=False, index=True)
court_status_id = Column("court_status_id", UUID(as_uuid=True), ForeignKey("court_statuses.id"), nullable=True)
court_status_id = Column("court_status_id", UUID(as_uuid=True), ForeignKey("court_statuses.id"), nullable=False)
court_status = relationship("CourtStatus", back_populates="hearings")
case = relationship("Case", back_populates="hearings")

View File

@ -299,9 +299,7 @@ def case_info(item: Case) -> schemas.Case:
proceedings=h.proceedings if h.proceedings is not None else "",
complianceDate=h.compliance_date,
nextHearingDate=h.next_hearing_date,
courtStatus=schemas.CourtStatusLink(id=h.court_status.id, name=h.court_status.name)
if h.court_status is not None
else None,
courtStatus=schemas.CourtStatusLink(id=h.court_status.id, name=h.court_status.name),
)
for h in item.hearings
],

View File

@ -40,6 +40,7 @@ class HearingIn(BaseModel):
class Hearing(HearingIn):
id_: Optional[uuid.UUID]
court_status: CourtStatusLink
class Config:
anystr_strip_whitespace = True

View File

@ -438,7 +438,6 @@
<mat-form-field fxFlex>
<mat-label>Latest Status</mat-label>
<mat-select placeholder="Latest Status" formControlName="latestStatus">
<mat-option value=""> -- Not Applicable --</mat-option>
<mat-option *ngFor="let cs of courtStatuses" [value]="cs.id">
{{ cs.name }}
</mat-option>
@ -521,7 +520,7 @@
<!-- Status Column -->
<ng-container matColumnDef="courtStatus">
<mat-header-cell *matHeaderCellDef class="right">Status</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{ row.courtStatus?.name }}</mat-cell>
<mat-cell *matCellDef="let row" class="right">{{ row.courtStatus.name }}</mat-cell>
</ng-container>
<!-- Proceedings Column -->

View File

@ -351,14 +351,10 @@ export class CaseDetailComponent implements OnInit, AfterViewInit {
const courtNumber: string = formValue.courtNumber;
const itemNumber: string = formValue.itemNumber;
const bench: string = formValue.bench;
const latestStatus =
formValue.latestStatus === ''
? null
: new CourtStatus({
id: formValue.latestStatus,
name: (this.courtStatuses.find((x) => x.id === formValue.latestStatus) as CourtStatus)
.name,
});
const latestStatus = new CourtStatus({
id: formValue.latestStatus,
name: (this.courtStatuses.find((x) => x.id === formValue.latestStatus) as CourtStatus).name,
});
const proceedings = formValue.proceedings;
const complianceDate = formValue.complianceDate

View File

@ -49,7 +49,6 @@
<mat-form-field fxFlex>
<mat-label>Latest Status</mat-label>
<mat-select placeholder="Latest Status" formControlName="latestStatus">
<mat-option value=""> -- Not Applicable --</mat-option>
<mat-option *ngFor="let cs of data.courtStatuses" [value]="cs.id">
{{ cs.name }}
</mat-option>

View File

@ -35,7 +35,7 @@ export class HearingDialogComponent implements OnInit {
courtNumber: this.data.hearing.courtNumber,
itemNumber: this.data.hearing.itemNumber,
bench: this.data.hearing.bench,
latestStatus: this.data.hearing.courtStatus ? this.data.hearing.courtStatus.id : '',
latestStatus: this.data.hearing.courtStatus.id,
proceedings: this.data.hearing.proceedings,
complianceDate: this.data.hearing.complianceDate
? moment(this.data.hearing.complianceDate, 'DD-MMM-YYYY').toDate()
@ -52,15 +52,11 @@ export class HearingDialogComponent implements OnInit {
this.data.hearing.itemNumber = formValue.itemNumber;
this.data.hearing.bench = formValue.bench;
this.data.hearing.courtStatus =
formValue.latestStatus === ''
? null
: new CourtStatus({
id: formValue.latestStatus,
name: (this.data.courtStatuses.find(
(x) => x.id === formValue.latestStatus,
) as CourtStatus).name,
});
this.data.hearing.courtStatus = new CourtStatus({
id: formValue.latestStatus,
name: (this.data.courtStatuses.find((x) => x.id === formValue.latestStatus) as CourtStatus)
.name,
});
this.data.hearing.proceedings = formValue.proceedings;
this.data.hearing.complianceDate = formValue.complianceDate
? moment(formValue.complianceDate).format('DD-MMM-YYYY')

View File

@ -96,20 +96,6 @@
<mat-cell *matCellDef="let row">{{ row.receiptDate }}</mat-cell>
</ng-container>
<!-- Office Column -->
<ng-container matColumnDef="office">
<mat-header-cell *matHeaderCellDef>Office</mat-header-cell>
<mat-cell *matCellDef="let row"
>{{ row.department?.name }} / {{ row.office?.name }}</mat-cell
>
</ng-container>
<!-- Lower Court Case Number Column -->
<ng-container matColumnDef="lowerCourtCaseNumber">
<mat-header-cell *matHeaderCellDef>Lower Court Case Number</mat-header-cell>
<mat-cell *matCellDef="let row">{{ row.lowerCourtCaseNumber }}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table>

View File

@ -35,8 +35,6 @@ export class CaseListComponent implements OnInit {
'officeStatus',
'remarks',
'receiptDate',
'office',
'lowerCourtCaseNumber',
];
constructor(private route: ActivatedRoute, private fb: FormBuilder, private ser: CaseService) {

View File

@ -5,7 +5,7 @@ export class Hearing {
courtNumber: string;
itemNumber: string;
bench: string;
courtStatus: CourtStatus | null;
courtStatus: CourtStatus;
proceedings: string;
complianceDate: string | null;
nextHearingDate: string | null;
@ -15,7 +15,7 @@ export class Hearing {
this.courtNumber = '';
this.itemNumber = '';
this.bench = '';
this.courtStatus = null;
this.courtStatus = new CourtStatus();
this.proceedings = '';
this.complianceDate = null;
this.nextHearingDate = null;