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):
PASS 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:Error: 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.
Workaround applied this run: hand-stripped
/Control*paths from the spec (5 paths) and added a stubControlschema so residual$reftargets resolved. Regenerated successfully.Suspected root cause
Assistant
Let me start by exploring the repository structure to understand the codebase and find the relevant files related to the typed-table-emit path mentioned in the issue.
The issue states:
- The typed-table emit path generates one column per leaf JSON field in a resource's response schema with no upper bound
- This caused a 3,747-column CREATE TABLE that exceeded SQLite's default SQLITE_MAX_COLUMN=2000
- The fix should check column count before writing CREATE TABLE and if it exceeds 1500, fall back to JSON-only schema
- The fix should be in
internal/generator/templates/store/
Let me first explore the repository structure.
Assistant
Let me explore the generator directory structure to find the store template files:
Assistant
Now let me look at the templates directory mentioned in the issue:
Assistant
Let me explore the store templates directory:
<tool_call> <function=bash_terminal> <parameter=command> ls -la /cli-printing-press/internal/generator/templates/store/ 2>/dev/null || find /cli-printing-press/internal/generator/templates -name "store" </tool_call>
Assistant
Let me search for store-related template files more effectively.
Assistant
Let me look at the store.go file and find where the CREATE TABLE is generated:
<tool_call> <function=bash_terminal> <parameter=command> grep -r "CREATE TABLE" /cli-printing-press/internal/generator/ --include=".tmpl" --include=".go" | head -20 </tool_call>
Assistant
Let me properly run the grep command to find CREATE TABLE occurrences.
Assistant
Now I found that
store.go.tmplis the template file that generates CREATE TABLE statements. Let me look at that file to understand how tables are created:<tool_call> <function=bash_terminal> <parameter=command> cat /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to use the proper tool call format for commands. Let me read the store.go.tmpl file.
Assistant
The file was truncated. Let me look at more of this file, especially around where CREATE TABLE is generated for resource tables.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "CREATE TABLE" /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to use the proper format for the bash_terminal command. Let me try again.
Assistant
Now let me look at the area around line 279 where the CREATE TABLE for resource tables is generated:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '270,380p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
Let me try again with the proper format for running shell commands.
Assistant
Now I need to understand how tables are generated. Let me look at the generator.go file to see how the table structure is built:
Assistant
I see that there's a template function
hasTypedTabledefined at line 408-409 in generator.go. It checkslen(t.Columns) > 3to decide if a table gets typed columns. The issue mentions that we need to limit the column count to 1500 before generating the CREATE TABLE.Let me look at more of the template function definition and understand how
hasTypedTableis used:<tool_call> <function=bash_terminal> <parameter=command> sed -n '400,450p' /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me properly run the bash command using the tool format.
Assistant
Now I can see that the
hasTypedTablefunction checkslen(t.Columns) > 3to determine whether to create a typed table. The issue is that there's no upper bound - tables with thousands of columns would be created.Let me also look at how TableDef is structured and how columns are added:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "type TableDef|type ColumnDef" /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me find where the TableDef type is defined.
Assistant
Let me search in the entire generator directory for TableDef and ColumnDef type definitions.
Assistant
Now let me look at the schema_builder.go file to understand the structure:
<tool_call> <function=bash_terminal> <parameter=command> cat /cli-printing-press/internal/generator/schema_builder.go </tool_call>
Assistant
I need to run bash commands properly. Let me read the schema_builder.go file to understand the structure.
Assistant
Now I understand the structure. The
TableDefhas aColumnsslice that includes the base columns (id, data, synced_at) plus any extracted scalar fields. The issue is that when there are too many columns (>1500), the CREATE TABLE will fail.Looking at the code:
- In
schema_builder.go,BuildSchemabuilds the table definitions by adding scalar fields as columns - In
generator.go, thehasTypedTablefunction decides if a table gets typed columns:len(t.Columns) > 3 - In
store.go.tmpl, the CREATE TABLE is generated for tables wherehasTypedTablereturns true
The fix should:
- Change the
hasTypedTablefunction to also check iflen(t.Columns) <= 1500 - Ensure that when the table falls back to JSON-only, it only has the 3 base columns (id, data, synced_at)
- Add a log message when falling back
Let me also check how the UpsertBatch dispatch works to ensure wide resources use the JSON-only path:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "UpsertBatch" /cli-printing-press/internal/generator/templates/*.tmpl | head -20 </tool_call>
- In
Assistant
I need to look at the UpsertBatch dispatch to understand how it routes to different tables. Let me check the sync.go template.
Assistant
Now let me look at the UpsertBatch function in store.go.tmpl to see how it dispatches to typed insert vs JSON:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '930,1050p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
Let me try the bash command again to view the UpsertBatch function.
Assistant
Now I understand the structure. The key issue is:
hasTypedTabledetermines if a table gets typed columns- If
hasTypedTablereturns true, the table will be created with typed columns and FTS5 indexes - If
hasTypedTablereturns false (or when the column count exceeds 1500), the table should be JSON-only with justid,data, andsynced_at
Now let me look at how the migration in store.go.tmpl handles the table creation. Let me look at more of the migration code:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '270,300p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
Let me try the command again to view the migration code in store.go.tmpl.
Assistant
Let me understand the structure better. I need to see how
hasTypedTableis used and how the table creation decision is made:Assistant
Now I understand the problem clearly. The issue is:
- The
hasTypedTabletemplate function ingenerator.goonly checkslen(t.Columns) > 3 - This means tables with thousands of columns (like the 3747 column
controltable) still get typed CREATE TABLE statements - SQLite has a limit of 2000 columns, and the fix should gate on 1500 to leave headroom
The fix should be:
- Modify
hasTypedTableingenerator.goto also checklen(t.Columns) <= 1500 - When
hasTypedTablereturns false for wide tables, the table will fall back to having only the 3 base columns (id, data, synced_at) sincehasTypedTablegates both table creation and typed upsert
Let me also check if there's a log message requirement. Looking at the issue description again:
Emit a generation-time log line naming the resource and the fallback (e.g.,
store-fallback: control (3747 cols) → JSON-only).This means we need to add some logging when a table falls back. Let me look at how logging happens during generation in the generator:
- The
Assistant
Let me look for logging patterns in the generator.go file to understand how logs are emitted during generation.
Assistant
No logging found there. Let me search more broadly in the generator for logging patterns:
Assistant
Let me check the issue description again. It says "Emit a generation-time log line naming the resource and the fallback". This would need to be done in the generator.go file when rendering the store files, likely in the
renderStoreFilesfunction or when callingBuildSchema.Let me look at the renderStoreFiles function to understand how tables are rendered:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2470,2520p' /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me look at the renderStoreFiles function to understand how tables are rendered.
Assistant
Assistant
Let me properly view the migration template code to understand the full structure before making changes.
Assistant
Assistant
Let me view the hasTypedTable function in generator.go to understand its current structure before modifying it.
Assistant
Now I understand the structure. I need to:
- Add a constant for the column threshold (1500)
- Modify
hasTypedTableto also checklen(t.Columns) <= 1500 - Add a new template function
isWideTablethat returns true if columns > 1500 - Update the migration template in
store.go.tmplto emit a 3-column table for wide tables - Add logging when a table falls back to JSON-only
Let me start implementing the fix. First, I'll add the constant and modify the template functions in generator.go:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "const|var " /cli-printing-press/internal/generator/generator.go | head -30 </tool_call>
Assistant
Let me find where constants are defined in generator.go to add the column threshold constant.
Assistant
I need to add a constant for the column threshold and modify the template functions. Let me find a good place to add the constant and understand the file structure better.
Let me look at the beginning of generator.go to understand where to add constants:
Assistant
Let me find the exact location where template functions are defined:
Assistant
Now I understand the structure. Let me implement the fix by:
- Adding a constant for the column threshold (1500)
- Modifying
hasTypedTableto check the column count - Adding a new template function
isWideTable - Updating the migration template to handle wide tables with JSON-only schema
- Adding logging when a table falls back
Let me first add the constant and modify the template functions in generator.go:
Assistant
Let me add a constant for the column threshold after the templateFS variables. Then I'll modify the template functions. First, let me find a good place to add the constant:
Assistant
Now let me implement the fix. I'll:
- Add a constant for the column threshold (1500) after line 38 (after
var TemplateFS = templateFS) - Modify the
hasTypedTabletemplate function to check column count <= 1500 - Add a new template function
isWideTablethat returns true if columns > 1500 - Add logging when a table falls back to JSON-only
Let me start by modifying the generator.go file:
- Add a constant for the column threshold (1500) after line 38 (after
Assistant
Now let me apply the patch by editing the generator.go file directly. I'll first add the constant after line 38:
Assistant
I need to add the constant after line 38. Let me use the edit command to add it.
Assistant
Now let me verify the constant was added correctly:
Assistant
The constant was added. Now I need to:
- Modify the
hasTypedTablefunction to check column count <= SQLiteColumnThreshold - Add the
hasWideJSONTabletemplate function
First, let me find the current line number of the
hasTypedTablefunction (it has shifted due to the added constant):- Modify the
Assistant
Now let me view the hasTypedTable function and the area around it:
Assistant
Now let me modify the
hasTypedTablefunction and addhasWideJSONTable:Assistant
Let me verify the changes were applied correctly:
Assistant
Now I need to update the store.go.tmpl template to handle wide tables with JSON-only schema. Let me look at the migration template section again to understand what needs to be changed:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '274,330p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to view the migration template section to understand what needs to be changed. Let me do that again.
Assistant
Now I understand the structure. I need to add a new block to handle wide tables with JSON-only schema. The current structure is:
{{- range .Tables}} {{- if hasTypedTable .}} CREATE TABLE ... (typed columns) CREATE INDEX ... CREATE FTS5 ... {{- end}} {{- end}}I need to add an
else if hasWideJSONTable .block that creates a 3-column JSON-only table. Let me modify the template:<tool_call> <function=bash_terminal> <parameter=command> sed -n '274,325p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to view and edit the template file. Let me use sed to view the relevant section of the migration template first.
Assistant
I need to modify the migration template in store.go.tmpl to add support for wide tables with JSON-only schema. The current structure ends the migration loop at line 320 with
{{- end}}. I need to add an else clause after{{- if hasTypedTable .}}to handle wide tables.Let me first understand the exact line structure. Looking at the output:
- Line 274:
{{- range .Tables}} - Line 275-278: Comment about gating
- Line 279:
{{- if hasTypedTable .}} - Line 280-284: CREATE TABLE for typed columns
- Line 285-287: CREATE INDEX
- Line 288-320: FTS5 creation and triggers
- Line 321-322: Closing braces for the range loop
I need to add an
else if hasWideJSONTable .block after the typed table block. The new block should create a 3-column JSON-only table with id, data, and synced_at.Let me modify the template to add this else clause:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '318,325p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
- Line 274:
Assistant
Let me view the end of the migration table creation section to find where to add the else clause for wide tables.
Assistant
Now I understand the structure. The migration string ends at line 323 (the closing
}of the migrations array). I need to add an else clause after the{{- if hasTypedTable .}}block to handle wide tables.The structure is:
{{- range .Tables}} {{- if hasTypedTable .}} ... typed table creation ... {{- end}} {{- end}}I need to change it to:
{{- range .Tables}} {{- if hasTypedTable .}} ... typed table creation ... {{- else if hasWideJSONTable .}} ... JSON-only table creation ... {{- end}} {{- end}}Let me find the exact line numbers and make the modification:
<tool_call> <function=bash_terminal> <parameter=command> grep -n '{{- end}}' /cli-printing-press/internal/generator/templates/store.go.tmpl | head -30 </tool_call>
Assistant
Let me look at the migration template to understand the exact structure and then add the else clause for wide tables.
Assistant
Now I can see the structure. Lines 320-323 close the range loop. I need to add an else clause after the
{{- if hasTypedTable .}}block. The{{- if hasTypedTable .}}is at line 279, and the closing brace for the range is at line 323.Let me look at the exact structure again and figure out where to add the else clause:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '315,325p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to use the proper format to run the bash command. Let me try again with the tool format.
Assistant
Now I can see the structure. I need to add the else clause for wide tables. The
{{- end}}at line 321 closes the FTS5 block, line 322 closes the table block, line 323 closes the range loop.I need to add an
else if hasWideJSONTable .block between the typed table creation and the closing braces. Let me replace lines 320-322 (the closing braces for FTS5 and the table) with a block that includes the else clause.Actually, let me look at the exact structure to understand where to place the else clause. The structure is:
- Line 279:
{{- if hasTypedTable .}}- start of typed table block - Lines 280-319: Various CREATE statements for typed table
- Line 320:
{{- end}}- ends FTS5 conditional - Line 321:
{{- end}}- ends the table block (closes theif hasTypedTable) - Line 322:
{{- end}}- another closing brace (probably for the migrations array or something else) - Line 323:
{{- end}}- ends the range loop
Wait, looking at line 322, there are two
{{- end}}before the range loop ends. Let me check the structure more carefully:- Line 279:
Assistant
Let me understand the nesting:
- Line 279:
{{- if hasTypedTable .}}- opens typed table block - Line 288:
{{- if .FTS5}}- opens FTS5 block - Line 289-316: FTS5 content
- Line 317:
{{- else}}- FTS5 else - Line 318-320: FTS5 else content
- Line 321:
{{- end}}- closes FTS5 (line 288) - Line 322:
{{- end}}- closes typed table (line 279) - Line 323:
{{- end}}- closes migrations array (or something else) - Line 324:
{{- end}}- closes range loop (line 274)
- Line 279:
Assistant
Let me view the closing braces more carefully to understand the exact structure.
Assistant
I can see there are 4 closing braces at lines 320-323. Let me trace through the structure more carefully:
Looking at the template:
migrations := []string{ ... {{- range .Tables}} <- line 274 {{- if hasTypedTable .}} <- line 279 CREATE TABLE... {{- range .Indexes}} {{- end}} <- line 287 (closes indexes range) {{- if .FTS5}} <- line 288 CREATE FTS5... {{- end}} <- line 320 (closes FTS5) {{- end}} <- line 321 (closes typed table if) {{- end}} <- line 322 (closes range) ... }Wait, that doesn't match. There are 4 closing braces but I only see 2 conditional closures. Let me look at the actual content more carefully to understand the nesting.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '274,325p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
Let me view the complete migration section from lines 274 to 325 to understand the exact structure.
Assistant
Now I understand the structure better. The closing braces are:
- Line 320:
{{- end}}- closes{{- if .FTS5}}(line 288) - Line 321:
{{- end}}- closes{{- if hasTypedTable .}}(line 279) - Line 322:
{{- end}}- closes{{- range .Tables}}(line 274) - Line 323:
{{- end}}- actually this is part of the migrations array definition
Wait, looking at line 323, it seems like there's an extra closing brace. Let me trace through the structure:
{{- range .Tables}}at line 274{{- if hasTypedTable .}}at line 279{{- range $i, $col := .Columns}}at line 280{{- range .Indexes}}at line 285{{- if .FTS5}}at line 288{{- if .FTS5Triggers}}at line 289- Various content with nested ranges
{{- else}}at line 317- FTS5 else content
{{- end}}at line 320 - closes (line 288)
- Line 320:
Assistant
Let me view the exact lines to understand the closing brace structure.
Assistant
Let me check the context around these lines to understand what each closing brace corresponds to.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '315,330p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to run the bash command properly. Let me try again with the tool format.
Assistant
Now I see the structure more clearly. The 4 closing braces at lines 320-323 are:
- Line 320:
{{- end}}- closes{{- if .FTS5}} - Line 321:
{{- end}}- closes{{- if hasTypedTable .}} - Line 322:
{{- end}}- closes{{- range .Tables}} - Line 323:
{{- end}}- this seems like it might close something else
Wait, looking at the migrations array structure, it seems like:
migrations := []string{ `CREATE TABLE IF NOT EXISTS resources (...)`, `CREATE TABLE IF NOT EXISTS sync_state (...)`, resourcesFTSCreateSQL, {{- range .Tables}} {{- if hasTypedTable .}} ... CREATE TABLE and related statements ... {{- end}} {{- end}} }So the closing
}is at line 324. The{{- end}}at line 323 must be closing the migrations array itself, but that doesn't make sense. Let me check the context before line 274:<tool_call> <function=bash_terminal> <parameter=command> sed -n '268,276p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
- Line 320:
Assistant
Let me view the context before the range to understand the migrations array structure.
Assistant
Now I understand. The migrations array starts before this and ends after line 324. The structure is:
migrations := []string{ `CREATE TABLE IF NOT EXISTS resources (...)`, `CREATE TABLE IF NOT EXISTS sync_state (...)`, resourcesFTSCreateSQL, {{- range .Tables}} {{- if hasTypedTable .}} ... statements ... {{- end}} {{- end}} }So line 323
{{- end}}closes the{{- range .Tables}}(line 274), and line 324}closes the migrations array.Wait, but there are 4
{{- end}}at lines 320-323. Let me re-check the actual line numbers from the earlier output:From the earlier output:
317:{{- end}} 320:{{- end}} 321:{{- end}} 322:{{- end}} 323:{{- end}}So line 317 is the
{{- else}}closing the{{- if .FTS5Triggers}}. Line 320 closes the{{- if .FTS5}}. Line 321 closes the{{- if hasTypedTable .}}. Line 322 closes the{{- range .Tables}}. Line 323... let me check what this is.Assistant
Let me understand the structure now. I'll create the necessary modifications.
Looking at the code:
- Line 279:
{{- if hasTypedTable .}}opens typed table block - Line 288:
{{- if .FTS5}}opens FTS5 block - Line 289:
{{- if .FTS5Triggers}}opens triggers block - Line 317:
{{- else}}is for FTS5Triggers - Line 320:
{{- end}}closes FTS5 - Line 321:
{{- end}}closes typed table if - Line 322:
{{- end}}closes range - Line 323:
{{- end}}- this must be closing something else, or there's an extra one
Let me check what's at line 288 to understand the nested conditionals:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '286,292p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
- Line 279:
Assistant
I need to view the FTS5 section to understand the nested conditionals.
Assistant
Now I understand the structure:
- Line 287:
{{- end}}closes{{- range .Indexes}} - Line 288:
{{- if .FTS5}}opens FTS5 block - Line 289:
{{- if .FTS5Triggers}}opens triggers block - Lines 290-315: Triggers content
- Line 316:
{{- end}}closes{{- if .FTS5Triggers}} - Line 317:
{{- else}}for FTS5Triggers - Lines 318-319: FTS5Triggers else content
- Line 320:
{{- end}}closes{{- if .FTS5}} - Line 321:
{{- end}}closes{{- if hasTypedTable .}} - Line 322:
{{- end}}closes
- Line 287:
Assistant
Now I understand the base columns. For wide tables, I need to emit a 3-column table with:
- id TEXT PRIMARY KEY
- data JSON NOT NULL
- synced_at DATETIME DEFAULT CURRENT_TIMESTAMP
Now let me create the modification to the store.go.tmpl template. I'll:
- Change line 321 from
{{- end}}to{{- else if hasWideJSONTable .}} - Add the wide table creation content after line 321
- Add
{{- end}}for the wide table block before the range closing brace
Actually, let me look at the current structure again. The line 321 closes the
{{- if hasTypedTable .}}block. If I change it to{{- else if hasWideJSONTable .}}, I need to:- Add the wide table content
- Add
{{- end}}to close the wide table block - Keep the range closing brace
Let me view the exact lines around 320-324 to understand where to place the changes:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '318,326p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to view the exact lines around 318-326 to understand where to place the changes. Let me do that.
Assistant
I'll proceed with modifying the template file to add support for wide tables with JSON-only schema. Let me use the edit command to make the changes.
<tool_call> <function=bash_terminal> <parameter=command> sed -i '321s/{{- end}}/{{- else if hasWideJSONTable .}}/' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to use the proper format for running bash commands. Let me try again with the correct tool format.
Assistant
The sed command completed successfully. Let me verify the change was applied correctly.
Now I need to add the wide table creation content after the else clause and add the closing brace. Let me first check the current state of the file around line 321.
Assistant
The else clause was added at line 321, but now I need to add the wide table creation content between lines 321 and 322 (before the closing brace). I also need to add a closing brace for the else block before the range closing brace.
Let me use the edit command to add the wide table content. I'll add the content after line 321 (the else clause) and before line 322 (the closing brace).
Assistant
Let me verify the changes were applied correctly.
I need to verify the changes were applied correctly to the store.go.tmpl file.
Assistant
The template was updated successfully. Now I need to add logging when a table falls back to JSON-only. Looking at the issue description:
Emit a generation-time log line naming the resource and the fallback (e.g.,
store-fallback: control (3747 cols) → JSON-only).This should be done during generation, not at runtime. I need to add logging in the
renderStoreFilesfunction in generator.go when a table falls back to JSON-only.Let me find the renderStoreFiles function and add the logging there.
I need to add logging when a table falls back to JSON-only. Let me find the renderStoreFiles function in generator.go and add the logging there.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "func (g *Generator) renderStoreFiles" /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me find the renderStoreFiles function in generator.go and add logging for wide table fallback.
Assistant
Let me view the renderStoreFiles function to understand how to add logging for wide table fallback.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2487,2530p' /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
Let me view the renderStoreFiles function to understand how to add logging for wide table fallback.
Assistant
Now I need to add logging for wide table fallback. I'll modify the
renderStoreFilesfunction to log when a table falls back to JSON-only. Let me add this logging before rendering the template.Assistant
Let me verify the logging was added correctly.
I need to verify the logging was added correctly to the generator.go file.
Assistant
The logging was added. Now let me verify the code compiles correctly by running
go build:Assistant
I need to set up the Go module cache first. Let me try running go mod tidy and then build:
Assistant
Let me set up the Go environment properly:
Assistant
The go mod tidy command seems to be running. Let me wait for it to complete and then try building again.
Assistant
Let me set up more environment variables:
Assistant
The build succeeded. Now let me run the tests to make sure the changes don't break anything:
Assistant
The tests mostly passed, with only one failure related to
govulncheckfinding a vulnerability in the Go standard library (which is unrelated to our changes). The actual generator tests passed.Now let me verify that my changes work correctly by creating a test case. First, let me look at the existing tests to see how they test the store generation:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "hasTypedTable|wide|threshold|1500" /cli-printing-press/internal/generator/generator_test.go | head -20 </tool_call>
Assistant
Let me search for how the tests verify the store generation to understand how I can verify my changes work correctly.
Assistant
Let me search for tests that specifically test the store generation and table creation to understand how I can verify my changes:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "CREATE TABLE|typed.*table|wide|1500|column" /cli-printing-press/internal/generator/generator_test.go | head -30 </tool_call>
Assistant
Let me search for tests that specifically test the store generation and table creation to understand how I can verify my changes work correctly.
Assistant
Let me search for tests that specifically test the store generation with specific column counts or wide tables:
Assistant
Let me create a test script to verify that my changes work correctly. First, let me look at how tests create synthetic specs:
Assistant
Let me look at one of the simpler test cases to understand the test structure:
Assistant
I see the test structure. Let me create a simple test to verify the wide table fallback works correctly. I'll create a test that generates a spec with a wide resource (>1500 columns) and verify that the generated store.go contains the JSON-only schema for that resource.
Let me first look at how synthetic specs are created in tests:
Assistant
Let me look at how specs are created with specific resources to understand how I can create a test with a wide resource:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "APISpec|Resource|TypeField" /cli-printing-press/internal/generator/generator_test.go | head -40 </tool_call>
Assistant
Let me search for how specs are created in tests:
Assistant
Let me look at how to create a spec with a wide resource. Let me examine a specific test that creates a spec:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '711,780p' /cli-printing-press/internal/generator/generator_test.go </tool_call>
Assistant
Let me view how a spec is created in the tests to understand the structure better.
Assistant
Now I understand the structure. I need to create a test that generates a spec with a resource that has many (>1500) TypeFields to trigger the wide table fallback. Let me also verify that the code compiles and the existing tests still pass.
Let me first verify that the build still works:
<tool_call> <function=bash_terminal> <parameter=command> cd /cli-printing-press && go build ./... 2>&1 | head -20 </tool_call>
Assistant
The build succeeded. Let me also run a quick test to verify the changes work correctly. I'll write a simple test script that creates a spec with a wide resource and checks if the generated store.go contains the JSON-only schema.
Let me first look at what the acceptance criteria are:
- positive: feed a synthetic spec where one resource has 3000+ leaf fields; generated store.go for 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 create a simple test to verify this works.
Assistant
The build succeeds. Now let me verify the changes by looking at the key parts of the code:
Assistant
The changes are in place. Let me verify the template changes as well:
Assistant
The template changes are in place. Let me verify the complete wide table section:
Assistant
The template looks correct. Now let me verify the logging message format matches what's expected:
<tool_call> <function=bash_terminal> <parameter=command> sed -n '2505,2515p' /cli-printing-press/internal/generator/generator.go </tool_call>
Assistant
I need to verify the logging message format. Let me check the exact line.
Assistant
The logging message looks correct. It matches the format specified in the issue:
store-fallback: control (3747 cols) → JSON-only.Now let me create a simple test script to verify that the fix works correctly. I'll create a synthetic spec with a wide resource and check if the generated store.go contains the JSON-only schema for that resource.
Let me first check the structure of the spec package to understand how to create a spec with many fields:
<tool_call> <function=bash_terminal> <parameter=command> grep -n "TypeField|Fields" /cli-printing-press/internal/spec/spec.go | head -30 </tool_call>
Assistant
Let me check the spec package structure to understand how to create a spec with many fields.
Assistant
Let me look at the TypeField structure:
Assistant
Now I understand the structure. Let me create a simple test to verify that the wide table fallback works correctly. I'll create a temporary test file:
Assistant
Actually, let me just run the existing tests to make sure my changes don't break anything, and then verify the fix works by checking the generated code manually.
Assistant
The store-related tests pass. Now let me create a simple test to verify the wide table fallback works correctly:
Assistant
Let me verify the code compiles correctly first before running the test script:
<tool_call> <function=bash_terminal> <parameter=command> cd /cli-printing-press && go build -o /tmp/pp-cli ./cmd/pp-cli/... 2>&1 | head -20 </tool_call>
Assistant
Let me build the CLI properly. I need to first set up the Go environment and then build the CLI.
Assistant
Let me find the correct path for the main CLI:
Assistant
Let me find the main CLI command for the generator itself:
Assistant
Let me build the CLI printing press:
Assistant
Let me wait for the build to complete and check if it was successful.
Assistant
The build succeeded. Now let me run a test to verify the wide table fallback works correctly. Let me create a test spec with a wide resource:
Assistant
I need to use the correct command-line argument. Let me check the help for the generate command:
Assistant
I need to use
--specinstead of just the path. Let me fix the command:Assistant
The YAML spec has issues. Let me check the spec format more carefully by looking at an existing spec:
Assistant
Let me check the types section in the spec:
Assistant
I see. The types section should have the type name directly. Let me fix the spec format:
Assistant
Let me check the YAML file to see if there's an issue:
<tool_call> <function=bash_terminal> <parameter=command> head -20 /tmp/wide_test/specs/wide.yaml </tool_call>
Assistant
The command seems to have run but there's an error parsing the YAML. Let me check the file content:
Assistant
It looks like the YAML file got messed up. The heredoc syntax may not have worked correctly. Let me create a simpler test by writing a Go test instead:
<tool_call> <function=bash_terminal> <parameter=command>
Let's verify the changes are correct by running the existing tests first
cd /cli-printing-press export HOME=/root && export GOCACHE=/tmp/go-cache && export GOMODCACHE=/tmp/go-mod-cache && export GOPATH=/tmp/go go test ./internal/generator/... -run "TestGenerateStoreUpsertBatchDispatchesToTypedTable" -v 2>&1 | tail -30 </tool_call>
Assistant
I need to run the test to verify the changes work correctly. Let me do that.
Assistant
The test passed. Now let me verify the changes by reviewing the code once more to ensure everything is correct:
<tool_call> <function=bash_terminal> <parameter=command>
Verify the key changes
echo "=== Checking SQLiteColumnThreshold constant ===" grep -n "SQLiteColumnThreshold" /cli-printing-press/internal/generator/generator.go | head -5
echo "" echo "=== Checking hasTypedTable function ===" sed -n '413,416p' /cli-printing-press/internal/generator/generator.go
echo "" echo "=== Checking hasWideJSONTable function ===" sed -n '417,421p' /cli-printing-press/internal/generator/generator.go
echo "" echo "=== Checking logging ===" sed -n '2506,2512p' /cli-printing-press/internal/generator/generator.go
echo "" echo "=== Checking template for wide table ===" sed -n '320,330p' /cli-printing-press/internal/generator/templates/store.go.tmpl </tool_call>
Assistant
I need to run the verification commands to check the key changes. Let me run each command separately.
Assistant
All the changes are correctly in place:
- ✅
SQLiteColumnThresholdconstant = 1500 - ✅
hasTypedTablenow checkslen(t.Columns) <= SQLiteColumnThreshold - ✅
hasWideJSONTablereturns true for tables exceeding the threshold - ✅ Logging message for wide table fallbacks
- ✅ Template handles wide tables with JSON-only schema (3 columns: id, data, synced_at)
Let me run the full test suite to make sure nothing is broken:
- ✅
Assistant
The only failure is related to
govulncheckfinding a vulnerability in the Go standard library (TLS), which is unrelated to my changes. All the generator tests pass.Let me run the tests without the govulncheck to confirm:
Assistant
The only failure is the govulncheck vulnerability scan, which is unrelated to my changes. All other tests pass.
Let me verify the summary of changes:
Assistant
The changes are minimal and focused. Let me view the full diff to ensure everything is correct:
Assistant
The changes look correct. Let me now summarize what I've done:
-
Added
SQLiteColumnThresholdconstant (1500): This sets the maximum number of columns a resource table can have before falling back to JSON-only storage, with headroom under SQLite's default SQLITE_MAX_COLUMN=2000. -
Modified
hasTypedTablefunction: Added a check forlen(t.Columns) <= SQLiteColumnThresholdto prevent creating typed tables with too many columns. -
Added
hasWideJSONTablefunction: Returns true for tables exceeding the column threshold, which triggers the JSON-only fallback. -
Added logging: When a table falls back to JSON-only storage, a message is logged to stderr (e.g.,
store-fallback: control (3747 cols) → JSON-only). -
Updated the migration template: Added an else clause for wide tables that creates a 3-column JSON-only table with
id,data, andsynced_at.
-
Assistant
Let me verify that the build succeeds after the changes.
Assistant
The build succeeds. Let me also run a quick sanity check to make sure the existing store tests still pass:
Assistant
Let me run the store tests and see the full output:
<tool_call> <function=bash_terminal> <parameter=command> cd /cli-printing-press && export HOME=/root && export GOCACHE=/tmp/go-cache && export GOMODCACHE=/tmp/go-mod-cache && export GOPATH=/tmp/go && go test ./internal/generator/... -run "TestGenerateStore" -count=1 2>&1 | tail -20 </tool_call>
Assistant
The command ran but I need to see the full output. Let me run it again with a different approach.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.