Fix a bug where non-rowid primary keys would be identified as 'not indexed' for foreign key indexes rule
This commit is contained in:
parent
740767ea11
commit
dbb43567d7
@ -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
|
||||
)
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user