I have a "virtual scratchpad" Rails app that has
pages (analogous to a piece of scratch paper), and each page
has_many :notes (analogous to the notes that you'd write on that paper).
I want to count the total
notes created over the lifetime of the app. I know all the advice about "never delete data" but in this case the app is literally designed to work like scratch paper. As a result, if a
page hasn't been touched/updated in 30 days, the app automatically destroys it (like throwing away scratch paper).
For fun I'd like to track the total lifetime number of pages created, and the total lifetime notes created. Since my app, be design, will destroy data when it expires, I can't simply do
Note.count in order to get these stats. I need instead to increment a counter for each, and have that counter persisted forever.
My question this: my first inclination for how to implement this is to simply create a
stats table with a column for each stat (e.g.
lifetime_note_count, etc.), and have that table contain only a single row since I will only have one set of statistics. It seems a little silly to create a table just to contain a single row, but is this considered okay for this kind of use? Is there a better model/pattern I should think about? My database is pretty simple as it is (literally just two tables -
notes), but that doesn't mean I want to be sloppy about the implementation just because I can.