Stamp a new adjustment with the version's own segment name

The loads read ADJUSTMENT_SEGMENT / ADJUSTMENT_BUCKET through VERSION_JOIN,
so pf.version's overrides applied; the rows pushed back incrementally from
scale, recode and clone stamped the built-in constants instead. An
adjustment therefore appeared under '99 - Adjustments' and moved to the
version's own name on the next refresh.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Paul Trowbridge 2026-09-23 09:38:29 -04:00
parent 7d09ab2245
commit 6c26872443

View File

@ -9,6 +9,18 @@ const { fcTable } = require('../lib/utils');
module.exports = function(pool) {
const router = express.Router();
// the names an adjustment's rows carry until the next load re-reads them
// through VERSION_JOIN. The per-version overrides live on pf.version, so
// stamping the built-in constants here made every fresh adjustment show as
// '99 - Adjustments' and jump to the version's own name on refresh.
function adjustmentNames(version) {
const pick = (v, dflt) => (v || '').trim() || dflt;
return {
pf_segment: pick(version?.adjustment_segment, ADJUSTMENT_SEGMENT),
pf_bucket: pick(version?.adjustment_bucket, ADJUSTMENT_BUCKET),
};
}
async function runSQL(sql, client) {
console.log('--- SQL ---\n', sql, '\n--- END SQL ---');
return (client || pool).query(sql);
@ -850,7 +862,8 @@ module.exports = function(pool) {
});
}
const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'scale' }));
const names = adjustmentNames(ctx.version);
const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'scale' }));
res.json({
rows,
rows_affected: rows.length,
@ -923,7 +936,8 @@ module.exports = function(pool) {
});
}
const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'recode' }));
const names = adjustmentNames(ctx.version);
const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'recode' }));
res.json({ rows, rows_affected: rows.length, slices_applied: units.length });
} finally {
if (!committed) try { await client.query('ROLLBACK'); } catch {}
@ -1030,7 +1044,8 @@ module.exports = function(pool) {
});
}
const opLabel = (req.body.tag || '').trim() || note || null;
const rows = allRows.map(r => ({ ...r, pf_segment: ADJUSTMENT_SEGMENT, pf_bucket: ADJUSTMENT_BUCKET, pf_note: opLabel, pf_op: 'clone' }));
const names = adjustmentNames(ctx.version);
const rows = allRows.map(r => ({ ...r, ...names, pf_note: opLabel, pf_op: 'clone' }));
res.json({ rows, rows_affected: rows.length, slices_applied: units.length });
} finally {
if (!committed) try { await client.query('ROLLBACK'); } catch {}