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("bench", sa.Unicode(length=255), nullable=True),
sa.Column("proceedings", sa.Unicode(length=2000), nullable=True), sa.Column("proceedings", sa.Unicode(length=2000), nullable=True),
sa.Column("compliance_date", sa.Date(), 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=False),
sa.Column("next_hearing_date", sa.Date(), nullable=True),
sa.Column("court_status_id", postgresql.UUID(as_uuid=True), nullable=True), sa.Column("court_status_id", postgresql.UUID(as_uuid=True), nullable=True),
sa.Column("old_court_status_id", sa.Integer(), 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")), 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("hearings", "old_court_status_id")
op.drop_column("court_statuses", "old_id") op.drop_column("court_statuses", "old_id")
# op.alter_column('cases', 'court_status_id', existing_type=postgresql.UUID(), nullable=False) # 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(): def update_courts():
@ -213,6 +213,8 @@ def update_cases():
) )
op.drop_column("hearings", "old_case_id") op.drop_column("hearings", "old_case_id")
op.drop_column("cases", "old_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(): def update_auth():

View File

@ -1,6 +1,6 @@
import uuid 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.dialects.postgresql import UUID
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
@ -9,6 +9,7 @@ from .meta import Base
class Hearing(Base): class Hearing(Base):
__tablename__ = "hearings" __tablename__ = "hearings"
__table_args__ = (UniqueConstraint("next_hearing_date", "case_id"),)
id = Column( id = Column(
"id", UUID(as_uuid=True), primary_key=True, server_default=text("gen_random_uuid()"), default=uuid.uuid4 "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) proceedings = Column("proceedings", Unicode(255), nullable=False, unique=True)
next_hearing_date = Column("next_hearing_date", Date, nullable=False, index=True) next_hearing_date = Column("next_hearing_date", Date, nullable=False, index=True)
compliance_date = Column("compliance_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") court_status = relationship("CourtStatus", back_populates="hearings")
case = relationship("Case", 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 "", proceedings=h.proceedings if h.proceedings is not None else "",
complianceDate=h.compliance_date, complianceDate=h.compliance_date,
nextHearingDate=h.next_hearing_date, nextHearingDate=h.next_hearing_date,
courtStatus=schemas.CourtStatusLink(id=h.court_status.id, name=h.court_status.name) courtStatus=schemas.CourtStatusLink(id=h.court_status.id, name=h.court_status.name),
if h.court_status is not None
else None,
) )
for h in item.hearings for h in item.hearings
], ],

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -96,20 +96,6 @@
<mat-cell *matCellDef="let row">{{ row.receiptDate }}</mat-cell> <mat-cell *matCellDef="let row">{{ row.receiptDate }}</mat-cell>
</ng-container> </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-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row> <mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
</mat-table> </mat-table>

View File

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

View File

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