Skip to content

Column tests should catch missing indexes on foreign keys #152

@rsyring

Description

@rsyring

Postgres does not create indexes on columns with a foreign key. They have to be created manually. Our ColumnCheck for a FK usually looks something like:

ColumnCheck('space_id', fk='space_spaces.id', required=True)

My proposal would be for that format throw an exception for "Foreign key has not specified an index." The new correct options would be:

# When an index exists
ColumnCheck('space_id', fk='space_spaces.id', required=True, index='ix_categories_space_id')
# When you specifically don't want an index for some reason
ColumnCheck('space_id', fk='space_spaces.id', required=True, index=False)

This at least makes it explicit.

We could query the tables indexes and see if any index has the same column/name as the FK column as it's first column, but I think explicit/manual might be better here? Actually make the dev think about what they want to do with the indexes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions