-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_schema_and_initial_data.sql
75 lines (61 loc) · 1.7 KB
/
database_schema_and_initial_data.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
-- create a database, connect to it and then run the following code
create table users (
id serial primary key,
username varchar,
password varchar,
name varchar,
email varchar);
CREATE TABLE roles (
id serial primary key,
role varchar
);
CREATE TABLE users_roles (
user_id INTEGER REFERENCES users,
role_id INTEGER REFERENCES roles,
PRIMARY KEY (user_id, role_id)
);
create table contacts (
id serial primary key,
name varchar,
phone varchar,
address varchar,
email varchar,
notes text,
created timestamp with time zone);
create table deals (
id serial primary key,
name varchar,
responsible_id int references users,
contact_id int references contacts,
status varchar,
price int,
probability int,
created timestamp with time zone,
updated timestamp with time zone);
create table notes (
id serial primary key,
note text,
deal_id int references deals on update cascade on delete cascade,
user_id int references users on update cascade on delete restrict,
created timestamp with time zone);
create table dashboard (
id serial primary key,
content text,
created timestamp with time zone,
"type" varchar, -- deal created, deal updated, deal deleted, note created, note deleted,
user_id int references users,
deal_id int references deals);
-- data
insert into users (username, password) values
('admin', 'admin');
insert into roles (role) values
('admin');
insert into users_roles (user_id, role_id) values
(1, 1);
insert into contacts (name) values
('Sérgio Ruoso');
insert into deals (name, responsible_id, contact_id, price) values
('Deal 1', 1, 1, '700');
insert into notes (note, deal_id, user_id) values
('Body of note', 1, 1),
('Note note', 1, 1);