1 | -- public.favourites definition
|
---|
2 |
|
---|
3 | -- Drop table
|
---|
4 |
|
---|
5 | -- DROP TABLE public.favourites;
|
---|
6 |
|
---|
7 | CREATE TABLE public.favourites (
|
---|
8 | user_id int4 NOT NULL,
|
---|
9 | map_id int4 NOT NULL,
|
---|
10 | CONSTRAINT favourites_pkey PRIMARY KEY (user_id, map_id)
|
---|
11 | );
|
---|
12 |
|
---|
13 |
|
---|
14 | -- public.favourites foreign keys
|
---|
15 |
|
---|
16 | ALTER TABLE public.favourites ADD CONSTRAINT favourites_map_id_fkey FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE;
|
---|
17 | ALTER TABLE public.favourites ADD CONSTRAINT favourites_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
---|
18 |
|
---|
19 |
|
---|
20 | -- public.floors definition
|
---|
21 |
|
---|
22 | -- Drop table
|
---|
23 |
|
---|
24 | -- DROP TABLE public.floors;
|
---|
25 |
|
---|
26 | CREATE TABLE public.floors (
|
---|
27 | num int4 NOT NULL,
|
---|
28 | map_id int4 NOT NULL,
|
---|
29 | map_data jsonb NULL,
|
---|
30 | CONSTRAINT floors_pkey PRIMARY KEY (map_id, num)
|
---|
31 | );
|
---|
32 |
|
---|
33 |
|
---|
34 | -- public.floors foreign keys
|
---|
35 |
|
---|
36 | ALTER TABLE public.floors ADD CONSTRAINT floors_map_id_fkey FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE;
|
---|
37 |
|
---|
38 | -- public.maps definition
|
---|
39 |
|
---|
40 | -- Drop table
|
---|
41 |
|
---|
42 | -- DROP TABLE public.maps;
|
---|
43 |
|
---|
44 | CREATE TABLE public.maps (
|
---|
45 | id serial4 NOT NULL,
|
---|
46 | "name" varchar(64) NULL,
|
---|
47 | gmaps_url text NULL,
|
---|
48 | published_at timestamp NULL,
|
---|
49 | created_at timestamp NULL,
|
---|
50 | modified_at timestamp NULL,
|
---|
51 | image_url text NULL,
|
---|
52 | usr_id int4 NULL,
|
---|
53 | status varchar(16) NULL,
|
---|
54 | map_type varchar(64) NULL,
|
---|
55 | is_published bool DEFAULT false NULL,
|
---|
56 | CONSTRAINT maps_pkey PRIMARY KEY (id)
|
---|
57 | );
|
---|
58 |
|
---|
59 |
|
---|
60 | -- public.maps foreign keys
|
---|
61 |
|
---|
62 | ALTER TABLE public.maps ADD CONSTRAINT maps_usr_id_fkey FOREIGN KEY (usr_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
---|
63 |
|
---|
64 | -- public.permissions definition
|
---|
65 |
|
---|
66 | -- Drop table
|
---|
67 |
|
---|
68 | -- DROP TABLE public.permissions;
|
---|
69 |
|
---|
70 | CREATE TABLE public.permissions (
|
---|
71 | id serial4 NOT NULL,
|
---|
72 | "name" varchar(64) NOT NULL,
|
---|
73 | CONSTRAINT permissions_name_key UNIQUE (name),
|
---|
74 | CONSTRAINT permissions_pkey PRIMARY KEY (id)
|
---|
75 | );
|
---|
76 |
|
---|
77 | -- public.publish_form definition
|
---|
78 |
|
---|
79 | -- Drop table
|
---|
80 |
|
---|
81 | -- DROP TABLE public.publish_form;
|
---|
82 |
|
---|
83 | CREATE TABLE public.publish_form (
|
---|
84 | id serial4 NOT NULL,
|
---|
85 | "name" varchar(64) NULL,
|
---|
86 | last_name varchar(64) NULL,
|
---|
87 | gmaps_url text NULL,
|
---|
88 | map_type varchar(64) NULL,
|
---|
89 | resolved bool DEFAULT false NULL,
|
---|
90 | user_id int4 NULL,
|
---|
91 | map_id int4 NULL,
|
---|
92 | CONSTRAINT publish_form_pkey PRIMARY KEY (id)
|
---|
93 | );
|
---|
94 |
|
---|
95 |
|
---|
96 | -- public.publish_form foreign keys
|
---|
97 |
|
---|
98 | ALTER TABLE public.publish_form ADD CONSTRAINT publish_form_map_id_fkey FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE;
|
---|
99 | ALTER TABLE public.publish_form ADD CONSTRAINT publish_form_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
---|
100 |
|
---|
101 | -- public.reports definition
|
---|
102 |
|
---|
103 | -- Drop table
|
---|
104 |
|
---|
105 | -- DROP TABLE public.reports;
|
---|
106 |
|
---|
107 | CREATE TABLE public.reports (
|
---|
108 | id serial4 NOT NULL,
|
---|
109 | user_id int4 NOT NULL,
|
---|
110 | subject varchar(255) NOT NULL,
|
---|
111 | "content" text NOT NULL,
|
---|
112 | created_at timestamp NOT NULL,
|
---|
113 | map_id int4 NULL,
|
---|
114 | CONSTRAINT reports_pkey PRIMARY KEY (id)
|
---|
115 | );
|
---|
116 |
|
---|
117 |
|
---|
118 | -- public.reports foreign keys
|
---|
119 |
|
---|
120 | ALTER TABLE public.reports ADD CONSTRAINT reports_map_id_fkey FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE;
|
---|
121 | ALTER TABLE public.reports ADD CONSTRAINT reports_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
---|
122 |
|
---|
123 | -- public.roles definition
|
---|
124 |
|
---|
125 | -- Drop table
|
---|
126 |
|
---|
127 | -- DROP TABLE public.roles;
|
---|
128 |
|
---|
129 | CREATE TABLE public.roles (
|
---|
130 | id serial4 NOT NULL,
|
---|
131 | "name" varchar(64) NOT NULL,
|
---|
132 | CONSTRAINT roles_name_key UNIQUE (name),
|
---|
133 | CONSTRAINT roles_pkey PRIMARY KEY (id)
|
---|
134 | );
|
---|
135 |
|
---|
136 | -- public.roles_permissions definition
|
---|
137 |
|
---|
138 | -- Drop table
|
---|
139 |
|
---|
140 | -- DROP TABLE public.roles_permissions;
|
---|
141 |
|
---|
142 | CREATE TABLE public.roles_permissions (
|
---|
143 | role_id int4 NOT NULL,
|
---|
144 | permission_id int4 NOT NULL,
|
---|
145 | CONSTRAINT roles_permissions_pkey PRIMARY KEY (role_id, permission_id)
|
---|
146 | );
|
---|
147 |
|
---|
148 |
|
---|
149 | -- public.roles_permissions foreign keys
|
---|
150 |
|
---|
151 | ALTER TABLE public.roles_permissions ADD CONSTRAINT roles_permissions_permission_id_fkey FOREIGN KEY (permission_id) REFERENCES public.permissions(id) ON DELETE CASCADE;
|
---|
152 | ALTER TABLE public.roles_permissions ADD CONSTRAINT roles_permissions_role_id_fkey FOREIGN KEY (role_id) REFERENCES public.roles(id) ON DELETE CASCADE;
|
---|
153 |
|
---|
154 | -- public.room_types definition
|
---|
155 |
|
---|
156 | -- Drop table
|
---|
157 |
|
---|
158 | -- DROP TABLE public.room_types;
|
---|
159 |
|
---|
160 | CREATE TABLE public.room_types (
|
---|
161 | id serial4 NOT NULL,
|
---|
162 | map_id int4 NULL,
|
---|
163 | "name" varchar(64) NULL,
|
---|
164 | CONSTRAINT room_types_name_map_id_key UNIQUE (name, map_id),
|
---|
165 | CONSTRAINT room_types_pkey PRIMARY KEY (id)
|
---|
166 | );
|
---|
167 |
|
---|
168 |
|
---|
169 | -- public.room_types foreign keys
|
---|
170 |
|
---|
171 | ALTER TABLE public.room_types ADD CONSTRAINT room_types_map_id_fkey FOREIGN KEY (map_id) REFERENCES public.maps(id) ON DELETE CASCADE;
|
---|
172 |
|
---|
173 | -- public.users definition
|
---|
174 |
|
---|
175 | -- Drop table
|
---|
176 |
|
---|
177 | -- DROP TABLE public.users;
|
---|
178 |
|
---|
179 | CREATE TABLE public.users (
|
---|
180 | id serial4 NOT NULL,
|
---|
181 | username varchar(64) NULL,
|
---|
182 | "password" text NULL,
|
---|
183 | email varchar(128) NULL,
|
---|
184 | created_at timestamp NULL,
|
---|
185 | last_login_at timestamp NULL,
|
---|
186 | profile_image_url text NULL,
|
---|
187 | oauth_provider varchar(64) NULL,
|
---|
188 | refresh_token text NULL,
|
---|
189 | access_token text NULL,
|
---|
190 | oauth_id varchar(255) NULL,
|
---|
191 | CONSTRAINT unique_email UNIQUE (email),
|
---|
192 | CONSTRAINT unique_username UNIQUE (username),
|
---|
193 | CONSTRAINT users_oauth_id_key UNIQUE (oauth_id),
|
---|
194 | CONSTRAINT users_pkey PRIMARY KEY (id)
|
---|
195 | );
|
---|
196 |
|
---|
197 | -- public.users_roles definition
|
---|
198 |
|
---|
199 | -- Drop table
|
---|
200 |
|
---|
201 | -- DROP TABLE public.users_roles;
|
---|
202 |
|
---|
203 | CREATE TABLE public.users_roles (
|
---|
204 | user_id int4 NOT NULL,
|
---|
205 | role_id int4 NOT NULL,
|
---|
206 | CONSTRAINT users_roles_pkey PRIMARY KEY (user_id, role_id)
|
---|
207 | );
|
---|
208 |
|
---|
209 |
|
---|
210 | -- public.users_roles foreign keys
|
---|
211 |
|
---|
212 | ALTER TABLE public.users_roles ADD CONSTRAINT users_roles_role_id_fkey FOREIGN KEY (role_id) REFERENCES public.roles(id) ON DELETE CASCADE;
|
---|
213 | ALTER TABLE public.users_roles ADD CONSTRAINT users_roles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id) ON DELETE CASCADE;
|
---|
214 |
|
---|