fix: increase unit_price decimal precision from 2 to 4 (closes #66)#70
fix: increase unit_price decimal precision from 2 to 4 (closes #66)#70marcm0de wants to merge 1 commit intolegions-developer:mainfrom
Conversation
…s-developer#66) The unit_price column in invoice_items used NUMERIC(10,2) which truncated values beyond 2 decimal places. For example, 0.141 would be stored as 0.14 and lose the third decimal place on page reload. Changed to NUMERIC(10,4) to support up to 4 decimal places, which covers common use cases like per-unit costs (e.g., $0.0375/kWh). Note: Existing data with 2 decimal places is unaffected — the migration just adds capacity for more precision.
|
@marcm0de is attempting to deploy a commit to the Invoicely OSS Team on Vercel. A member of the Team first needs to authorize it. |
📝 WalkthroughWalkthroughUpdated the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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 Tip You can enable review details to help with troubleshooting, context usage and more.Enable the |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/db/src/schema/invoice.ts (1)
98-98: Consider aligningvaluecolumn precision for consistency.The
invoiceDetailsBillingDetails.valuecolumn still usesscale: 2. If billing details (taxes, fees, discounts) could also require higher precision, consider updating this column toscale: 4as well. If the difference is intentional (e.g., percentages vs unit prices), no action needed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 758cba98-7f6d-4cad-b9dc-a851f4b1470b
📒 Files selected for processing (1)
packages/db/src/schema/invoice.ts
|
@marcm0de Unit prices, in general Price should be upto 2 decimal only. Unit quantity can be upto 4 decimal or more if it is required as per business requirements |
Summary
Fixes #66 — unit price loses decimal precision when saved to database.
Problem
The
unit_pricecolumn usesNUMERIC(10,2), which truncates anything beyond 2 decimal places. Setting a unit price of0.141saves as0.14.Fix
Changed
scalefrom2to4in the schema definition:NUMERIC(10,4).This supports up to 4 decimal places (e.g.,
0.0375for per-unit energy costs) while keeping existing 2-decimal data unaffected.Files Changed
packages/db/src/schema/invoice.ts—unitPricecolumn scale: 2 → 4Note
A database migration will be needed to alter the existing column for deployed instances.