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

Allow mytable.create_index() to ignore an already existing index #627

Open
tobych opened this issue Apr 27, 2024 · 0 comments
Open

Allow mytable.create_index() to ignore an already existing index #627

tobych opened this issue Apr 27, 2024 · 0 comments

Comments

@tobych
Copy link

tobych commented Apr 27, 2024

While I'm working on a migration, I like to keep my code idempotent.

I love that most operations offer an ignore argument.

I'd like one for create_index() too.

I can submit a PR but I'd like some discussion first.

Meanwhile I'm using this motif:

from contextlib import suppress

from sqlite_utils.db import OperationalError

with suppress(OperationalError):
    mytable.create_index({'mycolumn'}, unique=True)

I could instead check to see whether the index already exists, but that's not Pythonic.

I should be checking the error message there really. More fine-grained exception classes would help here, so I could do this:

with suppress(IndexAlreadyExists):
    mytable.create_index({'mycolumn'}, unique=True)

Where IndexAlreadyExists is a subclass of OperationalError. Separate issue though.

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