-
Notifications
You must be signed in to change notification settings - Fork 0
/
bakery.sql
162 lines (135 loc) · 6.14 KB
/
bakery.sql
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
CREATE SEQUENCE public.customer_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE public.buy_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE public.bread_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE public.orders_processed_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE public.bread_maker_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE SEQUENCE public.make_order_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE public.bread (
id integer DEFAULT nextval('public.bread_id_seq'::regclass) NOT NULL,
name character varying(255),
price float,
quantity integer,
description character varying(255),
type character varying(255),
status character varying(255),
created_at timestamp without time zone,
updated_at timestamp without time zone,
image character varying(255),
PRIMARY KEY (id)
);
ALTER TABLE public.bread_id_seq OWNER TO postgres;
CREATE TABLE public.bread_maker (
id integer DEFAULT nextval('public.bread_maker_id_seq'::regclass) NOT NULL,
name character varying(255),
email character varying(255),
created_at timestamp without time zone,
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
ALTER TABLE public.bread_maker_id_seq OWNER TO postgres;
CREATE TABLE public.make_order (
id integer DEFAULT nextval('public.make_order_id_seq'::regclass) NOT NULL,
bread_maker_id integer NOT NULL,
make_order_uuid character varying(255),
PRIMARY KEY (id),
FOREIGN KEY (bread_maker_id) REFERENCES public.bread_maker(id)
);
CREATE TABLE public.make_order_details (
make_order_id integer NOT NULL,
bread_id integer NOT NULL,
quantity integer,
PRIMARY KEY (make_order_id, bread_id),
FOREIGN KEY (make_order_id) REFERENCES public.make_order(id),
FOREIGN KEY (bread_id) REFERENCES public.bread(id)
);
CREATE TABLE public.customer (
id integer DEFAULT nextval('public.customer_id_seq'::regclass) NOT NULL,
name character varying(255),
email character varying(255),
password character varying(255),
created_at timestamp without time zone,
updated_at timestamp without time zone,
PRIMARY KEY (id)
);
ALTER TABLE public.customer_id_seq OWNER TO postgres;
CREATE TABLE public.buy_order (
id integer DEFAULT nextval('public.buy_id_seq'::regclass) NOT NULL,
customer_id integer NOT NULL,
buy_order_uuid character varying(255),
status character varying(255),
PRIMARY KEY (id),
FOREIGN KEY (customer_id) REFERENCES public.customer(id)
);
ALTER TABLE public.buy_id_seq OWNER TO postgres;
CREATE TABLE public.order_details (
buy_order_id integer NOT NULL,
bread_id integer NOT NULL,
quantity integer,
price float,
created_at timestamp without time zone,
updated_at timestamp without time zone,
PRIMARY KEY (buy_order_id, bread_id),
FOREIGN KEY (buy_order_id) REFERENCES public.buy_order(id),
FOREIGN KEY (bread_id) REFERENCES public.bread(id)
);
CREATE TABLE public.orders_processed (
id integer DEFAULT nextval('public.orders_processed_id_seq'::regclass) NOT NULL,
customer_id integer NOT NULL,
buy_order_id integer NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone,
PRIMARY KEY (id),
FOREIGN KEY (customer_id) REFERENCES public.customer(id),
FOREIGN KEY (buy_order_id) REFERENCES public.buy_order(id)
);
ALTER TABLE public.orders_processed_id_seq OWNER TO postgres;
CREATE TABLE public.outbox (
id SERIAL PRIMARY KEY,
payload BYTEA NOT NULL,
sent BOOLEAN NOT NULL DEFAULT false,
created_at timestamp without time zone NOT NULL DEFAULT now()
);
ALTER TABLE public.outbox OWNER TO postgres;
INSERT INTO public.customer (name, email, password, created_at, updated_at) VALUES (
'John Doe',
'123456',
now(),
now()
);
INSERT INTO public.bread_maker (name, email, created_at, updated_at) VALUES (
'Jake Maker',
now(),
now()
);