Phase 1: accounting
This commit is contained in:
254
schema.sql
254
schema.sql
@@ -2,10 +2,10 @@
|
||||
-- PostgreSQL database dump
|
||||
--
|
||||
|
||||
\restrict XHJaQEVNwjEtL1FZTBb0Sf7ooBX1Ld95BOqQlHUgJxKe87sxBoQbgpWG7aympDU
|
||||
\restrict dcppwhgnHJoNOBlNPc2moWihaP892wdvcafOsrY89xMPWDOJABsPkfufznphBjh
|
||||
|
||||
-- Dumped from database version 17.6
|
||||
-- Dumped by pg_dump version 17.6
|
||||
-- Dumped from database version 17.7
|
||||
-- Dumped by pg_dump version 17.7
|
||||
|
||||
SET statement_timeout = 0;
|
||||
SET lock_timeout = 0;
|
||||
@@ -45,7 +45,9 @@ CREATE TABLE public.customers (
|
||||
line3 character varying(255),
|
||||
line4 character varying(255),
|
||||
qbo_id character varying(50),
|
||||
qbo_sync_token character varying(50)
|
||||
qbo_sync_token character varying(50),
|
||||
contact character varying(255),
|
||||
remarks text
|
||||
);
|
||||
|
||||
|
||||
@@ -120,7 +122,7 @@ ALTER SEQUENCE public.invoice_items_id_seq OWNED BY public.invoice_items.id;
|
||||
|
||||
CREATE TABLE public.invoices (
|
||||
id integer NOT NULL,
|
||||
invoice_number character varying(50) NOT NULL,
|
||||
invoice_number character varying(50) DEFAULT NULL::character varying,
|
||||
customer_id integer,
|
||||
invoice_date date NOT NULL,
|
||||
terms character varying(100) DEFAULT 'Net 30'::character varying,
|
||||
@@ -135,7 +137,20 @@ CREATE TABLE public.invoices (
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
|
||||
qbo_id character varying(50),
|
||||
qbo_sync_token character varying(50),
|
||||
qbo_doc_number character varying(50)
|
||||
qbo_doc_number character varying(50),
|
||||
paid_date date,
|
||||
scheduled_send_date date,
|
||||
payment_status character varying(20),
|
||||
email_status character varying(20) DEFAULT 'open'::character varying,
|
||||
bill_to_name character varying(255),
|
||||
is_recurring boolean DEFAULT false,
|
||||
recurring_interval character varying(20),
|
||||
next_recurring_date date,
|
||||
recurring_source_id integer,
|
||||
stripe_payment_link_id character varying(255),
|
||||
stripe_payment_link_url text,
|
||||
stripe_payment_status character varying(50) DEFAULT 'pending'::character varying,
|
||||
sent_dates date[] DEFAULT '{}'::date[]
|
||||
);
|
||||
|
||||
|
||||
@@ -163,6 +178,84 @@ ALTER SEQUENCE public.invoices_id_seq OWNER TO quoteuser;
|
||||
ALTER SEQUENCE public.invoices_id_seq OWNED BY public.invoices.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices; Type: TABLE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE TABLE public.payment_invoices (
|
||||
id integer NOT NULL,
|
||||
payment_id integer,
|
||||
invoice_id integer,
|
||||
amount numeric(12,2) NOT NULL
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.payment_invoices OWNER TO quoteuser;
|
||||
|
||||
--
|
||||
-- Name: payment_invoices_id_seq; Type: SEQUENCE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.payment_invoices_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.payment_invoices_id_seq OWNER TO quoteuser;
|
||||
|
||||
--
|
||||
-- Name: payment_invoices_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.payment_invoices_id_seq OWNED BY public.payment_invoices.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: payments; Type: TABLE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE TABLE public.payments (
|
||||
id integer NOT NULL,
|
||||
payment_date date NOT NULL,
|
||||
reference_number character varying(100),
|
||||
payment_method character varying(50),
|
||||
deposit_to_account character varying(200),
|
||||
total_amount numeric(12,2) NOT NULL,
|
||||
customer_id integer,
|
||||
qbo_payment_id character varying(50),
|
||||
notes text,
|
||||
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.payments OWNER TO quoteuser;
|
||||
|
||||
--
|
||||
-- Name: payments_id_seq; Type: SEQUENCE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE SEQUENCE public.payments_id_seq
|
||||
AS integer
|
||||
START WITH 1
|
||||
INCREMENT BY 1
|
||||
NO MINVALUE
|
||||
NO MAXVALUE
|
||||
CACHE 1;
|
||||
|
||||
|
||||
ALTER SEQUENCE public.payments_id_seq OWNER TO quoteuser;
|
||||
|
||||
--
|
||||
-- Name: payments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER SEQUENCE public.payments_id_seq OWNED BY public.payments.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: quote_items; Type: TABLE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -250,6 +343,19 @@ ALTER SEQUENCE public.quotes_id_seq OWNER TO quoteuser;
|
||||
ALTER SEQUENCE public.quotes_id_seq OWNED BY public.quotes.id;
|
||||
|
||||
|
||||
--
|
||||
-- Name: settings; Type: TABLE; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE TABLE public.settings (
|
||||
key character varying(100) NOT NULL,
|
||||
value text,
|
||||
updated_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
ALTER TABLE public.settings OWNER TO quoteuser;
|
||||
|
||||
--
|
||||
-- Name: customers id; Type: DEFAULT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -271,6 +377,20 @@ ALTER TABLE ONLY public.invoice_items ALTER COLUMN id SET DEFAULT nextval('publi
|
||||
ALTER TABLE ONLY public.invoices ALTER COLUMN id SET DEFAULT nextval('public.invoices_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices id; Type: DEFAULT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payment_invoices ALTER COLUMN id SET DEFAULT nextval('public.payment_invoices_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payments id; Type: DEFAULT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payments ALTER COLUMN id SET DEFAULT nextval('public.payments_id_seq'::regclass);
|
||||
|
||||
|
||||
--
|
||||
-- Name: quote_items id; Type: DEFAULT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -325,6 +445,30 @@ ALTER TABLE ONLY public.invoices
|
||||
ADD CONSTRAINT invoices_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices payment_invoices_payment_id_invoice_id_key; Type: CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payment_invoices
|
||||
ADD CONSTRAINT payment_invoices_payment_id_invoice_id_key UNIQUE (payment_id, invoice_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices payment_invoices_pkey; Type: CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payment_invoices
|
||||
ADD CONSTRAINT payment_invoices_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payments payments_pkey; Type: CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payments
|
||||
ADD CONSTRAINT payments_pkey PRIMARY KEY (id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: quote_items quote_items_pkey; Type: CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -349,6 +493,14 @@ ALTER TABLE ONLY public.quotes
|
||||
ADD CONSTRAINT quotes_quote_number_key UNIQUE (quote_number);
|
||||
|
||||
|
||||
--
|
||||
-- Name: settings settings_pkey; Type: CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.settings
|
||||
ADD CONSTRAINT settings_pkey PRIMARY KEY (key);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_customers_qbo_id; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -384,6 +536,55 @@ CREATE INDEX idx_invoices_customer_id ON public.invoices USING btree (customer_i
|
||||
CREATE INDEX idx_invoices_invoice_number ON public.invoices USING btree (invoice_number);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_invoices_paid_date; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_invoices_paid_date ON public.invoices USING btree (paid_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_invoices_recurring; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_invoices_recurring ON public.invoices USING btree (is_recurring, next_recurring_date) WHERE (is_recurring = true);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_invoices_scheduled_send_date; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_invoices_scheduled_send_date ON public.invoices USING btree (scheduled_send_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_payment_invoices_invoice; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_payment_invoices_invoice ON public.payment_invoices USING btree (invoice_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_payment_invoices_payment; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_payment_invoices_payment ON public.payment_invoices USING btree (payment_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_payments_customer; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_payments_customer ON public.payments USING btree (customer_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_payments_date; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE INDEX idx_payments_date ON public.payments USING btree (payment_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: idx_quote_items_quote_id; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -405,6 +606,13 @@ CREATE INDEX idx_quotes_customer_id ON public.quotes USING btree (customer_id);
|
||||
CREATE INDEX idx_quotes_quote_number ON public.quotes USING btree (quote_number);
|
||||
|
||||
|
||||
--
|
||||
-- Name: uniq_recurring_source_invoice_date; Type: INDEX; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
CREATE UNIQUE INDEX uniq_recurring_source_invoice_date ON public.invoices USING btree (recurring_source_id, invoice_date) WHERE (recurring_source_id IS NOT NULL);
|
||||
|
||||
|
||||
--
|
||||
-- Name: invoice_items invoice_items_invoice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -429,6 +637,38 @@ ALTER TABLE ONLY public.invoices
|
||||
ADD CONSTRAINT invoices_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: invoices invoices_recurring_source_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.invoices
|
||||
ADD CONSTRAINT invoices_recurring_source_id_fkey FOREIGN KEY (recurring_source_id) REFERENCES public.invoices(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices payment_invoices_invoice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payment_invoices
|
||||
ADD CONSTRAINT payment_invoices_invoice_id_fkey FOREIGN KEY (invoice_id) REFERENCES public.invoices(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: payment_invoices payment_invoices_payment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payment_invoices
|
||||
ADD CONSTRAINT payment_invoices_payment_id_fkey FOREIGN KEY (payment_id) REFERENCES public.payments(id) ON DELETE CASCADE;
|
||||
|
||||
|
||||
--
|
||||
-- Name: payments payments_customer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.payments
|
||||
ADD CONSTRAINT payments_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES public.customers(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: quote_items quote_items_quote_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: quoteuser
|
||||
--
|
||||
@@ -449,5 +689,5 @@ ALTER TABLE ONLY public.quotes
|
||||
-- PostgreSQL database dump complete
|
||||
--
|
||||
|
||||
\unrestrict XHJaQEVNwjEtL1FZTBb0Sf7ooBX1Ld95BOqQlHUgJxKe87sxBoQbgpWG7aympDU
|
||||
\unrestrict dcppwhgnHJoNOBlNPc2moWihaP892wdvcafOsrY89xMPWDOJABsPkfufznphBjh
|
||||
|
||||
|
||||
Reference in New Issue
Block a user