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

reset_counts() method and command #219

Closed
simonw opened this issue Jan 3, 2021 · 4 comments
Closed

reset_counts() method and command #219

simonw opened this issue Jan 3, 2021 · 4 comments

Comments

@simonw
Copy link
Owner

simonw commented Jan 3, 2021

Thought: maybe there should be a .reset_counts() method too, for if the table gets out of date with the triggers.

One way that could happen is if a table is dropped and recreated - the counts in the _counts table would likely no longer match the number of rows in that table.

Originally posted by @simonw in #215 (comment)

@simonw
Copy link
Owner Author

simonw commented Jan 3, 2021

This is a little tricky. We should assume that the existing values in the _counts table cannot be trusted at all when this method is called - so we should probably clear that table entirely and then re-populate it.

But that means we need to figure out which tables in the database have the counts triggers defined.

@simonw
Copy link
Owner Author

simonw commented Jan 3, 2021

I think this should be accompanied by a sqlite-utils reset-counts command.

@simonw simonw changed the title .reset_counts() method reset_counts() method and command Jan 3, 2021
@simonw
Copy link
Owner Author

simonw commented Jan 3, 2021

To detect tables, look at the names of the triggers - {table}{counts_table}_insert and {table}{counts_table}_delete.

@simonw
Copy link
Owner Author

simonw commented Jan 3, 2021

A table.has_count_triggers property.

@simonw simonw closed this as completed in 0d2a47e Jan 3, 2021
simonw added a commit that referenced this issue Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant