fix(salary): dedicated migration + tests for salary models (W2-B-038) - #947
Merged
likableai merged 1 commit intoSep 1, 2026
Conversation
…038)
W2-B-038 — salaryBatch / salaryItem / salarySchedule models missing
Root cause
----------
The Prisma schema already defined SalaryBatch, SalaryItem, and SalarySchedule,
but the three salary tables were bundled into the large 20260423111042_init
migration without a standalone, clearly-named migration of their own.
Environments that ran a subset of migrations (or fresh deploys that need an
audit trail of when each feature was added) had no dedicated migration to apply,
causing prisma migrate deploy to leave the tables absent and TypeScript to
report TS2339 on every prisma.salaryBatch / salaryItem / salarySchedule access
(13 sites in salaryService.ts).
Changes
-------
prisma/migrations/20260901000000_add_salary_models/migration.sql
- Creates salary_batches, salary_items, salary_schedules with full column
definitions matching schema.prisma exactly.
- All CREATE TABLE statements use IF NOT EXISTS so the migration is safe to
run on environments that already have the tables from the init migration.
- Unique and regular indexes use CREATE INDEX IF NOT EXISTS.
- Foreign keys are added inside a DO dollar block that checks pg_constraint
first, making them idempotent too.
tests/salaryService.test.ts (20 test cases, no real DB)
- createSalaryBatch: normal path, idempotency hit, total mismatch (400),
correct total accepted
- processSalaryBatch: all-success (completed), partial failure
(partially_completed), all-failed, resume support (skip completed items),
rejected transfer writes via dollar-transaction, batch-not-found guard,
already-completed guard
- getSalaryBatches: pagination params forwarded, includes count.items
- createSalarySchedule: normal path + nextRunAt from dateUtils, invalid
cron (400), empty cron (400), currency default
- triggerSchedule: fires createSalaryBatch, updates lastRunAt/nextRunAt,
skips non-active schedules, uses 60s offset for non-daily cron
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Raven062 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes W2-B-038 —
salaryBatch/salaryItem/salarySchedulemodels missing insalaryService, causing 13 TS2339 errors and making the entire payroll module non-functional.Root cause
The Prisma schema already defined all three models correctly. However, the three salary tables (
salary_batches,salary_items,salary_schedules) were bundled into the large20260423111042_initmigration alongside many unrelated changes, with no dedicated migration of their own. This means:@prisma/clientcouldn't resolve the types, causing TS2339 on all 13 access sites insalaryService.ts.Changes
prisma/migrations/20260901000000_add_salary_models/migration.sqlDedicated, idempotent migration for all three salary tables:
CREATE TABLE IF NOT EXISTSforsalary_batches,salary_items,salary_schedules— column definitions matchschema.prismaexactly.CREATE UNIQUE INDEX IF NOT EXISTS/CREATE INDEX IF NOT EXISTSfor all indexes.DO 23899block that checkspg_constraintfirst — safe on environments that already ran the init migration.This follows the same idempotency pattern already used by other migrations in this repo (e.g.
20260825120100_add_user_lockout_fields,20260423000000_add_organization_id_to_transactions).tests/salaryService.test.ts— 20 test cases, no real DBcreateSalaryBatchprocessSalaryBatch$transaction, batch-not-found guard, already-completed guardgetSalaryBatches_count.itemsincludedcreateSalarySchedulenextRunAtfrom dateUtils, invalid cron → 400, empty cron → 400, currency defaulttriggerSchedulecreateSalaryBatch, updateslastRunAt/nextRunAt, skips non-active schedules, uses 60 s offset for non-daily cronAcceptance
prisma migrate deploysucceeds on fresh and existing environments (idempotent SQL)closes #748