Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How do you model double-entry book-keeping in your relational database? And where comes the fear of corruption if .ledger files are merely text?


I can't share everything here, but basics are this. Three tables: accounts, transactions, entries. Entries have amount, unit, notes. Accounts have name, parent_account. Transactions have subject, notes, date. That's the data. Then I have a view that flattens accounts tree, so that each has name and fullname. Name being Fun, fullname a full path to that account, eg. Expenses:Fun.

With that base structure, you can start answering any questions by just summing entries groupped by accounts filtered by a regexp on fullname and fitler on date. What is my cashflow for any time period, what is my equity, what is my balance sheet, what I actually have, what changed recently, how any of this develops over time...


Corruption not in a sense of storage issues, but in a sense of a fragile text format made for human editing, but not entire pleasant for that.

I wanted more pleasant entry. It became tedious/error prone to search for similar entries with vim and copy pasting. I could have made a specialized tool with nice autocomplete on top of ledger, but then why not drop the entire thing and use a database, where you don't need to re-invent groupping, sorting, filtering, summing, date interval operations and all the mundane stuff.

I also wanted to import data from a bank, and keep all the info associated with the entries. Easy to do in a database, not so in ledger text format.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: