[79a0317] | 1 | CREATE TABLE public.permissions (
|
---|
| 2 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 3 | "name" varchar(64) NOT NULL UNIQUE
|
---|
| 4 | );
|
---|
| 5 | CREATE TABLE public.roles (
|
---|
| 6 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 7 | "name" varchar(64) NOT NULL UNIQUE
|
---|
| 8 | );
|
---|
| 9 | CREATE TABLE public.users (
|
---|
| 10 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 11 | username varchar(64) NULL,
|
---|
| 12 | "password" text NULL,
|
---|
| 13 | email varchar(128) NULL,
|
---|
| 14 | created_at timestamp NULL,
|
---|
| 15 | last_login_at timestamp NULL,
|
---|
| 16 | profile_image_url text NULL,
|
---|
| 17 | oauth_provider varchar(64) NULL,
|
---|
| 18 | refresh_token text NULL,
|
---|
| 19 | access_token text NULL,
|
---|
| 20 | oauth_id varchar(255) NULL,
|
---|
| 21 | UNIQUE (email),
|
---|
| 22 | UNIQUE (username),
|
---|
| 23 | UNIQUE (oauth_id)
|
---|
| 24 | );
|
---|
| 25 | CREATE TABLE public.maps (
|
---|
| 26 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 27 | "name" varchar(64) NULL,
|
---|
| 28 | gmaps_url text NULL,
|
---|
| 29 | published_at timestamp NULL,
|
---|
| 30 | created_at timestamp NULL,
|
---|
| 31 | modified_at timestamp NULL,
|
---|
| 32 | image_url text NULL,
|
---|
| 33 | usr_id int4 NULL,
|
---|
| 34 | status varchar(16) NULL,
|
---|
| 35 | map_type varchar(64) NULL,
|
---|
| 36 | is_published bool DEFAULT false NULL,
|
---|
| 37 | FOREIGN KEY (usr_id) REFERENCES public.users(id) ON DELETE CASCADE
|
---|
| 38 | );
|
---|
| 39 | CREATE TABLE public.roles_permissions (
|
---|
| 40 | role_id int4 NOT NULL,
|
---|
| 41 | permission_id int4 NOT NULL,
|
---|
| 42 | PRIMARY KEY (role_id, permission_id),
|
---|
| 43 | FOREIGN KEY (permission_id) REFERENCES public.permissions(id) ON DELETE CASCADE,
|
---|
| 44 | FOREIGN KEY (role_id) REFERENCES public.roles(id) ON DELETE CASCADE
|
---|
| 45 | );
|
---|
| 46 | CREATE TABLE public.users_roles (
|
---|
| 47 | user_id int4 NOT NULL,
|
---|
| 48 | role_id int4 NOT NULL,
|
---|
| 49 | PRIMARY KEY (user_id, role_id),
|
---|
| 50 | FOREIGN KEY (role_id) REFERENCES public.roles(id) ON DELETE CASCADE,
|
---|
| 51 | FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE
|
---|
| 52 | );
|
---|
| 53 | CREATE TABLE public.favourites (
|
---|
| 54 | user_id int4 NOT NULL,
|
---|
| 55 | map_id int4 NOT NULL,
|
---|
| 56 | PRIMARY KEY (user_id, map_id),
|
---|
| 57 | FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE,
|
---|
| 58 | FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE
|
---|
| 59 | );
|
---|
| 60 | CREATE TABLE public.floors (
|
---|
| 61 | num int4 NOT NULL,
|
---|
| 62 | map_id int4 NOT NULL,
|
---|
| 63 | map_data jsonb NULL,
|
---|
| 64 | PRIMARY KEY (map_id, num),
|
---|
| 65 | FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE
|
---|
| 66 | );
|
---|
| 67 | CREATE TABLE public.room_types (
|
---|
| 68 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 69 | map_id int4 NULL,
|
---|
| 70 | "name" varchar(64) NULL,
|
---|
| 71 | UNIQUE (name, map_id),
|
---|
| 72 | FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE
|
---|
| 73 | );
|
---|
| 74 | CREATE TABLE public.publish_form (
|
---|
| 75 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 76 | "name" varchar(64) NULL,
|
---|
| 77 | last_name varchar(64) NULL,
|
---|
| 78 | gmaps_url text NULL,
|
---|
| 79 | map_type varchar(64) NULL,
|
---|
| 80 | resolved bool DEFAULT false NULL,
|
---|
| 81 | user_id int4 NULL,
|
---|
| 82 | map_id int4 NULL,
|
---|
| 83 | FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE,
|
---|
| 84 | FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE
|
---|
| 85 | );
|
---|
| 86 | CREATE TABLE public.reports (
|
---|
| 87 | id serial4 NOT NULL PRIMARY KEY,
|
---|
| 88 | user_id int4 NOT NULL,
|
---|
| 89 | subject varchar(255) NOT NULL,
|
---|
| 90 | "content" text NOT NULL,
|
---|
| 91 | created_at timestamp NOT NULL,
|
---|
| 92 | map_id int4 NULL,
|
---|
| 93 | FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE,
|
---|
| 94 | FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE
|
---|
| 95 | );
|
---|