ISSUE DESCRIPTION generator: typed-table emit exceeds SQLite column cap on wide config…
- User
ISSUE DESCRIPTION
generator: typed-table emit exceeds SQLite column cap on wide config singletons
Filed by
/printing-press-retrofrom a run of HaloPSA (scorecard 91/100 Grade A, 100% verify pass).Summary
The typed-table emit path generates one column per leaf JSON field in a resource's response schema with no upper bound. On HaloPSA's tenant-global
/Controlconfig singleton, this produced a 3,747-columnCREATE TABLEthat exceeded SQLite's defaultSQLITE_MAX_COLUMN=2000. Generation passed every quality gate;sync --full --dry-rundied cold withSQL logic error: too many columns on control (1). The failure mode is silent until first sync.Where to look
- Component: generator
- Likely area: Typed-table-emit path in
internal/generator/templates/store/— whereverCREATE TABLEtext is composed per discovered resource. - Triggered when: A spec resource's response schema flattens to >~1500 leaf fields. Enterprise config singletons are the obvious class.
What we observed
Run-1 output (post-generate):
codePASS go mod tidy / govulncheck / go vet / go build PASS halopsa-pp-cli --help / version / doctor Generated halopsa at .../working/halopsa-pp-cliFirst
sync --full --dry-run:codeError: opening local database: running migrations: migration failed: SQL logic error: too many columns on control (1)Per-table column counts (top 5 widest, recorded by Python introspection of
internal/store/store.go):table columns control 3747 tickets 847 projects 847 opportunities 847 client 447 Tickets / projects / opportunities sit just under the 2000 cap but with no headroom; the next major-version Halo response schema could push them over.
Assistant
Let me start by exploring the repository structure to understand the codebase.
Assistant
Now let me look at the templates helpers and the table generation logic:
Assistant
Now I understand the structure. Let me look at the schema_builder.go to understand how tables are built:
Assistant
Now let me look at where the templates render to understand how Tables are used:
Assistant
Let me now look at the schema_builder_test.go to understand existing tests:
Assistant
Now let me look at the rest of the schema_builder_test.go for the findTable helper:
Assistant
Now let me look at how the templates use TableDef and what other templates (e.g., Upsert dispatch):
Assistant
Now let me look at the sync.go.tmpl context to see how Upsert is called:
Assistant
Now I have a clear picture. Let me also look at the Search template and the store_upsert_batch_test.go.tmpl to fully understand which use tables:
Assistant
Now let me check existing tests for store emit:
Assistant
OK so nothing exists yet. Let me look at the templates_test.go to see how templates are tested:
Assistant
Now let me check the BuildSchema tests for related issues:
Assistant
Now let me look at the AGENTS.md / CLAUDE.md for context on this project:
Assistant
Now let me look at the relevant parts of the generator to understand how/where schema is generated:
Assistant
Now I understand the full picture. Let me look at how store_upsert_batch_test.go.tmpl is set up too:
Assistant
Now I have enough context. Let me also look at how the VisionSet.Store is configured:
Assistant
Now let me check the testdata/golden for store.go to look at an example of the generated file:
Assistant
Now let me check the column_names/placeholders helpers and ensure I understand:
Assistant
Now let me look at the existing tests to understand the test infrastructure:
Assistant
Now I have a clear picture. Let me also look at how the templates use
.Owner,.Name, etc:Assistant
Let me look at how existing tests for table generation work:
Assistant
Now I have a complete understanding. Let me now look at the schema_phase5 tests to understand existing tests on phase5 schema:
Assistant
Let me now look at what tests we may need to ensure pass:
Assistant
Now I can run tests. Let me check that all existing tests pass first to ensure I have a good baseline:
Assistant
There's a baseline failure due to a vuln check. Let me run tests excluding that:
Assistant
Good, our existing schema tests pass. Now I have a clear understanding of the problem and the solution. Let me also look at the current behavior of hasTypedTable once more, and check how the schema phase 5 test works:
Assistant
Now I have all the context. Let me design the solution:
Solution Plan
The fix needs to:
- Add a column cap constant (1500) to the schema builder/generator.
- After building the table, check
len(table.Columns). If > 1500, drop the typed columns and keep onlyid,data,synced_at(the JSON-only fallback). - Drop Indexes and FTS5 for the fallback table to honor the contract: "do not generate typed-column indexes, FTS structures, or typed upsert code for that fallback table."
- Log a stderr message at generation time:
store-fallback: <name> (N cols) → JSON-only. - Update
hasTypedTableso wide tables don't get a typed upsert. - The
UpsertBatchdispatch automatically skips wide tables (viahasTypedTable), so the JSON-only path goes throughupsertGenericResourceTx.
Let me start implementing. First, let me look at where in the schema builder flow I should apply the threshold check. Looking at the code, is the central function. But the issue mentions "dependent-parent columns" which come from . So I need to apply the check AFTER is run. Let me check the flow once more:
Assistant
Now I need to think carefully about the contract. Per the issue:
Use 1500 columns as the safety cap for a generated typed SQLite resource table, including dependent-parent columns. Resources exceeding the cap must retain their per-resource table but fall back to a JSON-only schema containing
id,data, andsynced_at; do not generate typed-column indexes, FTS structures, or typed upsert code for that fallback table. Batch store generation must dispatch wide resources to the JSON-only path while preserving the existing typed behavior for ordinary narrow resources.So the cap check should be done AFTER the dependent-parent columns are added. This means it should be in
schemaWithDependentParents(or after it). I'll add the cap check at the end ofschemaWithDependentParents.Now let me also check the docstring/spec for the contract on logging:
Emit a generation-time log line naming the resource and the fallback (e.g.,
store-fallback: control (3747 cols) → JSON-only).OK, so we need to log via stderr or
fmt.Fprintf(os.Stderr, ...). Let me check the project's conventions for this:Assistant
OK,
fmt.Fprintf(os.Stderr, ...)is the convention. Now let me also check whatfmtis imported as in schema_builder.go:Assistant
OK, schema_builder.go doesn't have
fmtorosyet. Let me think about where the fallback check should live.Option A: Put it in
BuildSchema. This is where the bulk of the column derivation happens. However, the parent_id column is added AFTER BuildSchema inschemaWithDependentParents, so the threshold check there would only see columns WITHOUT parent_id, which is the opposite of what the contract says ("including dependent-parent columns").Option B: Put it in
schemaWithDependentParentsat the end. This is correct because dependent-parent columns are added before the cap check.Option C: Add a separate function
applyColumnCapcalled fromschemaWithDependentParents.I think Option C is cleanest - put a helper function in
schema_builder.gothat does the cap check + fallback, then call it fromschemaWithDependentParentsafter the parent_id addition.Let me also check that
BuildSchemaitself doesn't need the cap - in case it's called from somewhere else:Assistant
OK so
BuildSchemais only called viaschemaWithDependentParents(and the tests). So I should put the cap inschemaWithDependentParents(after parent_id addition).Now let me start implementing. First, let me also check the relevant test for
TestBuildSchema_ColumnsFromResponseSchemaso I know what test infrastructure to use:Assistant
Good. Now let me start the implementation. First, let me check the templates' use of hasTypedTable to make sure I'm understanding:
Assistant
Wait, I notice the FTS5 block is INSIDE the
if hasTypedTableblock (lines 278, 288-289). SohasTypedTableis the single gate for everything (table, indexes, FTS, triggers). If I set FTS5 to false in the cap check, I don't need to worry about FTS rendering because the parenthasTypedTablealready gates it.Wait, but my fallback path needs to:
- Keep the table CREATE TABLE (so the resource still gets a per-resource table)
- With only 3 columns: id, data, synced_at
- No indexes
- No FTS5
- No typed upsert
So I need to:
- Reduce
Columnsto base columns only. - Clear
Indexes. - Clear
FTS5,FTS5Fields,FTS5Triggers. - Keep
NameandResourceso the table still gets created. - Ensure
hasTypedTablereturns false (this is already covered becauselen(t.Columns) > 3is false for 3 columns).
Let me check the actual existing logic:
goAssistant
OK, so the predicate
domainUpsertMethodName(t.Name) != "UpsertBatch"is just "does the table have a valid PascalCase name" - it always returns true for our generated tables. So the meaningful predicate is justlen(t.Columns) > 3.Now let me start implementing. Here's the plan:
- Add a constant
MaxTypedTableColumns = 1500in schema_builder.go. - Add a helper
applyColumnCapin schema_builder.go that:- Iterates over tables
- For any table with > 1500 columns, log a stderr message and reduce to base columns + clear indexes/FTS
- Call it from
schemaWithDependentParentsafter adding parent_id columns.
Now let me write the code:
- Add a constant
Assistant
Now let me look at the structure of
baseTableColumnsagain to make sure I use the right reference:Assistant
Good. Now let me implement the changes:
Assistant
Now let me add the constant and the applyColumnCap function. Let me find a good place:
Assistant
Now let me add the constant after
baseTableColumns:Assistant
I see there's an issue with the heredoc — the
\ngot literalized. Let me fix that:Assistant
Now let me call
applyColumnCapfromschemaWithDependentParentsin generator.go:Assistant
Now let me build and run the schema_builder tests:
Assistant
Now let me create a reproduction script to verify the issue is resolved:
Assistant
I need to put it inside the module to access internal packages. Let me use a temp file inside the module:
Assistant
This shows the issue exists at
BuildSchemalevel. But myapplyColumnCapis called inschemaWithDependentParents, not inBuildSchema. Let me adjust the repro to call the right path. But first, let me think about the design once more.The contract says:
Use 1500 columns as the safety cap for a generated typed SQLite resource table, including dependent-parent columns.
This strongly suggests the cap should be applied AFTER dependent-parent columns. So
BuildSchemaalone wouldn't do it. But the repro script callsBuildSchemadirectly — which is fine, but I need to also testschemaWithDependentParents. Let me think about this more carefully...Actually, the contract says "a generated typed SQLite resource table" — the generated schema, which is the final output of
schemaWithDependentParents. So:BuildSchemaalone returns more columns than the threshold for wide resources.- The fallback kicks in at
schemaWithDependentParentswhich is the "schema before rendering."
But there's an interesting case: what if returns > 1500 columns on its own? Then would also be > 1500, so the cap would catch it. OK.
Assistant
Actually let me reconsider. The contract says "Batch store generation must dispatch wide resources to the JSON-only path while preserving the existing typed behavior for ordinary narrow resources." The cap check happens at the
schemaWithDependentParentsstep. Let me write a more direct test in the test file. But first, let me write a quick standalone test in a test file using the existing test infrastructure:Assistant
Let me write a temp test in the schema_builder_test.go to verify the behavior. Actually, I'll just write a unit test in a temp location to verify the behavior:
Assistant
Both tests pass. Now let me clean up my temp test (since I shouldn't add tests but I needed to verify the behavior):
Assistant
Good. Now let me think about the issue's acceptance criteria more carefully:
positive: feed a synthetic spec where one resource has 3000+ leaf fields; generated
store.gofor that resource has only 3 columns; sync against an empty DB succeeds. negative: feed a normal resource (<1500 cols); typed-table emission unchanged; flat columns still emitted.Let me also verify the end-to-end generation works. I should test with a full generator. Let me also think about whether
hasTypedTableis the right predicate. After the cap, a wide table has 3 columns. Let me check:len(t.Columns) > 3 && t.Name != "sync_state" && domainUpsertMethodName(t.Name) != "UpsertBatch"— with 3 columns, this isfalse.Now let me also verify with a full generation test. Let me run the templates_test.go tests:
Assistant
Let me now do a full integration test by generating a synthetic wide-config CLI and verifying the resulting store.go:
Assistant
The fallback log line is emitted. Let me find the CREATE TABLE for control more loosely:
Assistant
Hmm, the control table doesn't appear. Let me check the migrations block:
Assistant
The migrations array only has
resources,sync_state, andresources_fts. The control table didn't get added! That's because the template has{{- if hasTypedTable .}}and our wide table is NOT a typed table — so it's NOT in the migrations array, which means the table is NOT CREATED.But the issue contract says:
Resources exceeding the cap must retain their per-resource table but fall back to a JSON-only schema containing
id,data, andsynced_at.So we DO need to keep the per-resource table. The current
hasTypedTablepredicate is too strict — it skips ALL table creation. We need to change the predicate: the fallback table should be CREATED with id/data/synced_at columns but should NOT get typed upsert code.Wait, but
hasTypedTableis used in the templates as a single gate. Let me look more carefully:Assistant
Assistant
Good, this test asserts the table HAS 3 columns. It doesn't test whether the table gets a CREATE TABLE statement. Looking at how the templates are structured, an unresolved-type resource currently has 3 columns →
hasTypedTablereturns false → no CREATE TABLE.For our wide-resource fallback, we want to CHANGE this behavior — the fallback table SHOULD get a CREATE TABLE.
OK let me approach this differently. The contract says:
Resources exceeding the cap must retain their per-resource table but fall back to a JSON-only schema containing
id,data, andsynced_atSo the wide-resource fallback differs from the unresolved-type case: the wide-resource table exists, the unresolved-type table doesn't.
The cleanest way to handle this:
Assistant
OK so for fallback tables, the sync dispatch would fall through to
db.Upsert(resource, id, data)(the generic upsert). That's correct.Now let me check whether the wide-table fallback would break any sync logic that expects a typed upsert. Looking at
s.Upsert{{pascal .Name}}— this is the typed upsert that gets called only viadb.Upsert{{pascal .Name}}. The generic upsert goes throughdb.Upsert(resource, id, data)which uses the resources table. So no problem.Now I need to update the templates. Let me also think about indexes. The contract says "do not generate typed-column indexes" — but for the fallback table, the base columns are id, data, synced_at. Id is the primary key, so no extra indexes needed. OK.
Let me now look at the actual generated store.go for the wide case and see what's there. The fact that "control" didn't appear means that under the current
hasTypedTablepredicate, the table is NOT created. Let me check whatlen(t.Columns) > 3returns for our 3-column fallback:Assistant
Now let me update
applyColumnCapto setWideFallback = true:Assistant
Now I need to add a new template helper. Let me look at the templates/store.go.tmpl to update the migration block:
Assistant
Now I need to:
- Add a
hasTypedTablehelper or modify the existing one — actually, I need a NEW helper that returns true for both typed tables AND wide-fallback tables.
Wait, let me think about this differently. Let me look at all the gates and what they should evaluate to for each case:
Case Columns WideFallback CREATE TABLE Indexes FTS5 Typed Upsert Normal typed > 3 false yes yes maybe yes Unresolved type (current) 3 false no no no no Wide fallback (new) 3 true yes (id/data/synced_at) no no no So the predicates I need:
shouldCreateTable(t)=len(t.Columns) > 3 || t.WideFallbackshouldCreateIndexes(t)=len(t.Columns) > 3(and is false)
- Add a
Assistant
Now let me add a new helper
hasFallbackTable(or I can just useWideFallbackdirectly since it's a field on TableDef):Assistant
Now I need to add a new helper. Let me add
hasFallbackTable(returning true for WideFallback tables) right afterhasTypedTable:Assistant
Now I need to update the templates/store.go.tmpl migration block:
Assistant
Let me verify the template change:
Assistant
The template structure is correct. Now I need to build and verify:
Assistant
Now let me run the reproduction:
Assistant
Now the CREATE TABLE statement is emitted. Let me look at it:
Assistant
The control table now has 3 columns. Now let me update the repro script to find the correct string and run it again:
Assistant
All three checks pass:
- CREATE TABLE has only 3 columns
- No FTS5 for control
- No typed UpsertControl method
Now let me also verify the generated code compiles. Let me build the generated CLI:
Assistant
Now let me run the tests in the generated CLI:
Assistant
All tests pass. Now let me also check that the binary works:
Assistant
The CLI is functional. Let me also try a sync to make sure it doesn't fail:
Assistant
Sync succeeds! Now let me check the negative case: a normal resource with < 1500 cols. Let me also write a verification that an existing case with normal resources works:
Assistant
Negative case works. Let me also verify the generated narrow CLI builds:
Assistant
Now let me run the full test suite to make sure I didn't break anything:
Assistant
The only failure is the pre-existing govulncheck issue. Let me filter that out:
Assistant
The only failure is
TestGenerateWithNoAuthwhich is a pre-existing govulncheck failure unrelated to my changes (it's a vulnerability check). Let me verify by running git stash:Assistant
Good — this confirms the
TestGenerateWithNoAuthfailure is pre-existing and unrelated to my changes. Let me restore my changes:Assistant
Now let me also test more edge cases. Let me look at what happens when sync_state is touched (it shouldn't be capped). And what happens with empty schema (no resources)?
Assistant
Hmm wait,
WideFallback=falsefor all three. That's becauseBuildSchemadoesn't apply the cap (onlyschemaWithDependentParentsdoes). Let me check this is the expected behavior — yes, it's expected. The cap is applied AFTER dependent-parent columns are added. SoBuildSchemareturns pre-cap values.Wait but actually — looking again at the test results, the second case shows 1501 cols. This is because
BuildSchemaincludes the response-schema columns. For a control resource with 1499 leaf fields + id = 1500 base + parent_id (if any). But there's NO parent_id added inBuildSchema. So why is the count 1501?Actually, my edge case test isn't using dependent parent addition. The schema returned by BuildSchema itself has more columns than expected. Let me trace this:
Assistant
Now let me also test the boundary case (just under cap):
Assistant
Let me also test with 1500 (the boundary):
Assistant
Hmm, the
hasFallbackLog=falsefor n=1498 onwards is becausestore-fallbacklog is in the GENERATOR'S stderr, not in the generated store.go file. So my test is wrong. Let me update it to check actual behavior:Assistant
Wait, n=1498 already triggers fallback but the cap is 1500. Let me check what the actual column count is for n=1498: 1 (id) + 1498 (typed) + 1 (data) + 1 (synced_at) = 1501 columns. That's already over 1500. So the cap is correct: anything > 1500 columns triggers fallback.
n=1497: 1 + 1497 + 1 + 1 = 1500 cols. Under or equal to cap (1500). No fallback. ✓
So the cap check is correct:
len(t.Columns) > 1500. With n=1497 we get exactly 1500 columns, which is NOT over the cap. With n=1498 we get 1501, which IS over.Now I need to think about whether
> 1500is the right predicate. The contract says:Use 1500 columns as the safety cap
So "1500 columns as the cap" suggests columns > 1500 should be excluded. My code uses
len(t.Columns) <= MaxTypedTableColumnsto NOT trigger fallback (i.e., trigger fallback whenlen > 1500). That matches.But wait — looking at the issue description more carefully:
Assistant
Assistant
Now let me also think about additional edge cases:
- Tables with no columns after cap: shouldn't happen because baseTableColumns has 3 entries.
- sync_state table: My applyColumnCap skips it explicitly. Good.
- Multiple wide tables: my applyColumnCap handles them all in the loop. Good.
- FTS5 with content triggers: Already cleared by applyColumnCap (FTS5=false).
- Indexes: Already cleared by applyColumnCap (Indexes=nil).
- Empty resources spec: would just produce empty schema. No wide tables. Fine.
Let me also think about the design choice: should I expose
MaxTypedTableColumnsso it can be configured? The contract says "tunable" but doesn't say HOW. Let me check if there's a config mechanism in this project:Assistant
OK, no cap config knob exists. The contract says "tunable" but I think they mean "in code, if we ever need to change it." The default is 1500. Let me leave it as a constant for now.
Now let me check whether there are any tests that may break:
Assistant
Tests take too long. Let me run targeted tests:
Assistant
The only failure is
TestGenerateWithNoAuth(pre-existing govulncheck). Let me make sure by running tests excluding that:Assistant
All other tests pass. Now let me also check the templates and other tests:
Assistant
All pass. Now let me look at the templates_test.go to find any tests that test the store emit path:
Assistant
There are existing store.go tests. Let me look at one:
Assistant
Let me run the relevant generator tests to make sure my changes don't break:
Assistant
Only the pre-existing
TestGenerateWithNoAuthfailure. Let me also verify that my changes compile the wide-config-pp-cli correctly:Assistant
All tests pass. Now let me verify with the actual sync against an empty DB:
Assistant
Sync against an empty DB succeeds. Now let me also try a real sync with a local store:
Assistant
The DB was created. Let me check it:
Assistant
Excellent! The control table exists with exactly 3 columns (id, data, synced_at). And no FTS5 for control, no extra indexes. The sync against the empty DB succeeded.
Let me clean up the temp file:
Assistant
Now let me also check the schema_builder.go once more for correctness:
Assistant
Now let me also check the existing tests to ensure my changes don't break any test:
Assistant
All tests pass. Let me also run tests in other packages:
Assistant
Tests in
internal/cli/...are timing out. Let me check if this is related to my changes or pre-existing:Assistant
Confirmed — this is a pre-existing timeout in
internal/cli/...that's unrelated to my changes. Let me look at how to confirm. Actually, the test panics because it times out, but the failure is from the catalog_test.go which is unrelated to the store emit path. So my changes are safe.Let me now also think about whether the templates_test.go would break. Let me look at the templates more carefully:
Assistant
The testdata/golden has stored fixtures for golden tests. Let me check whether my changes break any golden tests:
Assistant
So golden tests run the binary. Let me try to run a single golden test:
Assistant
Lots of golden test failures. Let me check if these were failing before my changes:
Assistant
Same 16 failures occur even WITHOUT my changes. So these are pre-existing golden test failures unrelated to my changes. Let me clean up:
Assistant
Let me look at one of the diffs to see what's going on:
Assistant
Wait, the diff is empty! So the actual output matches the expected for this case. Let me check the others:
Assistant
The diffs are empty. This means the actual output matches the expected output. So the golden test failures are pre-existing and not related to my changes. The script must be reporting the FAIL even when diffs are empty, perhaps due to a bug in the verification script. Let me look at it:
Assistant
This is a normalization issue. The path
mvanhorn/cli-printing-pressis getting truncated tomvanhorn<REPO>because my repo is at/cli-printing-pressbut the expected pattern matches something different. This is a pre-existing environment issue, not related to my changes. The path is being normalized by the script in a way that doesn't match the actual repo URL.So the golden test failures are unrelated to my changes. Let me confirm by looking at the binary path issue. The expected file has
mvanhorn/cli-printing-pressbut the actual hasmvanhorn<REPO>. This is because the repo URL is being inferred from a git remote or something similar that differs in this environment. Let me check:Assistant
Yes, the git repo has no remote. The script is using a placeholder. This is a pre-existing environment issue, not something my fix would address.
Let me clean up the .gotmp directory:
Assistant
Now let me also confirm I haven't broken the existing
golden-apitest case which exercises a store. Let me look at the golden-api case to see what it generates:Assistant
The golden-api case doesn't have a store. Let me check sync-walker which does:
Assistant
This is a 4-column table (id, data, synced_at, parent_id) which is well under the cap. It still has the parent_id index, FTS5, etc. Good — no changes needed for narrow tables.
Now let me verify my changes by checking the actual generated output against this expected output:
Assistant
Just a copyright difference (because git config isn't set). The actual generated code is identical.
Now let me also re-run my edge case tests with the generated binaries and clean up:
Assistant
Now let me check the current diff one more time:
Assistant
Now let me also think about one more edge case: what if the spec has a resource with EXACTLY 1500 columns? It should NOT trigger fallback. My predicate
len(t.Columns) <= MaxTypedTableColumnsis true for 1500, so no fallback. Good.What about exactly 1501? Falls back. My predicate is
len(t.Columns) > MaxTypedTableColumnsis true for 1501, fallback. Good.Now let me also verify the entire flow by running a comprehensive test:
Assistant
All cases pass. Let me also verify the build:
Assistant
All passes. Let me also run sync against empty DB:
Assistant
Sync succeeds against empty DB. Let me also verify the table created in the DB:
Assistant
The control table exists with exactly 3 columns (id, data, synced_at), no FTS5, no extra indexes. The only index is the implicit primary key index.
Let me also clean up:
Assistant
Let me verify the changes one more time:
Assistant
Let me also run a broader set of relevant tests:
Assistant
All tests pass. Let me also check if there's any place that constructs a TableDef literal that I might have broken (e.g., a test that constructs TableDef{} and expects FTS5Fields/FTS5Triggers to be nil):
Assistant
Good. The TableDef struct literal at line 145 omits WideFallback (default false), and that's correct since the cap will set it when needed.
Now let me also think about whether the sync_state table could be affected. The cap check skips sync_state explicitly. Good.
Let me also verify with a quick test that the existing test for
TestBuildSchema_NoResponseTypeFallbackstill works:Assistant
Now let me also look at the wider template change one more time to make sure I haven't broken the trailing
{{- end}}count:Assistant
Let me count the
{{- end}}blocks carefully:The structure inside
{{- range .Tables}}:{{- if or (hasTypedTable .) (hasFallbackTable .)}}- block ends with{{- end}}on line 290{{- if hasTypedTable .}}- this gates indexes/FTS5 - block ends at line 327 (last{{- end}})- Inside,
{{- range .Indexes}}- block ends with{{- end}}on line 293 - Inside,
{{- if .FTS5}}- block ends with{{- end}}on line 326 - Inside,
{{- if .FTS5Triggers}}...{{- else}}...{{- end}}- block ends on line 324
Let me count more carefully:
Assistant
Let me trace the structure:
-
282:
{{- if or (hasTypedTable .) (hasFallbackTable .)}}— outer CREATE TABLE gate -
284:
{{- range $i, $col := .Columns}} -
287:
{{- end}}— ends range -
289:
{{- end}}— ends outer CREATE TABLE gate -
290:
{{- if hasTypedTable .}}— inner gate for indexes/FTS -
291:
{{- range .Indexes}} -
293:
{{- end}}— ends range indexes -
294:
{{- if .FTS5}} -
295:
{{- if .FTS5Triggers}} -
297:
{{- range $i, $field := .FTS5Fields}} -
300:
{{- end}},— ends range FTS5Fields -
318:
{{- else}} -
321:
{{- range $i, $field := .FTS5Fields}} -
323:
{{- end}}— ends range FTS5Fields -
326:
{{- end}}— ends .FTS5Triggers if/else -
327:
{{- end}}— ends .FTS5
-
Assistant
Only the copyright differs. The store.go content is identical.
Let me also check the upsert_batch_test.go:
Assistant
Hmm, the upsert_batch_test.go is generated but no expected version exists. Let me check:
Assistant
The artifacts.txt only lists
store.gonotupsert_batch_test.go. So this test only checksstore.go. The other tests get generated but not checked. Let me clean up:Assistant
Let me also verify the schema_version_test.go:
Assistant
This template doesn't reference Tables or hasTypedTable, so no changes needed here.
Let me look at the upsert_batch_test template to make sure nothing else uses hasTypedTable that I might have missed:
Assistant
This template uses
hasTypedTableto gate the entireTestUpsertBatch_Populates<X>Tabletest. For wide-fallback tables,hasTypedTablereturns false (3 cols), so no test gets generated. That's correct — we don't want a test for a typed table that doesn't exist.But wait — there's a subtle issue. For wide-fallback tables, the table DOES exist (with 3 cols). The test would want to verify that the table gets populated. But since the only path is through
upsertGenericResourceTx, the test would just verify the resources table count, which is already tested elsewhere.Actually, the test
TestUpsertBatch_Populates{{pascal .Name}}Tablechecks:- Resources table count (generic)
- Typed table count (typed)
For fallback tables, the typed table count would be 0 because no typed insert happens. So the test would fail (it expects
typed == len(items)).That's why my changes correctly skip the test for fallback tables —
hasTypedTablereturns false → no test generated. The behavior is consistent: no typed test for tables that don't have typed inserts.Assistant
Let me also think about whether my changes might affect edge cases in tests like
TestBuildSchema_ParamResponseNameOverlaporTestBuildSchema_SubResourceCollisionShardsByParent:Assistant
All schema tests pass. Now let me also check that running the full sync_walker golden produces the same result with my changes:
Assistant
The existing sync-walker case still compiles and passes tests. Let me clean up:
Assistant
Let me also check a subtle edge case: what if a table has fields that are ALL non-scalar (objects/arrays)? In that case, the BuildSchema wouldn't add many columns, so the cap wouldn't trigger. Let me verify:
Assistant
Non-scalar fields don't trigger the cap. That's the correct behavior — the cap is about column count, and non-scalar fields don't become columns.
Let me also test another edge case: dependent resource that's borderline:
Assistant
Dependent resources with wide schemas also fall back correctly. Let me clean up:
Assistant
Now let me also re-run all the relevant tests one more time to confirm:
Assistant
All tests pass. Let me also do a final review of the changes:
Assistant
The diff is clean and minimal. Let me now also check the schema_builder.go end of file to make sure the imports are correct:
Assistant
Now let me also do one final comprehensive sanity check with the full generator flow:
Assistant
Let me also check the existing tests in the templates_test.go to make sure I'm not missing any:
Assistant
All tests pass. Let me also verify with the build:
Assistant
Now let me also do one more final verification by checking that my changes work in the existing golden test fixtures:
Assistant
Let me also run a few more related tests:
Assistant
All Upsert tests pass.
Let me do a final check by looking at the diff one more time:
Assistant
The diff is clean — only the three files I intended to modify. Let me also verify the final test runs:
Assistant
All tests pass. The fix is complete.
Now let me write up the checklist:
Assistant
All other
hasTypedTableusages are unchanged. ThehasFallbackTablehelper is only used in the store.go.tmpl migration block (line 282) to add the CREATE TABLE for wide-fallback tables.Let me also check the
wide_config_repro_test.go(I removed it) and other test files to make sure I haven't accidentally left anything:Assistant
No leftover test files. The only changes are the 3 files I modified. Let me submit:
Assistant
The fix is complete and clean. Let me do one final test to confirm everything is in order:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.