forked from jtpedersen/poodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createdb.sql
78 lines (60 loc) · 2.03 KB
/
createdb.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
begin transaction;
create language 'plpgsql';
CREATE OR REPLACE FUNCTION update_updated()
RETURNS TRIGGER AS $$
BEGIN
NEW.updated = now();
RETURN NEW;
END;
$$ language 'plpgsql';
create table pizza_place (
id serial primary key,
created timestamp default now(),
updated timestamp default now(),
name varchar(100),
logo_img varchar(100),
url varchar(100),
catalog_url varchar(100),
phone_1 integer,
phone_2 integer
);
CREATE TRIGGER update_updated BEFORE UPDATE
ON pizza_place FOR EACH ROW EXECUTE PROCEDURE
update_updated();
insert into pizza_place(name, logo_img, url, catalog_url, phone_1, phone_2)
values ('Liberta', NULL, 'http://www.vericenter.dk/Butikker/Pizzeria_Liberta.aspx', 'http://www.just-eat.dk/restaurants-liberta/menu-2201', 86217898, 86217888);
create table pizza_order (
id serial primary key,
created timestamp default now(),
updated timestamp default now(),
pizza_order text default 'hack mad',
pizza_place integer references pizza_place(id),
admin_uuid varchar(42) unique ,
user_uuid varchar(42) unique ,
driver varchar(100),
collector varchar(100),
pickup_time timestamp default NULL,
order_time timestamp default NULL
);
CREATE TRIGGER update_updated BEFORE UPDATE
ON pizza_order FOR EACH ROW EXECUTE PROCEDURE
update_updated();
create table pizza (
id serial primary key, -- pizza id
created timestamp default now(),
updated timestamp default now(),
order_id integer references pizza_order(id),
username varchar(150),
pizza_id varchar(50),
comment varchar(1024),
price numeric(5,2) default 60, --max prize 999.99
chili boolean,
garlic boolean,
cheese boolean,
bacon boolean,
paid boolean
);
CREATE TRIGGER update_updated BEFORE UPDATE
ON pizza FOR EACH ROW EXECUTE PROCEDURE
update_updated();
commit;