Last active
October 7, 2024 22:56
-
-
Save ezza/f541d7eb7484e5a832cb0cc293a6c3f3 to your computer and use it in GitHub Desktop.
Count how many times each key has changed in your jsonb papertrail storage
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# If you use the default table name | |
PaperTrail::Version.connection.execute(<<-SQL | |
select k as key, count(*) | |
from versions v cross join lateral | |
jsonb_object_keys(v.object_changes) k | |
group by k order by count(*) desc; | |
SQL | |
).to_a | |
# If your table name is papertrail_versions | |
PaperTrail::Version.connection.execute(<<-SQL | |
select k as key, count(*) | |
from papertrail_versions v cross join lateral | |
jsonb_object_keys(v.object_changes) k | |
group by k order by count(*) desc; | |
SQL | |
).to_a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment