Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

10504 dxox #5520

Draft
wants to merge 36 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
4d4787e
10504: start case correspondence + deadline
pixiwyn Oct 11, 2024
b1f6ade
10504: add additional case deadline queries
pixiwyn Oct 11, 2024
a0a6557
10504: remove old case deadline queries
pixiwyn Oct 11, 2024
8af8edd
10504: add seed data
pixiwyn Oct 11, 2024
3d157ab
10504: fix error with docket number
pixiwyn Oct 11, 2024
1da7c2d
10504: add correspondence seed
pixiwyn Oct 11, 2024
d13d26c
10491: add case correspondence
pixiwyn Oct 11, 2024
98dcdf6
10504: add case worksheets
pixiwyn Oct 11, 2024
a0e67e2
Merge branch 'staging' of github.com:ustaxcourt/ef-cms into 10504-dxox
pixiwyn Nov 6, 2024
9471803
10504-dxox: remove case-dealine| and fix correspondence mock file and…
Mwindo Nov 6, 2024
68c798b
10504-dxox: add mocks.jest.ts files, and fix updateCaseAndAssociation…
Mwindo Nov 6, 2024
d22ec53
10504-dxox: fix updatePetitionerInformationInteractor.test.ts
Mwindo Nov 6, 2024
ddeea43
10504-dxox: fix CaseDeadline.test.ts, getCaseDeadlnesInteractor.test.…
Mwindo Nov 6, 2024
b13ad2d
10504-dxox: fixing a whole lotta api tests
Mwindo Nov 7, 2024
8cc25ac
10504-dxox: fix shared test
Mwindo Nov 7, 2024
fecdc98
10504-dxox: fix more API tests
Mwindo Nov 7, 2024
016287e
10504-dxox: fix a few more tests, undo a change to MOCK_CASE (which w…
Mwindo Nov 7, 2024
81af9d7
10504-dxox: fix more tests, and some types
Mwindo Nov 7, 2024
db2846a
10504-dxox: remove dynamo persistence from client test application co…
Mwindo Nov 7, 2024
a09c769
10504-dxox: fix failing scripts test
Mwindo Nov 7, 2024
739a7d7
10504-dxox: fix failing integration test
Mwindo Nov 7, 2024
cba4b8c
10504-dxox: null check in caseWorksheet mapper
Mwindo Nov 8, 2024
3fbe127
10504-dxox: fix integration tests failing for timezone reasons
Mwindo Nov 8, 2024
3df68d9
10504-dxox: fix more timezone format mismatches in tests
Mwindo Nov 8, 2024
54c0cab
10504-dxox: change createCaseDeadline to upserCaseDeadline, and relat…
Mwindo Nov 8, 2024
891ae7a
10504-dxox: fix script test and api tests
Mwindo Nov 8, 2024
967414b
10504-dxox: remove numberOfPages, which looks like it was a spurious …
Mwindo Nov 11, 2024
86cca87
10504-dxox: remove numberOfPages from migration
Mwindo Nov 11, 2024
bcab627
10504-dxox: WIP using upsertCaseCorrespondences instead of upsertCase…
Mwindo Nov 12, 2024
00458dc
10504-dxox: WIP, make stream processors for deadlines, correspondence…
Mwindo Nov 12, 2024
f687585
10504-dxox: fix incorrect keys in processStreamUtilities; replace ups…
Mwindo Nov 13, 2024
60114d3
10504-dxox: update some tests after the previous refactor
Mwindo Nov 13, 2024
037f5b8
10504-dxox: add deletition scripts, add validation for judge id to Ca…
Mwindo Nov 13, 2024
830ab53
10504-dxox: add tests to new stream processors, and update postgres d…
Mwindo Nov 13, 2024
fcbf4ba
10504-dxox: fix validateCaseWorksheetAction.test, and avoid passing …
Mwindo Nov 13, 2024
fee1eaf
10504-dxox: add 'so far' to deletion scripts
Mwindo Nov 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions __TODO_10504.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
check Correspondence works now with docketNumber (added to the entity) and update validation?

--

Is docketNumber in Case assignCorrespondences necessary? Were there some old cases, maybe, onto which we directly stored correspondences?


--

check CaseWorksheet works now with judgeUserId (added to the entity) and update validation?

--

entityName: "CaseWorksheet" in updateCaseWorksheetAction is silly

--

add missing tests
3 changes: 0 additions & 3 deletions docs/dynamodb-access-patterns.csv
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
Access Scenario,PK,SK,GS1PK,GSI2PK
the case deadline object,case-deadline|${DEADLINE_ID},case-deadline|${DEADLINE_ID},
associate a deadline with a case (mapping record),case|${CASE_ID},case-deadline|${DEADLINE_ID},
a case,case|${CASE_ID},case|${CASE_ID},leadCase|${LEAD_CASE_ID}
associate an irs practitioner onto a case,case|${CASE_ID},irsPractitioner|${USER_ID},leadCase|${LEAD_CASE_ID}
associate a private practitioner onto a case,case|${CASE_ID},privatePractitioner|${USER_ID},leadCase|${LEAD_CASE_ID}
associate docket entry on a case,case|${CASE_ID},docket-entry|${DOCKET_ENTRY_ID},
add correspondence to a case,case|${CASE_ID},correspondence|${CORRESPONDENCE_ID},
add a hearing to a case,case|${CASE_ID},hearing|${TRIAL_SESSION_ID},
a work item on a case,case|${CASE_ID},work-item|${WORK_ITEM_ID},work-item|${WORK_ITEM_ID},assigneeId|${ASSIGNEE_ID}
docket number generator counter,docketNumberCounter-${YEAR},docketNumberCounter-${YEAR},
Expand Down
3 changes: 3 additions & 0 deletions scripts/dynamo/fix-race-condition-served-in-drafts.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*
* @jest-environment node
*/
import '@web-api/persistence/postgres/caseCorrespondences/mocks.jest';
import '@web-api/persistence/postgres/cases/mocks.jest';

import { DynamoDBClient, GetItemCommand } from '@aws-sdk/client-dynamodb';
import { MOCK_DOCUMENTS } from '@shared/test/mockDocketEntry';
import { applicationContext } from '@shared/business/test/createTestApplicationContext';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import {
Copy link
Contributor

@Mwindo Mwindo Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the script that was used for delete-messages.ts. I moved it here so it could be reusable.

BatchWriteCommand,
DynamoDBDocumentClient,
} from '@aws-sdk/lib-dynamodb';

export async function batchDeleteDynamoItems(
itemsToDelete: { DeleteRequest: { Key: { pk: string; sk: string } } }[],
client: DynamoDBDocumentClient,
tableNameInput: string,
): Promise<number> {
const BATCH_SIZE = 25;
const RETRY_DELAY_MS = 5000; // Set the delay between retries (in milliseconds)
let totalItemsDeleted = 0;

for (let i = 0; i < itemsToDelete.length; i += BATCH_SIZE) {
const batch = itemsToDelete.slice(i, i + BATCH_SIZE);

const batchWriteParams = {
RequestItems: {
[tableNameInput]: batch,
},
};

try {
let unprocessedItems: any[] = batch;
let retryCount = 0;
const MAX_RETRIES = 5;

// Retry logic for unprocessed items
while (unprocessedItems.length > 0 && retryCount < MAX_RETRIES) {
const response = await client.send(
new BatchWriteCommand(batchWriteParams),
);

totalItemsDeleted +=
unprocessedItems.length -
(response.UnprocessedItems?.[tableNameInput]?.length || 0);

unprocessedItems = response.UnprocessedItems?.[tableNameInput] ?? [];

if (unprocessedItems.length > 0) {
console.log(
`Retrying unprocessed items: ${unprocessedItems.length}, attempt ${retryCount + 1}`,
);
batchWriteParams.RequestItems[tableNameInput] = unprocessedItems;
retryCount++;

// Add delay before the next retry
await new Promise(resolve => setTimeout(resolve, RETRY_DELAY_MS));
}
}

if (unprocessedItems.length > 0) {
console.error(
`Failed to delete ${unprocessedItems.length} items after ${MAX_RETRIES} retries.`,
);
}
} catch (error) {
console.error('Error in batch delete:', error);
}
}
return totalItemsDeleted;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/**
* HOW TO RUN
*
* TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-correspondences.ts
*/

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient, ScanCommandInput } from '@aws-sdk/client-dynamodb';
import { requireEnvVars } from '../../../shared/admin-tools/util';
import { getDbReader } from '../../../web-api/src/database';
import { isEmpty } from 'lodash';
import { batchDeleteDynamoItems } from './batch-delete-dynamo-items';

const caseCorrespondencePageSize = 10000;
const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' });
const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient);

requireEnvVars(['TABLE_NAME']);

const tableNameInput = process.env.TABLE_NAME!;

const getCaseCorrespondencesToDelete = async (offset: number) => {
const caseCorrespondences = await getDbReader(reader =>
reader
.selectFrom('dwCaseCorrespondence')
.select(['docketNumber', 'correspondenceId'])
.orderBy('correspondenceId')
.limit(caseCorrespondencePageSize)
.offset(offset)
.execute(),
);
return caseCorrespondences;
};

let totalItemsDeleted = 0;

async function main() {
let offset = 0;
let caseCorrespondencesToDelete =
await getCaseCorrespondencesToDelete(offset);

while (!isEmpty(caseCorrespondencesToDelete)) {
const dynamoItemsToDelete = caseCorrespondencesToDelete.map(cd => ({
DeleteRequest: {
Key: {
pk: `case|${cd.docketNumber}`,
sk: `correspondence${cd.correspondenceId}`,
},
},
}));
totalItemsDeleted += await batchDeleteDynamoItems(
dynamoItemsToDelete,
dynamoDbDocClient,
tableNameInput,
);
console.log(
`Total case correspondences deleted so far: ${totalItemsDeleted}`,
);
offset += caseCorrespondencePageSize;
caseCorrespondencesToDelete = await getCaseCorrespondencesToDelete(offset);
}
console.log('Done deleting case correspondences from Dynamo');
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* HOW TO RUN
*
* TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-deadlines.ts
*/

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { requireEnvVars } from '../../../shared/admin-tools/util';
import { getDbReader } from '../../../web-api/src/database';
import { isEmpty } from 'lodash';
import { batchDeleteDynamoItems } from './batch-delete-dynamo-items';

const caseDeadlinePageSize = 10000;
const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' });
const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient);

requireEnvVars(['TABLE_NAME']);

const tableNameInput = process.env.TABLE_NAME!;

const getCaseDeadlinesToDelete = async (offset: number) => {
const caseDeadlines = await getDbReader(reader =>
reader
.selectFrom('dwCaseDeadline')
.select(['docketNumber', 'caseDeadlineId'])
.orderBy('caseDeadlineId')
.limit(caseDeadlinePageSize)
.offset(offset)
.execute(),
);
return caseDeadlines;
};

let totalItemsDeleted = 0;

async function main() {
let offset = 0;
let caseDeadlinesToDelete = await getCaseDeadlinesToDelete(offset);

while (!isEmpty(caseDeadlinesToDelete)) {
const dynamoItemsToDelete = caseDeadlinesToDelete.map(cd => ({
DeleteRequest: {
Key: {
pk: `case|${cd.docketNumber}`,
sk: `case-deadline|${cd.caseDeadlineId}`,
},
},
}));
totalItemsDeleted += await batchDeleteDynamoItems(
dynamoItemsToDelete,
dynamoDbDocClient,
tableNameInput,
);
console.log(`Total case deadlines deleted so far: ${totalItemsDeleted}`);
offset += caseDeadlinePageSize;
caseDeadlinesToDelete = await getCaseDeadlinesToDelete(offset);
}
console.log('Done deleting case deadlines from Dynamo');
}

main().catch(console.error);
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* HOW TO RUN
*
* TABLE_NAME=testing npx ts-node --transpileOnly scripts/postgres/delete-case-worksheets.ts
*/

import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
import { requireEnvVars } from '../../../shared/admin-tools/util';
import { getDbReader } from '../../../web-api/src/database';
import { isEmpty } from 'lodash';
import { batchDeleteDynamoItems } from './batch-delete-dynamo-items';

const caseWorksheetPageSize = 10000;
const dynamoDbClient = new DynamoDBClient({ region: 'us-east-1' });
const dynamoDbDocClient = DynamoDBDocumentClient.from(dynamoDbClient);

requireEnvVars(['TABLE_NAME']);

const tableNameInput = process.env.TABLE_NAME!;

const getCaseWorksheetsToDelete = async (offset: number) => {
const caseWorksheets = await getDbReader(reader =>
reader
.selectFrom('dwCaseWorksheet')
.select(['docketNumber'])
.orderBy('docketNumber')
.limit(caseWorksheetPageSize)
.offset(offset)
.execute(),
);
return caseWorksheets;
};

let totalItemsDeleted = 0;

async function main() {
let offset = 0;
let caseWorksheetsToDelete = await getCaseWorksheetsToDelete(offset);

while (!isEmpty(caseWorksheetsToDelete)) {
const dynamoItemsToDelete = caseWorksheetsToDelete.map(cd => ({
DeleteRequest: {
Key: {
pk: `case|${cd.docketNumber}`,
sk: `case-worksheet|${cd.docketNumber}`,
},
},
}));
totalItemsDeleted += await batchDeleteDynamoItems(
dynamoItemsToDelete,
dynamoDbDocClient,
tableNameInput,
);
console.log(`Total case worksheets deleted so far: ${totalItemsDeleted}`);
offset += caseWorksheetPageSize;
caseWorksheetsToDelete = await getCaseWorksheetsToDelete(offset);
}
console.log('Done deleting case worksheets from Dynamo');
}

main().catch(console.error);
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
ScanCommand,
} from '@aws-sdk/lib-dynamodb';
import { DynamoDBClient, ScanCommandInput } from '@aws-sdk/client-dynamodb';
import { requireEnvVars } from '../../shared/admin-tools/util';
import { requireEnvVars } from '../../../shared/admin-tools/util';

requireEnvVars(['TABLE_NAME']);

Expand Down
Loading
Loading