A primary-key column never takes its default

Table of Contents

This page is a capture in the inbox bucket of the product backlog — a pre-sprint idea, not yet pulled into a sprint as a story.

1. What

Carry the :default_value: guard into the primary-key branch of the domain template, so a key column can state an initialiser like every other column can.

2. Why

cpp_domain_type_class.hpp.mustache emits the two shapes differently:

{{#primary_key.columns}}
    {{{cpp_type}}} {{column}};                                       <- no initialiser
{{/primary_key.columns}}
{{#natural_keys}}
    {{{cpp_type}}} {{column}}{{#default_value}} = {{{default_value}}}{{/default_value}};
{{/natural_keys}}

So :default_value: 0 on a primary-key column is silently ignored. Every precedent that works — credit_simulation_config.seed, bond_formula_based_leg_data.fixing_days — is a non-key column.

The consequence is the opposite of what a key needs. An ordinal in a composite key is the field a writer is most likely to forget, because it is metadata about the row rather than data from the document; with no initialiser the forgotten value is an indeterminate int, so the failure is undefined rather than the constraint's refusal.

Found while giving instrument_strikes.sequence_number a default of zero. The model gained the property, regeneration ignored it, and the member stayed bare. Changing this affects every generated key in every component, so it wants its own unit and a regeneration sweep.

3. References

4. See also

Emacs 29.3 (Org mode 9.6.15)