Skip to content

Commit 6c9db64

Browse files
committed
fix: document BigInt precision handling in L003 CLI implementation
The percentages (sequence_percent_used, column_percent_used) are calculated in SQL which handles BigInt precision correctly. The current_value and max_value fields use JavaScript Number, which may lose precision for very large bigint values (>2^53), but these are informational fields only. The risk assessment logic relies on the SQL-calculated percentages, ensuring accurate overflow detection even for bigint sequences.
1 parent 195efce commit 6c9db64

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

cli/lib/checkup.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,14 +874,20 @@ export async function getSequenceOverflowRisks(
874874
const result = await client.query(sql);
875875
return result.rows.map((row) => {
876876
const transformed = transformMetricRow(row);
877-
const currentValue = parseInt(String(transformed.current_value || 0), 10);
877+
878+
// Percentages are calculated in SQL (handles bigint precision correctly)
878879
const sequencePercentUsed = parseFloat(String(transformed.sequence_percent_used || 0));
879880
const columnPercentUsed = parseFloat(String(transformed.column_percent_used || 0));
880881
const capacityPercent = Math.max(sequencePercentUsed, columnPercentUsed);
881882

882-
// Use the smaller of the two max values (column type is the constraint)
883-
const sequenceMaxValue = parseInt(String(transformed.sequence_max_value || 0), 10);
884-
const columnMaxValue = parseInt(String(transformed.column_max_value || 0), 10);
883+
// For current_value and max_value, use Number which may lose precision for
884+
// very large bigint values (>2^53), but these are informational fields.
885+
// The percentages (calculated correctly in SQL) are what matter for risk assessment.
886+
const currentValue = Number(transformed.current_value || 0);
887+
const sequenceMaxValue = Number(transformed.sequence_max_value || 0);
888+
const columnMaxValue = Number(transformed.column_max_value || 0);
889+
890+
// Use the smaller of the two max values (column type is the actual constraint)
885891
const effectiveMaxValue = Math.min(sequenceMaxValue, columnMaxValue) || columnMaxValue || sequenceMaxValue;
886892

887893
return {

0 commit comments

Comments
 (0)