A double-entry accounting system in pure PostgreSQL. Note that this is only part
of the accounting system, you will still need something calling balance_grant
and balance_revoke
(like a worker for a particular payment processor) to
maintain zero-sum. Other services using this service should not use the tables
directly, and instead should use the available functions. Database credentials
should be created in such a manner as to only give access to the minimal amount
of functions needed to perform their tasking.
NOTE: THERE ARE 2 "DANGEROUS" FUNCTIONS, balance_grant
AND balance_revoke
.
THESE FUNCTIONS IGNORE BALANCES WHEN CREATING/REVOKING BALANCES. THEY SHOULD BE
DROPPED IF NOT NEEDED, OR PROTECTED IF THEY ARE.
A collection of transactions, usually attached (externally) to some entity, such as a customer or business.
A transfer between two accounts.
A unit representing value, such as a currency, energy drinks, chickens, etc.
Create an account with the given name
Get the given account metadata value for the given key and account id.
Set the given account metadata key to the given value for the given account id.
Get the balance for the given account id and uot
Give the given account id the given balance in the given uot.
Remove the given balance in the given uot from the given account id.
Transfer the given balance in the given uot from the given source account id to the given destination account id.
Get the given transaction metadata value for the given key and transaction id.
Set the given transaction metadata key to the given value for the given transaction id.
Holds accounts and their names that have been created.
A key value store for attaching data to accounts.
Holds transactions and their source and destination account, uot and amount.
A key value store for attaching data to transactions.
Updates the row's modified timestamp. Attached to:
accounts
accounts_metadata
transactions
transactions_metadata