Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Column tests should catch missing indexes on foreign keys #152

Open
rsyring opened this issue Sep 2, 2021 · 0 comments
Open

Column tests should catch missing indexes on foreign keys #152

rsyring opened this issue Sep 2, 2021 · 0 comments

Comments

@rsyring
Copy link
Member

rsyring commented Sep 2, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant