sqlite_lint: add lint checks for rowid and without rowid
This commit is contained in:
@@ -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
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user