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 understanding the repository structure and the issue. The issue is about a code generator that creates SQLite tables for API resources. When a resource has too many leaf JSON fields (>1500 columns), it should fall back to a JSON-only schema instead of creating a typed table with one column per field.
Let me explore the repository structure first.
Assistant
Let me explore more of the repo structure, particularly focusing on the generator and store packages.
Assistant
Let me look for the store-related templates and generation code.
Assistant
Let me examine the key template file and related generation code.
Assistant
Let me look at the template first to understand the structure.
Assistant
The open command seems to have an issue. Let me try reading the file using bash commands.
Assistant
Let me search for the key CREATE TABLE-related sections in the template.
Assistant
Let me look at the key sections: around lines 220-290 where the CREATE TABLE with columns is emitted.
Assistant
Now let me find where
.Tablesis constructed and passed to the template. Let me look at the generatorAssistant
Let me look at the
TableDefstruct and how schema/tables are builtAssistant
Let me look at the
TableDefstruct definition and theschemaWithDependentParentsfunction.Assistant
Let me search more broadly for
TableDef.Assistant
Let me look at schema_builder.go and also the
schemaWithDependentParentsfunctionAssistant
Now let me look at the
hasTypedTablefunction and how it gates typed table creation, and also examine relevant parts of generator.goAssistant
Now let me understand the full template flow. Let me look at the Upsert section and how tables dispatch.
Assistant
Let me look at how generation logging works and where to add the fallback logic. Let me also check existing
Assistant
Let me look at how
renderStoreFilesworks and how it calls the template.Assistant
Let me look at the UpsertBatch dispatch switch to understand how typed vs generic tables are handled:
Assistant
Let me look at the UpsertBatch function to see how it dispatches:
Assistant
Let me also look at the sync template and the schema_builder_test.go for existing tests:
Assistant
Let me look at the full CREATE TABLE section of the template:
Assistant
Let me look at ALL usages of
hasTypedTablein the template:Assistant
Let me check all templates for
hasTypedTableusageAssistant
Let me check the sync.go.tmpl and store_upsert_batch_test.go.tmpl usages:
Assistant
OK now let me look at the test template:
Assistant
Let me look at the full UpsertBatch dispatch switch and how non-typed resources are handled:
Assistant
Let me first look at how the templates are tested to understand the test infrastructure:
Assistant
Let me look at the template function map in generator.go where
hasTypedTableis defined:Assistant
Let me search for where template functions are assembled:
Assistant
Let me look at the full FuncMap definition to see its extent:
Assistant
Let me see where the FuncMap is defined (line 206):
Assistant
Let me look at
upsertGenericResourceTxin the template:Assistant
Let me look at
upsertGenericResourceTx:Assistant
Let me look at the default
Upsertfunction (for non-typed resources):Assistant
Let me check if the same FuncMap is used for all templates:
Assistant
Let me look at
renderTemplate:Assistant
Let me see the renderTemplate implementation
Assistant
Let me look at the
templatefunction:Assistant
Let me see the template
Assistant
Now I have a thorough understanding. Let me implement the changes. I'll start with `schema_builder.go
Assistant
Let me try the open command in a different way:
Assistant
Let me see the rest of the BuildSchema function
Assistant
Now I'll implement the changes. Let me start with
schema_builder.go:Step 1: Add
JSONOnlyfield toTableDef, add max columns constant, and add the column count check.Assistant
Let me use the proper heredoc syntax:
Assistant
Now let me add
fmtto imports and add theMaxTypedColumnsconstant:Assistant
Now let me add the
MaxTypedColumnsconstant afterbaseTableColumns:Assistant
Now let me add the column count check. Let me see the lines around the append:
Assistant
Now let me add the column count check before appending the table. I'll insert it right before
tables = append(tables, table):Assistant
Now I also need to add the check in
schemaWithDependentParents. Let me look at it:Assistant
I should also add the check in
schemaWithDependentParentsto cover the case where parent_id pushes a table over the limit:Assistant
There seems to be a problem with duplication. Let me check the file around that area:
Assistant
I see the problem - the edit didn't properly replace the old function. Let me see the full extent of the damage
Assistant
I need to fix the duplication. Let me first revert and re-apply the change properly. Let me use git to restore the file
Assistant
Let me re-check the original function:
Assistant
Now let me apply the change properly. I'll replace lines 2441-2472 (from the function declaration to the return)
Assistant
I see there's still an orphaned
return schemaand}. Let me fix that:Assistant
Let me see the exact state around lines 2490-2495:
Assistant
I see an extra
}on line 2492. Let me fix it:Assistant
Now let me add the
isJSONOnlytemplate function. Let me find where to add it in the FuncMap:Assistant
Now let me modify the store.go.tmpl template. Let me first look at the exact section where I need to add the JSON-only CREATE TABLE (after the hasTypedTable block):
Assistant
Let me look at the Upsert section:
Assistant
Now let me implement the template changes. First, let me add the JSON-only CREATE TABLE in store.go.tmpl. I'll add it after the
hasTypedTableblock:Assistant
The template syntax is causing issues with the heredoc. Let me use
replaceinstead:Assistant
Let me look at the exact lines more carefully:
Assistant
Let me get exact line numbers:
Assistant
Now I understand the structure. Let me add the JSON-only CREATE TABLE between lines 322 (closes
hasTypedTable) and 323 (closesrange .Tables):Assistant
Let me use sed directly to make the change:
Assistant
Let me verify the change:
Assistant
Good. Now let me add the JSON-only Upsert. Let me find the current location:
Assistant
Let me look at the Upsert section around line 797:
Assistant
Now let me add the JSON-only Upsert between the
hasTypedTable{{- end}}andrange .Tables{{- end}}:Assistant
Let me use a Python script for all the template changes at once:
Assistant
Now let me update the UpsertBatch section. Let me find the new line numbers:
Assistant
Let me look at the UpsertBatch section around the dispatch switch:
Assistant
Let me update the UpsertBatch section with the Python script:
Assistant
Let me verify the UpsertBatch changes:
Assistant
There's a problem - the JSON-only block is outside the
range .Tablesloop. Let me check the exact line numbers and fix:Assistant
I need to move the JSON-only block inside the
range .Tablesloop. Let me fix:Assistant
Let me verify:
Assistant
Now let me update the
sync.go.tmpltemplate. Let me look at the dispatch:Assistant
I need to add a JSON-only case in the sync dispatch. Let me find the exact line numbers:
Assistant
Let me find the specific lines in sync.go.tmpl:
Assistant
Let me add the JSON-only dispatch in sync.go.tmpl:
Assistant
Let me use Python to insert the JSON-only block:
Assistant
Now let me check the test template:
Assistant
Let me check how
$hasTypedis used in the testAssistant
Let me update the test template to include JSON-only in the
$hasTypedcheck:Assistant
Now let me try to build and run tests to verify everything compiles:
Assistant
Let me check Go setup:
Assistant
Let me set up Go module cache:
Assistant
Let me wait for the build to
Assistant
Let me set GOCACHE as well:
Assistant
Build succeeded. Now let me run the relevant tests:
Assistant
Let me run all generator tests:
Assistant
Let me check if these test failures are pre-existing:
Assistant
Let me restore my changes and investigate:
Assistant
Let me check the FuncMap around my changes:
Assistant
Let me search for pathContainsParam in generator.go:
Assistant
I accidentally removed
pathContainsParam! Let me check the original:Assistant
I need to restore
pathContainsParam. Let me fix thisAssistant
Let me check the state of generator.go:
Assistant
Let me revert the accidental edit to store.go.tmpl and fix generator.go:
Assistant
Now fix generator.go - add
pathContainsParamback and keep `isJSONOnlyAssistant
Now I need to re-apply the template changes since I reverted store.go.tmpl. Let me apply all template changes:
Assistant
Let me verify the build and tests:
Assistant
Let me run the tests again:
Assistant
Let me run the full generator test suite:
Assistant
Let me check if this test failure is pre-existing:
Assistant
Good, that's a pre-existing failure. Let me restore my changes and run the schema builder tests:
Assistant
Let me now write a quick test to verify the JSON-only fallback logic:
Assistant
Let me write a proper test file inside the generator package:
Assistant
All new tests pass. Let me also run a broader set of tests to make sure nothing is broken
Assistant
All tests pass. Let me clean up the temporary test file and do a final review:
Assistant
Let me do a final review of all changes:
Assistant
Let me see the full diff:
Assistant
I see a duplication issue in sync.go.tmpl. Let me fix it:
Assistant
Let me fix the duplicate:
Assistant
Let me use Python to fix:
Assistant
Let me verify:
Assistant
Let me verify store.go.tmpl for similar issues:
Assistant
Let me verify the store.go.tmpl Upsert section:
Assistant
This looks correct. Let me run the final build and tests:
Assistant
Let me clean up the temporary file and run a broader test:
Assistant
All tests pass. Let me do a final review of the complete diff:
Assistant
The diff looks correct. Let me now go through the checklist:
Checklist review:
-
Reproduce the error: I couldn't reproduce the exact error (SQLite column limit) since the repo is the code generator, not a generated CLI. But I verified the behavior by writing tests that confirm:
- A resource with 3000+ fields correctly gets
JSONOnly = trueand only 3 columns (id, data, synced_at) - Normal resources (<1500 cols) keep their typed columns
- The fallback log message is printed correctly
- A resource with 3000+ fields correctly gets
-
Confirm the fix resolves the error: My fix prevents the generator from emitting CREATE TABLE with >1500 columns. Resources exceeding the threshold fall back to JSON-only schemas with exactly 3 columns, well under SQLite's 2000-column limit. The generated code will no longer fail with "too many columns".
-
Edge cases:
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.