Skip to content

#171: Refactor Submission Record data access layer for new schema - #209

Open
leoraba wants to merge 20 commits into
feat/submission_records_separationfrom
feat/submission_records_refactor
Open

#171: Refactor Submission Record data access layer for new schema#209
leoraba wants to merge 20 commits into
feat/submission_records_separationfrom
feat/submission_records_refactor

Conversation

@leoraba

@leoraba leoraba commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Refactors the functions responsible for fetching, updating, and deleting, and validate Submission Records to align with the new database structure.

Issues

This PR is part 2 of #171
depends on PR #206

Description of Changes

  • Removed the legacy columns for data and errors in Submission table. NOTE: This permanently deletes the data and errors values stored under the old schema. This data has already been migrated to the new schema, so no information is lost.
  • Added 2 new repository files: submissionFilesRepository.ts and submissionRecordsRepository.ts to access submission files and records.
  • Updated Submission service and utils functions to adapt to new database schema to fetch submission records
  • Endpoints changes:
    • renamed path GET /submission/category/{categoryId}/details: to /submission/category/{categoryId}/data: added query param fileId
    • renamed path DELETE /submission/category/{categoryId}/{actionType}: to /submission/category/{categoryId}/data: added query params: fileId, recordId
  • Added/updated unit tests
  • Added tech-debts that will be addressed in separate PRs

Readiness Checklist

  • Self Review
    • I have performed a self review of code
    • I have run the application locally and manually tested the feature
    • I have checked all updates to correct typos and misspellings
  • Formatting
    • Code follows the project style guide
    • Autmated code formatters (ie. Prettier) have been run
  • Local Testing
    • Successfully built all packages locally
    • Successfully ran all test suites, all unit and integration tests pass
  • Updated Tests
    • Unit and integration tests have been added that describe the bug that was fixed or the features that were added
  • Documentation
    • All new environment variables added to .env.schema file and documented in the README
    • All changes to server HTTP endpoints have open-api documentation
    • All new functions exported from their module have TSDoc comment documentation

@leoraba
leoraba marked this pull request as draft July 3, 2026 16:07
@leoraba
leoraba force-pushed the feat/submission_records_refactor branch from b62e41b to 4a94d8f Compare August 11, 2026 11:53
updated tsdocs, removed unused code, added missing db transactions
@leoraba
leoraba force-pushed the feat/submission_records_refactor branch from b5fcdc6 to 5679af7 Compare August 11, 2026 17:57
@leoraba
leoraba marked this pull request as ready for review August 14, 2026 13:35
Comment thread apps/server/swagger/submission-api.yml Outdated
$ref: '#/components/responses/ServiceUnavailableError'

/submission/{submissionId}/{actionType}:
/submission/{submissionId}/data:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

renamed this endpoint to /data and changed to query params to include recordId and fileId

/submission/{submissionId}/details:
get:
summary: Fetch Submission Data records. Sorted in their original file order and grouped by `inserts`, `updates`, and `deletes`.
summary: Fetch Submission Data records. Sorted in their original file order and grouped by `insert`, `update`, and `delete`.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the values of this query param to be consistent through all the application

Comment on lines +1 to +2
ALTER TABLE "submissions" DROP COLUMN IF EXISTS "data";--> statement-breakpoint
ALTER TABLE "submissions" DROP COLUMN IF EXISTS "errors"; No newline at end of file

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removing data and errors column from submission table, this PR assumes the SQL script migration (0016) moved all submissions data into it's own separate table

Comment on lines +797 to +800
await Promise.all(
Object.entries(insertRecords).map(([entityName, entityRecords]) =>
dependencies.db.transaction(async (tx) => {
const savedFileId = await submissionFilesRepository.save(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

wrapped in a db transaction storing each file along with it's records for atomicity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant