-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.sql
More file actions
82 lines (82 loc) · 2.17 KB
/
init.sql
File metadata and controls
82 lines (82 loc) · 2.17 KB
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
create table users
(
id serial
primary key,
address varchar not null,
phone_number varchar not null,
username varchar not null,
email varchar not null,
firstname varchar not null,
second_name varchar,
lastname varchar not null,
second_lastname varchar,
password varchar not null,
role_id integer not null
constraint users_roles_id_fk
references roles
on update cascade on delete cascade,
enabled BOOLEAN DEFAULT TRUE,
constraint users_pk
unique (address, phone_number)
);
create table roles
(
id serial
constraint roles_pk
primary key,
name varchar not null
constraint roles_pk_2
unique
);
create table addresses
(
id serial not null
constraint addresses_pk
primary key,
street varchar not null,
number varchar not null,
constraint unique_address
unique (street, number)
);
create table refresh_tokens
(
id serial
primary key,
token text not null,
user_id integer not null
constraint fk_user
references users,
created_at timestamp not null,
expires_at timestamp not null,
is_valid boolean default true,
ip_address varchar(45),
user_agent text,
last_used_at timestamp
);
create table packages
(
id SERIAL PRIMARY KEY,
service VARCHAR NOT NULL,
received_at TIMESTAMP NOT NULL,
confirmed_at TIMESTAMP,
address_id INT NOT NULL,
status INT NOT NULL,
CONSTRAINT fk_address
FOREIGN KEY (address_id) REFERENCES addresses(id)
);
create table role_permissions (
id SERIAL PRIMARY KEY,
role_id INTEGER NOT NULL
CONSTRAINT fk_role_permission_role
REFERENCES roles(id) ON DELETE CASCADE,
entity VARCHAR NOT NULL,
permission VARCHAR NOT NULL
);
create table user_permissions (
id SERIAL PRIMARY KEY,
user_id INTEGER NOT NULL
CONSTRAINT fk_user_permission_user
REFERENCES users(id) ON DELETE CASCADE,
entity VARCHAR NOT NULL,
permission VARCHAR NOT NULL
);