Advertisement
tarkhil

receipts

Dec 25th, 2020
2,406
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 1.03 KB | None | 0 0
  1. CREATE TABLE billing.receipts (
  2.     id serial NOT NULL,
  3.     payment_date DATE NOT NULL,
  4.     "number" int4 NOT NULL,
  5.     "comments" text NOT NULL,
  6.     SUM NUMERIC(12,2) NOT NULL,
  7.     STATUS int4 NOT NULL,
  8.     payer VARCHAR(500) NOT NULL,
  9.     proposed_agr int4 NULL,
  10.     proposed_bill int4 NULL,
  11.     process_result text NULL,
  12.     payer_ok bool NOT NULL DEFAULT FALSE,
  13.     CONSTRAINT receipts_pkey PRIMARY KEY (id),
  14.     CONSTRAINT receipts_un UNIQUE (payment_date, NUMBER, comments, SUM),
  15.     CONSTRAINT receipts_agreements_fk FOREIGN KEY (proposed_agr) REFERENCES agreements(id) ON UPDATE CASCADE ON DELETE RESTRICT,
  16.     CONSTRAINT receipts_bills_fk FOREIGN KEY (proposed_bill) REFERENCES bills(id) ON UPDATE CASCADE ON DELETE SET NULL,
  17.     CONSTRAINT receipts_status_fkey FOREIGN KEY (STATUS) REFERENCES aux.receipt_states(id)
  18. );
  19. CREATE INDEX receipts_proposed_agr_idx ON billing.receipts USING btree (proposed_agr);
  20. CREATE INDEX receipts_proposed_bill_idx ON billing.receipts USING btree (proposed_bill);
  21. CREATE INDEX receipts_status_idx ON billing.receipts USING btree (STATUS);
  22.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement