Skip to content

Commit

Permalink
fix tables creation order in schema.sql
Browse files Browse the repository at this point in the history
`invoices` is referenced in `transfers`
  • Loading branch information
Changaco committed Mar 30, 2017
1 parent bf86f69 commit bb948bc
Showing 1 changed file with 30 additions and 30 deletions.
60 changes: 30 additions & 30 deletions sql/schema.sql
Expand Up @@ -174,6 +174,36 @@ CREATE TRIGGER update_current_tip INSTEAD OF UPDATE ON current_tips
FOR EACH ROW EXECUTE PROCEDURE update_tip();


-- invoices

CREATE TYPE invoice_nature AS ENUM ('expense');

CREATE TYPE invoice_status AS ENUM
('pre', 'canceled', 'new', 'retracted', 'accepted', 'paid', 'rejected');

CREATE TABLE invoices
( id serial PRIMARY KEY
, ctime timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
, sender bigint NOT NULL REFERENCES participants
, addressee bigint NOT NULL REFERENCES participants
, nature invoice_nature NOT NULL
, amount numeric(35,2) NOT NULL CHECK (amount > 0)
, description text NOT NULL
, details text
, documents jsonb NOT NULL
, status invoice_status NOT NULL
);

CREATE TABLE invoice_events
( id serial PRIMARY KEY
, invoice int NOT NULL REFERENCES invoices
, participant bigint NOT NULL REFERENCES participants
, ts timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
, status invoice_status NOT NULL
, message text
);


-- transfers -- balance transfers from one user to another

CREATE TYPE transfer_context AS ENUM
Expand Down Expand Up @@ -509,36 +539,6 @@ CREATE INDEX newsletter_texts_not_sent_idx
WHERE sent_at IS NULL AND scheduled_for IS NOT NULL;


-- invoices

CREATE TYPE invoice_nature AS ENUM ('expense');

CREATE TYPE invoice_status AS ENUM
('pre', 'canceled', 'new', 'retracted', 'accepted', 'paid', 'rejected');

CREATE TABLE invoices
( id serial PRIMARY KEY
, ctime timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
, sender bigint NOT NULL REFERENCES participants
, addressee bigint NOT NULL REFERENCES participants
, nature invoice_nature NOT NULL
, amount numeric(35,2) NOT NULL CHECK (amount > 0)
, description text NOT NULL
, details text
, documents jsonb NOT NULL
, status invoice_status NOT NULL
);

CREATE TABLE invoice_events
( id serial PRIMARY KEY
, invoice int NOT NULL REFERENCES invoices
, participant bigint NOT NULL REFERENCES participants
, ts timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
, status invoice_status NOT NULL
, message text
);


-- composite types, keep this at the end of the file

\i sql/composites.sql

0 comments on commit bb948bc

Please sign in to comment.