// derive forecast table name from source tname + version id function fcTable(tname, versionId) { return `pf.fc_${tname}_${versionId}`; } // map information_schema data_type to a clean postgres column type function mapType(dataType, numericPrecision, numericScale) { switch (dataType) { case 'character varying': case 'character': case 'text': return 'text'; case 'smallint': case 'integer': return 'integer'; case 'bigint': return 'bigint'; case 'numeric': case 'decimal': return (numericPrecision) ? `numeric(${numericPrecision}, ${numericScale || 0})` : 'numeric'; case 'real': case 'double precision': return 'numeric'; case 'date': return 'date'; case 'timestamp without time zone': return 'timestamp'; case 'timestamp with time zone': return 'timestamptz'; case 'boolean': return 'boolean'; default: return 'text'; } } module.exports = { fcTable, mapType };