Prisma schema mapping - #352
Conversation
| firstName: req.query.firstName, | ||
| lastName: req.query.lastName, | ||
| contactApplicantRelationship: req.query.contactApplicantRelationship, | ||
| phoneNumber: req.query.phoneNumber, |
Check warning
Code scanning / CodeQL
Sensitive data read from GET request Medium
36d9607 to
13dd675
Compare
13dd675 to
bc895d2
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR fundamentally changes the database interaction layer by implementing Prisma schema mapping from snake_case to camelCase naming conventions. It replaces manually created DB types with auto-generated Prisma models, removes the old DAO/DTO layers, and restructures controllers and services to use individual function exports with transaction wrappers for better data integrity.
Key changes include:
- Migration from snake_case to camelCase database field naming using
prisma-case-format - Replacement of manual DB types with auto-generated Prisma models in
models.ts - Restructuring of controllers and services to export individual functions instead of default exports
- Implementation of transaction wrappers for all database operations
Reviewed Changes
Copilot reviewed 174 out of 277 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| app/tests/unit/controllers/*.spec.ts | Updated test files to use new controller function imports and transaction mocks |
| app/tests/mocks/prismaMock.ts | Enhanced mock setup to support transaction wrapper and extended client types |
| app/src/validators/*.ts | Updated field names from snake_case to camelCase and restructured validation schemas |
| app/src/utils/regexp.ts | Added common regex patterns for validation |
| app/src/types/models.ts | New auto-generated Prisma model types replacing manual DB types |
| app/src/types/index.ts | Simplified to export only models and utility types |
| app/src/services/*.ts | Converted to individual function exports with transaction client parameters |
Files not reviewed (1)
- app/package-lock.json: Language not supported
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
Here's what I found so far (Housing -NAV view) Projects submissions table
Project submission information tab
Enquiry
|
|
|
Housing NAV view Enquiry submission
Contacts page
|
4cbd26c to
42c0d20
Compare
|
Housing Proponent intake form Couldn't submit the intake form. Received the following error message upon submission
After hitting these errors, the app wouldn't respond when trying to navigate to other pages. After refreshing the app worked again. Electrification Proponent intake form |
Note -> NoteHistory file renames. Test updates. Lint fixes.
Removed custom models layer. Adjusted naming in services.
Use Prisma client types and consolidate model types to single file. Remove custom model types
Use new typings. Explicit return types. Exporting each function individually.
tsDoc, function names, Array to []
5fdd632 to
efb4752
Compare
|
For starters (need these fixed before going much further)
|
|
Electrification specific - NAV view
|
|
More NAV view errors across both initiatives Enquiry submissions
|
|
4b8779b to
17a3711
Compare
17a3711 to
b171374
Compare
9ad4ddf to
1f4e7ee
Compare
415a8c9 to
255724f
Compare
Use `filesize` in create body instead of `length`
255724f to
45c3fef
Compare
|
|




Description
This PR fundamentally changes the way the database is interacted with. Prisma now maps the database snake_case naming to camelCase naming in the schema.prisma file. This can be done automatically using a new package,
prisma-case-format. This package is automatically set up as part of theprisma:migratecommand.prisma:casecan be run independently to do a case update and resync.The old manually created DB application types and prisma dao/dto layers are now gone. Models now exist in the
models.tsfile using a strict structure. Theconstbase is a validated Prisma object for that table. The exportedBasetype is the auto generated Prisma structure. This type should be used for allprisma.create()calls. The exported type below theBasetype is the type generally used through the application, extendingBaseto include any relational information.Non-DB types should be added to
stuff.d.ts. Yes, stuff. That's what it is.The controller layers now export each function independently instead of wrapping them all as a single default export. This allows the router layers to easily add the controller function as part of the chain. Each controller function now creates a single Prisma transaction using the
transactionWrapper, and each service call is to use this transaction to ensure data integrity and proper data rollbacks in the event of an error.The service layers now export each function independently instead of wrapping them all as a single default export. Each service function now takes a
PrismaTransactionClientas its first parameter. This is to be the transaction object created in the controller. The Prisma client should never interact with the database, only thePrismaTransactionClientshould be used.Some default unit testing data for the back end has been added to
app\tests\unit\data\index.ts. There was way too many duplicated testing types spread throughout the files making it a nightmare to update tests should a DB schema change happen. Use these directly or destructure them and make any necessary data changes locally in a test. DO NOT change the existing types unless a schema change is required. If you need something wildly different than the existing ones then add new ones.And probably a whole lot more. There's 277 file changes. Sorry.
https://apps.nrs.gov.bc.ca/int/jira/browse/PADS-589
Types of changes
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)
Breaking change (fix or feature that would cause existing functionality to change)
Checklist
Further comments