feat: centralize code table management and enum generation - #473
Conversation
|
Release c3bc681 deployed at https://pcns-dev-pr-473.apps.silver.devops.gov.bc.ca |
d3cf52b to
1c59400
Compare
There was a problem hiding this comment.
Pull request overview
This PR refactors “code table” handling by generating enums and building a centralized, dynamic in-memory cache for DB lookup/code tables (Prisma models ending in _code), then updating validators/controllers/tests to consume that centralized cache rather than hardcoded arrays.
Changes:
- Moved enum generation into
src/db/codes/generate.tsand updated generated enum import paths across app + frontend. - Introduced a centralized code-table discovery (
tables.ts), fetching (services/code.ts), and caching layer (cache.ts) with acodeTableaccessor. - Replaced hardcoded validation arrays/constants with code-table cache lookups and updated unit tests/mocks accordingly.
Reviewed changes
Copilot reviewed 35 out of 36 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/utils/enums/codeEnums.ts | Updates generator reference in the auto-generated frontend enum file header. |
| frontend/src/store/codeStore.ts | Changes a computed getter to map code → definition instead of code → code. |
| app/tests/unit/validators/permit.spec.ts | Updates enum import path to the new generated enums location. |
| app/tests/unit/validators/appliedPermits.spec.ts | Updates enum import path to the new generated enums location. |
| app/tests/unit/services/code.spec.ts | Updates service test expectations for the refactored code-table listing implementation. |
| app/tests/unit/parsers/peachParser.test.ts | Updates enum import path to the new generated enums location. |
| app/tests/unit/data/index.ts | Updates enum imports and adjusts expected note text fixture. |
| app/tests/unit/controllers/permit.spec.ts | Updates enum import path and assertions to use codeTable display strings. |
| app/tests/unit/controllers/peach.test.ts | Updates enum import path to the new generated enums location. |
| app/tests/unit/controllers/housingProject.spec.ts | Updates enum import path to the new generated enums location. |
| app/tests/unit/controllers/generalProject.spec.ts | Updates enum import path to the new generated enums location. |
| app/tests/mocks/prismaMock.ts | Adds a mocked codeTable implementation derived from generated enums for unit tests. |
| app/src/validators/permit.ts | Switches Joi .valid(...) lists from constants to codeTable.*.codes. |
| app/src/validators/noteHistory.ts | Switches Joi .valid(...) lists from cached arrays to codeTable.*.codes. |
| app/src/validators/generalProject.ts | Switches Joi .valid(...) lists from cached arrays to codeTable.*.codes. |
| app/src/validators/electrificationProject.ts | Switches Joi .valid(...)/array item lists from cached arrays to codeTable.*.codes. |
| app/src/validators/appliedPermit.ts | Switches Joi .valid(...) list from constants to codeTable.*.codes. |
| app/src/utils/constants/permit.ts | Removes now-redundant hardcoded PERMIT_STAGE_LIST / PERMIT_STATE_LIST. |
| app/src/utils/cache/codes.ts | Deletes the legacy code-cache module that managed per-table arrays. |
| app/src/types/stuff.d.ts | Updates enum import path to the new generated enums location. |
| app/src/services/code.ts | Refactors code-table listing to iterate discovered _code models dynamically. |
| app/src/parsers/peach.ts | Updates enum import path to the new generated enums location. |
| app/src/db/utils/generate_enums.ts | Removes the old enum generation script (replaced by src/db/codes/generate.ts). |
| app/src/db/codes/types.ts | Introduces shared types for code-table names and code rows. |
| app/src/db/codes/tables.ts | Adds code-table discovery via Prisma DMMF (*_code models, with exclusions). |
| app/src/db/codes/generate.ts | Adds the new enum generation script under the centralized codes module. |
| app/src/db/codes/enums.ts | Updates generator reference in the auto-generated backend enum file header. |
| app/src/db/codes/cache.ts | Adds the centralized in-memory code-table cache and refresh function. |
| app/src/controllers/roadmap.ts | Updates enum import path to the new generated enums location. |
| app/src/controllers/permit.ts | Updates enum import path and uses codeTable display strings in status-change note generation. |
| app/src/controllers/peach.ts | Updates enum import path to the new generated enums location. |
| app/src/controllers/housingProject.ts | Updates enum import path to the new generated enums location. |
| app/src/controllers/generalProject.ts | Updates enum import path to the new generated enums location. |
| app/server.ts | Switches code-cache warmup to the new centralized cache module. |
| app/peachSync.ts | Ensures code-cache warmup occurs before starting the PEACH sync loop. |
| app/package.json | Updates the prisma:enums script to point at the new generator. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
c084187 to
2efdfc8
Compare
2efdfc8 to
252162a
Compare
Refactors database lookup code tables to dynamically build caches and types directly from Prisma metadata. - Move enum generation script to `src/db/codes/generate.ts` - Implement dynamic cache manager in `src/db/codes/cache.ts` with a fail-fast Proxy to catch type sync errors - Fetch active tables dynamically via Prisma DMMF models - Initialize caches in `peachSync.ts` prior to sync loop - Replace static Joi `.valid()` calls with a `.custom()` Proxy to ensure code tables evaluate at runtime - Update unit tests and Jest mocks to support the central cache system Signed-off-by: qhanson55 <quinn.hanson@gov.bc.ca>
252162a to
8abb3d8
Compare
|
|



Description
Refactors how database lookup code tables are cached, generated, and consumed. This eliminates manual code table arrays by dynamically building memory caches and types from Prisma metadata models ending in
_code.src/db/codes/generate.tssrc/db/codes/cache.tsusing aProxymappingservices/code.tsvia Prisma DMMF modelspeachSync.tsto initialize caches prior to executing the synchronization loopTypes of changes
New feature (non-breaking change which adds functionality)
Checklist