Fix a bug where non-rowid primary keys would be identified as 'not indexed' for foreign key indexes rule
Some checks failed
Build / build (push) Failing after 7m1s
Build / test-action (push) Successful in 3m7s

This commit is contained in:
wispem-wantex 2025-07-31 22:35:37 -07:00
parent 740767ea11
commit dbb43567d7
3 changed files with 12 additions and 7 deletions

View File

@ -104,14 +104,13 @@ var Checks = map[string]Check{
from tables
join pragma_index_list(tables.name) as indexes
join pragma_index_info(indexes.name) as columns
union
select table_name,
column_name
from columns
where column_name = 'rowid'
and is_primary_key != 0 -- 'pk' is either 0, or the 1-based index of the column within the primary key
where is_primary_key != 0 -- 'pk' is either 0, or the 1-based index of the column within the primary key
), foreign_keys as (
select * from columns where is_foreign_key = 1
)

View File

@ -54,7 +54,8 @@ func TestFailureCases(t *testing.T) {
}
func TestSuccessCase(t *testing.T) {
db, err := checks.OpenSchema("../../test_schemas/success.sql")
file := "../../test_schemas/success.sql"
db, err := checks.OpenSchema(file)
if err != nil {
t.Fatalf("failed to open database: %v", err)
}
@ -64,8 +65,8 @@ func TestSuccessCase(t *testing.T) {
if err != nil {
t.Errorf("failed to execute check '%s': %v", check.Name, err)
}
if len(results) > 0 {
t.Errorf("Should have passed, but didn't: %s", "test_schemas/success.sql")
for _, r := range results {
t.Errorf("Unexpected error in file %q: %#v", file, r)
}
}
}

View File

@ -11,3 +11,8 @@ create table stuff2 (
stuff_id integer references stuff(rowid),
alternative_stuff_id integer references stuff(amount)
) strict;
create table stuff3 (
weird_pk3 integer primary key,
stuff2_id integer not null references stuff2(weird_pk)
) strict;