ores.sql.asset_class.codes_populate

Table of Contents

The refdata product taxonomy seed: one insert ... values row per class the catalogue's taxonomy list declares, in display order, carrying the prose the model holds for it. The script is idempotent, as the hand-written one was, and it used to be the copy the whole repository read.

The {{^last}} idiom emits the separating comma on every row but the last, as the sibling SQL archetypes do. {{description_sql}} is the class's prose already folded onto one line and quote-doubled, so a class whose text carries an apostrophe cannot break the literal.

See the Template variable reference for the complete list of available variables and their semantics.

1. Template

The full template source. Edit here and re-tangle with compass build --direct tangle_codegen_templates to regenerate library/templates/sql_asset_class_codes_populate.mustache.

{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.sql.asset_class.org. Edit the org source. }}
{{{sql_license}}}

/**
 * AUTO-GENERATED FILE - DO NOT EDIT MANUALLY
 * Template: sql_asset_class_codes_populate.mustache
 *
 * Asset Class Codes Population Script
 *
 * Populates the top-level asset class classification codes. This table is
 * the source of truth for the taxonomy; no C++ enum mirrors it.
 *
 * Generated from ores.refdata.asset_class_catalogue, which also declares the
 * oresmd market-data namespace and the mapping between the two lists.
 *
 * This script is idempotent - uses INSERT ON CONFLICT.
 */

\echo '--- Asset Class Codes ---'

insert into ores_refdata_asset_class_codes_tbl (
    tenant_id, code, version, name, description, display_order,
    modified_by, performed_by, change_reason_code, change_commentary
)
values
{{#asset_class_catalogue}}
{{#taxonomy}}
    (ores_utility_system_tenant_id_fn(), '{{code}}', 0, '{{name}}',
     '{{description_sql}}',
     {{display_order}}, current_user, current_user, 'system.initial_load', 'Initial population of asset class codes'){{comma}}
{{/taxonomy}}
{{/asset_class_catalogue}}
on conflict (tenant_id, code)
where valid_to = ores_utility_infinity_timestamp_fn()
do nothing;

-- Summary
select 'refdata_asset_class_codes' as entity, count(*) as count
from ores_refdata_asset_class_codes_tbl;

2. See also

Emacs 29.3 (Org mode 9.6.15)