Task: Model the hand-written tables that have a codegen shape

Table of Contents

This page documents a task in the Finish moving the hand-written SQL onto models story. It captures the goal, current status, acceptance, and any notes or results.

1. Goal

Every table a codegen shape covers has a model, so its schema, drop, notify trigger and C++ come from one source.

2. Status

Field Value
State BACKLOG
Parent story Finish moving the hand-written SQL onto models
Now Not yet started.
Waiting on Nothing.
Next Begin implementation.
Last touched 2026-10-15

3. Acceptance

  • Each of the 23 tables with no model is either modelled, with generated SQL identical to the current file or the difference explained, or recorded as staying hand-written with its reason.
  • The census reports the modelled tables as codegen output.

4. Plan

(Implementation strategy. Written when work starts; key decisions are distilled into the parent story's * Decisions at close, but the plan itself stays — it is the historical record of what we did.)

5. Measurements

Every number this task claims about a tree, with the command that produced it and the commit it was measured at. A number without both is not a measurement, because a clean-up record describes a tree and trunk moves under a branch: a consumer count, a gate's component count and a suite's size all change with no code changing, and the reader of a bare number cannot tell which tree it came from. Where the raw output matters, put it in an evidence/ file beside the task and name that file in the Command column.

Whatever creates a table without a model, in projects/ores.sql/create 23 for f in $(grep -rL 'Template: ' projects/ores.sql/create --include'*_create.sql'); do grep -q 'create table if not exists' "$f" && echo "$f"; done wc -l= 9c0b211616
The same census, before the two DQ clean-up tasks 25 as above, at the base of the branch 5e185399d4

6. Notes

From the hand-written SQL census in Find why so much SQL is hand-written and generate what codegen can.

The 25 tables: 18 with no model (junctions such as iam_account_roles, iam_role_permissions, reporting_risk_report_config_books and _portfolios; time series such as iam_auth_events, iam_session_samples and the telemetry samples; DQ publication logs; compute_batch_dependencies, scheduler_job_instances, workspace_trade_scope and others) and 7 DQ artefact staging tables. mq and telemetry are infrastructure and likely stay hand-written; mq_messages holds the only hard REFERENCES in the tree.

6.1. What the two DQ clean-up tasks took off the census

The census is 23 now, not 25. The DQ artefact sharing of it was 7 and is 1.

The one DQ artefact staging table left is dq_ip2country_artefact_create.sql, which waits on its geo store by Model the geo ip2country store.

7. Test Scenarios

Manual QA scenarios (scaffolded via compass add test_scenario) that verify this task. Link new ones here as they're created; the scenario doc itself links back via its "Verifies task" field.

Scenario State Notes
     

8. PRs

PR Title
   

9. Review

Comment summary File Decision Notes
       

10. Result

Emacs 29.3 (Org mode 9.6.15)