| author | Tomas Zeman <tzeman@volny.cz> |
| Tue, 05 Jun 2012 15:40:43 +0200 | |
| changeset 101 | b6a00fd29998 |
| parent 100 | 1fcbeae1f9da |
| child 104 | ef29ecada49d |
| permissions | -rw-r--r-- |
| 36 | 1 |
-- table declarations : |
2 |
create table "code_list_item" ( |
|
| 92 | 3 |
"id" bigint primary key not null, |
| 36 | 4 |
"name" varchar(100) not null, |
| 92 | 5 |
"i18n" boolean not null, |
| 36 | 6 |
"rank" integer not null, |
| 92 | 7 |
"dflt" boolean not null, |
| 36 | 8 |
"code_list" varchar(40) not null, |
9 |
"note" varchar(10240), |
|
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
10 |
"created_at" timestamp not null, |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
11 |
"created_by" bigint, |
| 92 | 12 |
"updated_at" timestamp not null, |
13 |
"updated_by" bigint, |
|
14 |
"i1" integer not null, |
|
| 36 | 15 |
"i2" integer not null, |
| 92 | 16 |
"i3" integer not null, |
17 |
"l1" bigint not null, |
|
| 36 | 18 |
"l2" bigint not null, |
| 92 | 19 |
"l3" bigint not null, |
20 |
"s1" varchar(200) not null, |
|
21 |
"s2" varchar(200) not null, |
|
22 |
"s3" varchar(200) not null, |
|
23 |
"oi1" integer, |
|
24 |
"oi2" integer, |
|
25 |
"oi3" integer, |
|
26 |
"ol1" bigint, |
|
27 |
"ol2" bigint, |
|
| 36 | 28 |
"ol3" bigint, |
| 92 | 29 |
"os1" varchar(200), |
30 |
"os2" varchar(200), |
|
| 36 | 31 |
"os3" varchar(200), |
32 |
"deleted" boolean not null |
|
33 |
); |
|
34 |
create sequence "code_list_item_id_seq"; |
|
35 |
-- indexes on code_list_item |
|
36 |
create index "code_list_item_code_list_idx" on "code_list_item" ("code_list");
|
|
37 |
create table "city" ( |
|
| 92 | 38 |
"id" bigint primary key not null, |
| 36 | 39 |
"name" varchar(100) not null, |
| 92 | 40 |
"note" varchar(10240), |
| 36 | 41 |
"country_id" bigint not null, |
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
42 |
"created_at" timestamp not null, |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
43 |
"created_by" bigint, |
| 92 | 44 |
"updated_at" timestamp not null, |
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
45 |
"updated_by" bigint |
| 36 | 46 |
); |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
47 |
create sequence "city_id_seq"; |
| 36 | 48 |
create table "address" ( |
| 92 | 49 |
"id" bigint primary key not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
50 |
"name" varchar(100) not null, |
| 92 | 51 |
"street_name" varchar(100) not null, |
52 |
"street_num" varchar(100) not null, |
|
| 36 | 53 |
"zip_code" varchar(100) not null, |
| 92 | 54 |
"city_id" bigint not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
55 |
"note" varchar(10240), |
|
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
56 |
"created_at" timestamp not null, |
|
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
57 |
"created_by" bigint, |
| 92 | 58 |
"updated_at" timestamp not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
59 |
"updated_by" bigint |
| 36 | 60 |
); |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
61 |
create sequence "address_id_seq"; |
| 36 | 62 |
create table "country" ( |
| 92 | 63 |
"id" bigint primary key not null, |
| 36 | 64 |
"name" varchar(100) not null, |
65 |
"iso2" varchar(2) not null, |
|
| 92 | 66 |
"iso3" varchar(3) not null, |
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
67 |
"note" varchar(10240), |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
68 |
"created_at" timestamp not null, |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
69 |
"created_by" bigint, |
| 92 | 70 |
"updated_at" timestamp not null, |
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
71 |
"updated_by" bigint |
| 36 | 72 |
); |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
73 |
create sequence "country_id_seq"; |
| 76 | 74 |
create table "location" ( |
| 92 | 75 |
"id" bigint primary key not null, |
| 76 | 76 |
"name" varchar(100) not null, |
| 92 | 77 |
"address_id" bigint not null, |
78 |
"note" varchar(10240), |
|
| 76 | 79 |
"latitude" double precision not null, |
80 |
"longitude" double precision not null, |
|
81 |
"created_at" timestamp not null, |
|
82 |
"created_by" bigint, |
|
| 92 | 83 |
"updated_at" timestamp not null, |
| 76 | 84 |
"updated_by" bigint |
85 |
); |
|
86 |
create sequence "location_id_seq"; |
|
| 36 | 87 |
create table "contact" ( |
| 92 | 88 |
"id" bigint primary key not null, |
| 36 | 89 |
"name" varchar(100) not null, |
| 92 | 90 |
"first_name" varchar(80) not null, |
91 |
"last_name" varchar(80) not null, |
|
92 |
"position" varchar(40), |
|
93 |
"note" varchar(10240), |
|
94 |
"work_mail" varchar(256) not null, |
|
95 |
"work_phone" varchar(40), |
|
| 36 | 96 |
"work_mobile" varchar(40) not null, |
97 |
"private_mail" varchar(256), |
|
| 92 | 98 |
"private_phone" varchar(40), |
99 |
"private_mobile" varchar(40), |
|
100 |
"other_mail" varchar(256), |
|
101 |
"other_mobile" varchar(40), |
|
| 36 | 102 |
"fax" varchar(40), |
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
103 |
"created_at" timestamp not null, |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
104 |
"created_by" bigint, |
| 92 | 105 |
"updated_at" timestamp not null, |
106 |
"updated_by" bigint |
|
| 36 | 107 |
); |
108 |
create sequence "contact_id_seq"; |
|
109 |
create table "company" ( |
|
| 92 | 110 |
"id" bigint primary key not null, |
| 36 | 111 |
"name" varchar(100) not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
112 |
"dic" varchar(40) not null, |
| 36 | 113 |
"ico" varchar(40) not null, |
114 |
"note" varchar(10240), |
|
| 91 | 115 |
"status" bigint not null, |
| 92 | 116 |
"address_id" bigint not null, |
117 |
"post_adress_id" bigint, |
|
118 |
"pin" integer not null, |
|
|
61
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
119 |
"created_at" timestamp not null, |
|
b65843860274
Trackable entity: created/updated fields
Tomas Zeman <tzeman@volny.cz>
parents:
56
diff
changeset
|
120 |
"created_by" bigint, |
| 92 | 121 |
"updated_at" timestamp not null, |
122 |
"updated_by" bigint |
|
| 36 | 123 |
); |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
124 |
create sequence "company_id_seq"; |
| 36 | 125 |
create table "bank_account" ( |
| 92 | 126 |
"id" bigint primary key not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
127 |
"name" varchar(100) not null, |
| 36 | 128 |
"prefix" bigint not null, |
| 92 | 129 |
"number" bigint not null, |
| 36 | 130 |
"bank_code" varchar(100) not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
131 |
"company_id" bigint not null, |
|
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
132 |
"note" varchar(10240), |
|
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
133 |
"created_at" timestamp not null, |
|
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
134 |
"created_by" bigint, |
| 92 | 135 |
"updated_at" timestamp not null, |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
136 |
"updated_by" bigint |
| 36 | 137 |
); |
|
65
a35a0edf9ddd
Geo+Company record refactoring
Tomas Zeman <tzeman@volny.cz>
parents:
61
diff
changeset
|
138 |
create sequence "bank_account_id_seq"; |
| 72 | 139 |
create table "company_contact" ( |
140 |
"contact" bigint not null, |
|
141 |
"entity" bigint not null |
|
142 |
); |
|
| 73 | 143 |
create table "user" ( |
| 92 | 144 |
"id" bigint primary key not null, |
| 73 | 145 |
"name" varchar(100) not null, |
| 92 | 146 |
"login" varchar(40) not null, |
| 73 | 147 |
"note" varchar(10240), |
| 92 | 148 |
"active" boolean not null, |
149 |
"password" varchar(128) not null, |
|
150 |
"deleted" boolean not null, |
|
| 73 | 151 |
"created_at" timestamp not null, |
152 |
"created_by" bigint, |
|
| 92 | 153 |
"updated_at" timestamp not null, |
154 |
"updated_by" bigint |
|
| 73 | 155 |
); |
156 |
create sequence "user_id_seq"; |
|
157 |
-- indexes on user |
|
158 |
create index "user_login_idx" on "user" ("login");
|
|
159 |
create table "user_contact" ( |
|
160 |
"contact" bigint not null, |
|
161 |
"entity" bigint not null |
|
162 |
); |
|
| 100 | 163 |
create table "attachment" ( |
164 |
"name" varchar(100) not null, |
|
165 |
"updated_at" timestamp not null, |
|
166 |
"id" bigint primary key not null, |
|
167 |
"mime_type" varchar(80) not null, |
|
168 |
"content_id" varchar(20) not null, |
|
169 |
"size" bigint not null, |
|
170 |
"note" varchar(10240), |
|
171 |
"created_at" timestamp not null, |
|
172 |
"created_by" bigint, |
|
173 |
"updated_by" bigint |
|
174 |
); |
|
175 |
create sequence "attachment_id_seq"; |
|
| 79 | 176 |
create table "project" ( |
| 92 | 177 |
"id" bigint primary key not null, |
| 79 | 178 |
"name" varchar(100) not null, |
179 |
"description" varchar(40960) not null, |
|
180 |
"responsible" bigint not null, |
|
181 |
"deadline" timestamp not null, |
|
182 |
"ident_s" varchar(256) not null, |
|
183 |
"state" bigint not null, |
|
| 92 | 184 |
"product_line" bigint, |
| 79 | 185 |
"note" varchar(10240), |
186 |
"created_at" timestamp not null, |
|
187 |
"created_by" bigint, |
|
| 92 | 188 |
"updated_at" timestamp not null, |
| 79 | 189 |
"updated_by" bigint |
190 |
); |
|
191 |
create sequence "project_id_seq"; |
|
| 81 | 192 |
create table "task" ( |
| 92 | 193 |
"id" bigint primary key not null, |
| 81 | 194 |
"name" varchar(100) not null, |
| 101 | 195 |
"num" integer not null, |
| 81 | 196 |
"project_id" bigint not null, |
197 |
"responsible" bigint not null, |
|
198 |
"deadline" timestamp not null, |
|
199 |
"state" bigint not null, |
|
| 92 | 200 |
"task_type" bigint, |
| 81 | 201 |
"note" varchar(10240), |
202 |
"created_at" timestamp not null, |
|
203 |
"created_by" bigint, |
|
| 92 | 204 |
"updated_at" timestamp not null, |
| 81 | 205 |
"updated_by" bigint |
206 |
); |
|
207 |
create sequence "task_id_seq"; |
|
| 83 | 208 |
create table "comment" ( |
| 92 | 209 |
"id" bigint primary key not null, |
| 83 | 210 |
"name" varchar(100) not null, |
211 |
"task_id" bigint not null, |
|
212 |
"note" varchar(10240), |
|
213 |
"created_at" timestamp not null, |
|
214 |
"created_by" bigint, |
|
| 92 | 215 |
"updated_at" timestamp not null, |
| 83 | 216 |
"updated_by" bigint |
217 |
); |
|
218 |
create sequence "comment_id_seq"; |
|
| 85 | 219 |
create table "project_company" ( |
220 |
"project" bigint not null, |
|
221 |
"company" bigint not null |
|
222 |
); |
|
|
98
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
223 |
create table "project_location" ( |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
224 |
"location" bigint not null, |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
225 |
"project" bigint not null |
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
226 |
); |
| 100 | 227 |
create table "project_attachment" ( |
228 |
"project" bigint not null, |
|
229 |
"attachment" bigint not null |
|
230 |
); |
|
231 |
create table "task_attachment" ( |
|
232 |
"task" bigint not null, |
|
233 |
"attachment" bigint not null |
|
234 |
); |
|
| 99 | 235 |
create table "service" ( |
236 |
"name" varchar(100) not null, |
|
237 |
"updated_at" timestamp not null, |
|
238 |
"id" bigint primary key not null, |
|
239 |
"to" timestamp, |
|
240 |
"state" bigint not null, |
|
241 |
"company" bigint not null, |
|
242 |
"note" varchar(10240), |
|
243 |
"from" timestamp not null, |
|
244 |
"created_at" timestamp not null, |
|
245 |
"created_by" bigint, |
|
246 |
"updated_by" bigint |
|
247 |
); |
|
248 |
create sequence "service_id_seq"; |
|
249 |
create table "service_payment" ( |
|
250 |
"id" bigint primary key not null, |
|
251 |
"service" bigint not null, |
|
252 |
"direction" integer not null, |
|
253 |
"period" bigint not null, |
|
254 |
"amount" numeric(16,2) not null, |
|
255 |
"currency" bigint not null |
|
256 |
); |
|
257 |
create sequence "service_payment_id_seq"; |
|
| 36 | 258 |
-- foreign key constraints : |
| 92 | 259 |
alter table "address" add foreign key ("city_id") references "city"("id");
|
260 |
alter table "city" add foreign key ("country_id") references "country"("id");
|
|
261 |
alter table "location" add foreign key ("address_id") references "address"("id");
|
|
262 |
alter table "company" add foreign key ("status") references "code_list_item"("id");
|
|
263 |
alter table "company" add foreign key ("address_id") references "address"("id");
|
|
264 |
alter table "company" add foreign key ("post_adress_id") references "address"("id") on delete set null;
|
|
265 |
alter table "bank_account" add foreign key ("company_id") references "company"("id") on delete cascade;
|
|
266 |
alter table "project" add foreign key ("responsible") references "user"("id");
|
|
267 |
alter table "project" add foreign key ("product_line") references "code_list_item"("id") on delete set null;
|
|
268 |
alter table "project" add foreign key ("state") references "code_list_item"("id");
|
|
269 |
alter table "task" add foreign key ("responsible") references "user"("id");
|
|
270 |
alter table "task" add foreign key ("task_type") references "code_list_item"("id");
|
|
271 |
alter table "task" add foreign key ("state") references "code_list_item"("id");
|
|
272 |
alter table "task" add foreign key ("project_id") references "project"("id");
|
|
273 |
alter table "comment" add foreign key ("task_id") references "task"("id") on delete cascade;
|
|
| 99 | 274 |
alter table "service" add foreign key ("company") references "company"("id");
|
275 |
alter table "service" add foreign key ("state") references "code_list_item"("id");
|
|
| 92 | 276 |
alter table "company_contact" add foreign key ("entity") references "company"("id") on delete cascade;
|
| 99 | 277 |
alter table "service_payment" add foreign key ("service") references "service"("id") on delete cascade;
|
278 |
alter table "service_payment" add foreign key ("period") references "code_list_item"("id");
|
|
279 |
alter table "service_payment" add foreign key ("currency") references "code_list_item"("id");
|
|
| 92 | 280 |
alter table "company_contact" add foreign key ("contact") references "contact"("id") on delete cascade;
|
281 |
alter table "user_contact" add foreign key ("entity") references "user"("id") on delete cascade;
|
|
282 |
alter table "user_contact" add foreign key ("contact") references "contact"("id") on delete cascade;
|
|
283 |
alter table "project_company" add foreign key ("project") references "project"("id") on delete cascade;
|
|
284 |
alter table "project_company" add foreign key ("company") references "company"("id") on delete cascade;
|
|
|
98
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
285 |
alter table "project_location" add foreign key ("project") references "project"("id") on delete cascade;
|
|
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
286 |
alter table "project_location" add foreign key ("location") references "location"("id") on delete cascade;
|
| 100 | 287 |
alter table "project_attachment" add foreign key ("project") references "project"("id") on delete cascade;
|
288 |
alter table "project_attachment" add foreign key ("attachment") references "attachment"("id") on delete cascade;
|
|
289 |
alter table "task_attachment" add foreign key ("task") references "task"("id") on delete cascade;
|
|
290 |
alter table "task_attachment" add foreign key ("attachment") references "attachment"("id") on delete cascade;
|
|
| 72 | 291 |
-- composite key indexes : |
| 92 | 292 |
alter table "company_contact" add unique("entity","contact");
|
293 |
alter table "user_contact" add unique("entity","contact");
|
|
294 |
alter table "project_company" add unique("project","company");
|
|
|
98
eac38214183d
9830b81e1c79d212 Project locations
Tomas Zeman <tzeman@volny.cz>
parents:
92
diff
changeset
|
295 |
alter table "project_location" add unique("project","location");
|
| 100 | 296 |
alter table "project_attachment" add unique("project","attachment");
|
297 |
alter table "task_attachment" add unique("task","attachment");
|
|
| 56 | 298 |
-- column group indexes : |
299 |
create index "user_deleted_active_idx" on "user" ("deleted","active");
|