Spaces:
Runtime error
Runtime error
File size: 5,981 Bytes
2a902a6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | Database Schema:
CREATE TABLE IF NOT EXISTS public.erp_customers
(
customer_id integer NOT NULL DEFAULT nextval('erp_customers_customer_id_seq'::regclass),
name character varying(100) COLLATE pg_catalog."default" NOT NULL,
email character varying(100) COLLATE pg_catalog."default" NOT NULL,
phone character varying(20) COLLATE pg_catalog."default",
address text COLLATE pg_catalog."default",
created_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
CONSTRAINT erp_customers_pkey PRIMARY KEY (customer_id),
CONSTRAINT erp_customers_email_key UNIQUE (email)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_customers
OWNER to postgres;
CREATE TABLE IF NOT EXISTS public.erp_invoices
(
invoice_id integer NOT NULL DEFAULT nextval('erp_invoices_invoice_id_seq'::regclass),
order_id integer,
invoice_date date DEFAULT CURRENT_DATE,
amount numeric(12,2) NOT NULL,
payment_terms character varying(50) COLLATE pg_catalog."default",
due_date date,
is_paid boolean DEFAULT false,
invoice_number character varying(50) COLLATE pg_catalog."default",
CONSTRAINT erp_invoices_pkey PRIMARY KEY (invoice_id),
CONSTRAINT erp_invoices_invoice_number_key UNIQUE (invoice_number),
CONSTRAINT erp_invoices_order_id_fkey FOREIGN KEY (order_id)
REFERENCES public.erp_orders (order_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_invoices
OWNER to postgres;
CREATE INDEX IF NOT EXISTS idx_invoices_order
ON public.erp_invoices USING btree
(order_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE TABLE IF NOT EXISTS public.erp_order_history
(
history_id integer NOT NULL DEFAULT nextval('erp_order_history_history_id_seq'::regclass),
order_id integer,
"timestamp" timestamp without time zone DEFAULT CURRENT_TIMESTAMP,
status_change character varying(50) COLLATE pg_catalog."default",
notes text COLLATE pg_catalog."default",
updated_by character varying(100) COLLATE pg_catalog."default",
CONSTRAINT erp_order_history_pkey PRIMARY KEY (history_id),
CONSTRAINT erp_order_history_order_id_fkey FOREIGN KEY (order_id)
REFERENCES public.erp_orders (order_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_order_history
OWNER to postgres;
CREATE INDEX IF NOT EXISTS idx_order_history_order
ON public.erp_order_history USING btree
(order_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE TABLE IF NOT EXISTS public.erp_order_items
(
order_item_id integer NOT NULL DEFAULT nextval('erp_order_items_order_item_id_seq'::regclass),
order_id integer,
product_id integer,
quantity integer NOT NULL,
unit_price numeric(10,2) NOT NULL,
subtotal numeric(12,2) NOT NULL,
CONSTRAINT erp_order_items_pkey PRIMARY KEY (order_item_id),
CONSTRAINT erp_order_items_order_id_fkey FOREIGN KEY (order_id)
REFERENCES public.erp_orders (order_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT erp_order_items_product_id_fkey FOREIGN KEY (product_id)
REFERENCES public.erp_products (product_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_order_items
OWNER to postgres;
CREATE INDEX IF NOT EXISTS idx_order_items_order
ON public.erp_order_items USING btree
(order_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE INDEX IF NOT EXISTS idx_order_items_product
ON public.erp_order_items USING btree
(product_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE TABLE IF NOT EXISTS public.erp_orders
(
order_id integer NOT NULL DEFAULT nextval('erp_orders_order_id_seq'::regclass),
customer_id integer,
order_date date DEFAULT CURRENT_DATE,
total_amount numeric(12,2) NOT NULL,
status character varying(20) COLLATE pg_catalog."default" NOT NULL DEFAULT 'Processing'::character varying,
previous_order_id integer,
estimated_delivery date,
actual_delivery date,
payment_status character varying(20) COLLATE pg_catalog."default" DEFAULT 'Pending'::character varying,
shipping_address text COLLATE pg_catalog."default" NOT NULL,
shipping_country character varying(100) COLLATE pg_catalog."default",
destination_country character varying(100) COLLATE pg_catalog."default",
CONSTRAINT erp_orders_pkey PRIMARY KEY (order_id),
CONSTRAINT erp_orders_customer_id_fkey FOREIGN KEY (customer_id)
REFERENCES public.erp_customers (customer_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION,
CONSTRAINT erp_orders_previous_order_id_fkey FOREIGN KEY (previous_order_id)
REFERENCES public.erp_orders (order_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_orders
OWNER to postgres;
CREATE INDEX IF NOT EXISTS idx_orders_customer
ON public.erp_orders USING btree
(customer_id ASC NULLS LAST)
TABLESPACE pg_default;
CREATE TABLE IF NOT EXISTS public.erp_products
(
product_id integer NOT NULL DEFAULT nextval('erp_products_product_id_seq'::regclass),
product_name character varying(100) COLLATE pg_catalog."default" NOT NULL,
description text COLLATE pg_catalog."default",
category character varying(50) COLLATE pg_catalog."default",
price numeric(10,2) NOT NULL,
stock_quantity integer NOT NULL DEFAULT 0,
sku character varying(50) COLLATE pg_catalog."default",
CONSTRAINT erp_products_pkey PRIMARY KEY (product_id),
CONSTRAINT erp_products_sku_key UNIQUE (sku)
)
TABLESPACE pg_default;
ALTER TABLE IF EXISTS public.erp_products
OWNER to postgres; |