This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5c4c8b
commit 848f975
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
BEGIN; | ||
|
||
CREATE TYPE account_type AS ENUM ('asset', 'liability', 'income', 'expense'); | ||
|
||
CREATE TABLE accounts | ||
( id serial PRIMARY KEY | ||
, type account_type NOT NULL | ||
, participant text DEFAULT NULL UNIQUE REFERENCES participants | ||
ON UPDATE CASCADE ON DELETE RESTRICT | ||
, team text DEFAULT NULL UNIQUE REFERENCES teams | ||
ON UPDATE CASCADE ON DELETE RESTRICT | ||
, system text DEFAULT NULL UNIQUE | ||
|
||
, CONSTRAINT exactly_one_foreign_key CHECK ( | ||
CASE WHEN participant IS NULL THEN 0 ELSE 1 END + | ||
CASE WHEN team IS NULL THEN 0 ELSE 1 END + | ||
CASE WHEN system IS NULL THEN 0 ELSE 1 END = 1 | ||
) | ||
); | ||
|
||
INSERT INTO accounts (type, system) VALUES ('asset', 'escrow'); | ||
INSERT INTO accounts (type, system) VALUES ('asset', 'escrow receivable'); | ||
INSERT INTO accounts (type, system) VALUES ('liability', 'escrow payable'); | ||
INSERT INTO accounts (type, system) VALUES ('income', 'processing fee revenues'); | ||
INSERT INTO accounts (type, system) VALUES ('expense', 'processing fee expenses'); | ||
INSERT INTO accounts (type, system) VALUES ('income', 'earned interest'); | ||
INSERT INTO accounts (type, system) VALUES ('expense', 'chargeback expenses'); | ||
|
||
|
||
CREATE TABLE journal | ||
( id bigserial PRIMARY KEY | ||
, ts timestamp_tz NOT NULL DEFAULT CURRENT_TIMESTAMP | ||
, amount numeric(35, 2) NOT NULL | ||
, debit bigint NOT NULL REFERENCES accounts | ||
, credit bigint NOT NULL REFERENCES accounts | ||
, payday int DEFAULT NULL REFERENCES paydays | ||
, route bigint DEFAULT NULL REFERENCES exchange_routes | ||
, status exchange_status DEFAULT NULL | ||
, recorder text DEFAULT NULL REFERENCES participants | ||
ON UPDATE CASCADE ON DELETE RESTRICT | ||
); | ||
|
||
CREATE TABLE journal_notes | ||
( id bigserial PRIMARY KEY | ||
, body text NOT NULL | ||
, author text NOT NULL REFERENCES participants | ||
ON UPDATE CASCADE ON DELETE RESTRICT | ||
, is_private boolean NOT NULL DEFAULT TRUE | ||
); | ||
END; |