sqlite_lint: add lint checks for rowid and without rowid
Some checks failed
CI / build-docker (push) Successful in 7s
CI / build-docker-bootstrap (push) Has been skipped
CI / release-test (push) Failing after 15s

This commit is contained in:
2026-01-10 17:04:20 -08:00
parent 560e461b00
commit 2ac9d8e775
7 changed files with 70 additions and 6 deletions

View File

@@ -133,4 +133,63 @@ var Checks = []Check{
return
},
},
{
Name: "forbid_rowid_on_without_rowid_table",
Explanation: "Tables that are `without rowid` may not have a `rowid` column",
Execute: func(s schema.Schema) (ret []CheckResult) {
for tblName, tbl := range s.Tables {
if !tbl.IsWithoutRowid {
continue
}
for _, column := range tbl.Columns {
if column.Name == "rowid" {
ret = append(ret, CheckResult{
ErrorMsg: "rowid on 'without rowid' table",
TableName: tblName,
ColumnName: column.Name,
})
}
}
}
return
},
},
{
Name: "require_explicit_rowid",
Explanation: "All tables should have an explicit `rowid integer primary key` column, unless they\n" +
"are declared `without rowid`.",
Execute: func(s schema.Schema) (ret []CheckResult) {
tbl_loop:
for tblName, tbl := range s.Tables {
if tbl.IsWithoutRowid {
continue
}
for _, column := range tbl.Columns {
if column.Name == "rowid" {
if !column.IsPrimaryKey {
ret = append(ret, CheckResult{
ErrorMsg: "`rowid` column not declared \"primary key\"",
TableName: tblName,
ColumnName: column.Name,
})
}
if column.Type != "integer" {
ret = append(ret, CheckResult{
ErrorMsg: "non-integer `rowid` column",
TableName: tblName,
ColumnName: column.Name,
})
}
continue tbl_loop
}
}
ret = append(ret, CheckResult{
ErrorMsg: "no `rowid` column",
TableName: tblName,
ColumnName: "",
})
}
return
},
},
}