{"record":{"id":"060b8ef9c05ad21b","repo":"gastownhall/beads","slug":"legacy-sqlite-s-is-d-current-int-range-d-d","errorCode":null,"errorMessage":"legacy SQLite %s is %d (current INT range %d..%d)","messagePattern":"legacy SQLite (.+?) is (.+?) \\(current INT range (.+?)\\.\\.(.+?)\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/migration/legacysqlite/reader.go","lineNumber":758,"sourceCode":"\nfunc checkCurrentVarchars(fields ...currentVarchar) error {\n\tfor _, field := range fields {\n\t\tif n := utf8.RuneCountInString(field.value); n > field.maxRunes {\n\t\t\treturn fmt.Errorf(\"legacy SQLite %s is %d characters (current VARCHAR(%d) maximum)\", field.name, n, field.maxRunes)\n\t\t}\n\t}\n\treturn nil\n}\n\ntype currentInt struct {\n\tname  string\n\tvalue sql.NullInt64\n}\n\nfunc checkCurrentInts(fields ...currentInt) error {\n\tfor _, field := range fields {\n\t\tif field.value.Valid && (field.value.Int64 < math.MinInt32 || field.value.Int64 > math.MaxInt32) {\n\t\t\treturn fmt.Errorf(\"legacy SQLite %s is %d (current INT range %d..%d)\", field.name, field.value.Int64, math.MinInt32, math.MaxInt32)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc nonempty(values ...sql.NullString) bool {\n\tfor _, v := range values {\n\t\tif v.Valid && v.String != \"\" {\n\t\t\treturn true\n\t\t}\n\t}\n\treturn false\n}\nfunc nullString(v sql.NullString) string {\n\tif v.Valid {\n\t\treturn v.String\n\t}\n\treturn \"\"","sourceCodeStart":740,"sourceCodeEnd":776,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/internal/migration/legacysqlite/reader.go#L740-L776","documentation":"A legacy SQLite integer column (sql.NullInt64) holds a value outside the current schema's 32-bit INT range (-2147483648..2147483647). The reader validates integer fields during validate() so values that would overflow the current Dolt INT columns are rejected before any write, instead of silently wrapping or failing deep in the driver.","triggerScenarios":"Running the legacy-SQLite migration when a numeric column (e.g. priority, counter columns checked by checkCurrentInts) stores a value beyond int32 range, such as an extreme value written by an old or buggy bd build, or a manually edited database.","commonSituations":"Databases corrupted by integer overflow bugs in older versions; manual SQL edits inserting sentinel values like 9999999999; external tools writing SQLite rows directly; clock or epoch values stored in milliseconds that exceed int32.","solutions":["Find the column named in the error and UPDATE it in the legacy SQLite DB to a value within -2147483648..2147483647 before migrating.","If the value is a sentinel/garbage (e.g. 9999999999), reset it to the schema default (often NULL or 2 for priority).","Audit the legacy DB with a query like SELECT * FROM issues WHERE <col> NOT BETWEEN -2147483648 AND 2147483647 to catch all offending rows at once.","Check for tools or scripts outside bd that wrote to the SQLite file and fix them to use int32-safe values."],"exampleFix":"// before: priority stored as 4294967295\nUPDATE issues SET priority = 2 WHERE priority > 2147483647;\n// after: value fits current INT range","handlingStrategy":"validation","validationCode":"func intFitsCurrentSchema(v int64) bool {\n    return v >= -2147483648 && v <= 2147483647\n}\n// SELECT ... WHERE col < -2147483648 OR col > 2147483647 on all int columns first","typeGuard":"func isInt32Safe(v int64) bool {\n    return v >= math.MinInt32 && v <= math.MaxInt32\n}","tryCatchPattern":null,"preventionTips":["Query all integer columns for values outside [-2147483648, 2147483647] before migration and clamp them.","Avoid writing sentinel or overflowed integers via external tools into the SQLite DB.","Upgrade old bd versions through supported paths so integer columns are normalized."],"tags":["migration","sqlite","integer-overflow","schema-validation"],"backgroundTag":"int32-range-exceeded","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}