-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate.sql
632 lines (509 loc) · 19.6 KB
/
create.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
create table crm.accounts (
account_id serial not null,
created_date date,
updated_date date,
email varchar(255),
enabled boolean,
pwd varchar(255),
primary key (account_id)
);
create table crm.cities (
city_id serial not null,
created_date date,
updated_date date,
city varchar(255),
state_id int4,
primary key (city_id)
);
create table crm.langs (
lang_id varchar(255) not null,
lang varchar(255),
primary key (lang_id)
);
create table crm.roles (
role_id varchar(255) not null,
role varchar(255),
primary key (role_id)
);
create table crm.specs (
spec_id varchar(255) not null,
created_date date,
updated_date date,
primary key (spec_id)
);
create table crm.specs_translations (
spec_id varchar(255) not null,
translation_id int4 not null,
primary key (spec_id, translation_id)
);
create table crm.states (
state_id int4 not null,
state varchar(255),
primary key (state_id)
);
create table crm.translations (
translation_id serial not null,
created_date date,
updated_date date,
translation varchar(255),
lang_id varchar(255),
primary key (translation_id)
);
create table crm.users (
user_id serial not null,
created_date date,
updated_date date,
enabled boolean,
fiscal_code varchar(255),
name varchar(255),
surname varchar(255),
account_id int4,
role_id varchar(255),
primary key (user_id)
);
create table crm.users_specs (
user_id varchar(255) not null,
spec_id varchar(255) not null
);
alter table crm.accounts
drop constraint UK_n7ihswpy07ci568w34q0oi8he;
alter table crm.accounts
add constraint UK_n7ihswpy07ci568w34q0oi8he unique (email);
alter table crm.specs_translations
drop constraint UK_rprrremgfbtxyyi92hptxldtb;
alter table crm.specs_translations
add constraint UK_rprrremgfbtxyyi92hptxldtb unique (translation_id);
alter table crm.users
drop constraint UK_p8rpwek75uww1cmxdsofs8f78;
alter table crm.users
add constraint UK_p8rpwek75uww1cmxdsofs8f78 unique (fiscal_code);
alter table crm.users_specs
drop constraint UK_bwpl0irc5k4yvd17gr9lgp0sv;
alter table crm.users_specs
add constraint UK_bwpl0irc5k4yvd17gr9lgp0sv unique (spec_id);
create table ecommerce.categories (
category_id serial not null,
created_date date,
updated_date date,
primary key (category_id)
);
create table ecommerce.categories_translations (
category_id int4 not null,
translation_id int4 not null,
primary key (category_id, translation_id)
);
create table ecommerce.products (
product_id serial not null,
created_date date,
updated_date date,
price numeric(19, 2) not null,
quantity int4 not null,
primary key (product_id)
);
create table ecommerce.products_categories (
product_id int4 not null,
category_id int4 not null
);
create table ecommerce.products_translations (
product_id int4 not null,
translation_id int4 not null
);
create table ecommerce.stores (
store_id serial not null,
created_date date,
updated_date date,
store varchar(255),
postal_code int4,
street varchar(255),
city_id int4,
primary key (store_id)
);
create table ecommerce.stores_products (
store_id int4,
product_id int4 not null,
primary key (product_id)
);
create table ecommerce.users_cart (
user_cart_id serial not null,
created_date date,
updated_date date,
quantity int4 not null,
total_price numeric(19, 2) not null,
product_id int4 not null,
user_id varchar(255) not null,
primary key (user_cart_id)
);
create table ecommerce.users_orders (
user_id varchar(255) not null,
product_id int4 not null
);
create table ecommerce.users_stores (
user_id varchar(255) not null,
store_id int4 not null,
primary key (store_id)
);
alter table ecommerce.categories_translations
drop constraint UK_py3e8qvx7d4xnj6fxff4mvpba;
alter table ecommerce.categories_translations
add constraint UK_py3e8qvx7d4xnj6fxff4mvpba unique (translation_id);
alter table ecommerce.products_categories
drop constraint UK_h68v82rb4q1qff468ds4vwqyj;
alter table ecommerce.products_categories
add constraint UK_h68v82rb4q1qff468ds4vwqyj unique (category_id);
alter table ecommerce.products_translations
drop constraint UK_jy3wdun3ew6u4vrlfd223q2td;
alter table ecommerce.products_translations
add constraint UK_jy3wdun3ew6u4vrlfd223q2td unique (translation_id);
alter table ecommerce.users_orders
drop constraint UK_j97n30reigwj9vevjyyp2jcyo;
alter table ecommerce.users_orders
add constraint UK_j97n30reigwj9vevjyyp2jcyo unique (product_id);
create sequence hibernate_sequence start 1 increment 1;
alter table crm.cities
add constraint FKsu54e1tlhaof4oklvv7uphsli
foreign key (state_id)
references crm.states;
alter table crm.specs_translations
add constraint FKjs150rtqp7n1pqfemyf76998
foreign key (translation_id)
references crm.translations;
alter table crm.specs_translations
add constraint FKfysw7e34flxi8yfg6muga8r1x
foreign key (spec_id)
references crm.specs;
alter table crm.translations
add constraint FKmvnsfvvmnjg6r19p5e2j2a04b
foreign key (lang_id)
references crm.langs;
alter table crm.users
add constraint FKfm8rm8ks0kgj4fhlmmljkj17x
foreign key (account_id)
references crm.accounts;
alter table crm.users
add constraint FKp56c1712k691lhsyewcssf40f
foreign key (role_id)
references crm.roles;
alter table crm.users_specs
add constraint FKdvlpowdsnvivbe5bjoxgi4c9e
foreign key (spec_id)
references crm.specs;
alter table crm.users_specs
add constraint FK7qvsc4p1qi6hx5a8eb4fuql9u
foreign key (user_id)
references crm.users;
alter table ecommerce.categories_translations
add constraint FKtiocd34bxare1dffuyfrfje0e
foreign key (translation_id)
references crm.translations;
alter table ecommerce.categories_translations
add constraint FK811cpj5ahrgngxsevcgbvqeax
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKqt6m2o5dly3luqcm00f5t4h2p
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKtj1vdea8qwerbjqie4xldl1el
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.products_translations
add constraint FKckn1e460u8nmap2b5rerycfwm
foreign key (translation_id)
references crm.translations;
alter table ecommerce.products_translations
add constraint FKrb4l1n108cy7ifj53kuvfw0hr
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.stores
add constraint FKoi3i5uaki2wfnk0mjvf4513gb
foreign key (city_id)
references crm.cities;
alter table ecommerce.stores_products
add constraint FKkr69gr3x80v60hd9d2bmjpbti
foreign key (store_id)
references ecommerce.stores;
alter table ecommerce.stores_products
add constraint FKnql58gp9lehxhda6tytrv7cc4
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FK97rl4on9o8349tff3yc7yt8n5
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FKdn91r1vbqdmcgxrcnwxokfjys
foreign key (user_id)
references crm.users;
alter table ecommerce.users_orders
add constraint FK787nkee14cbw4v063f31e69ro
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_orders
add constraint FKms88pdhtsiuuusjpeij73f6df
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FK41enlc1xt5092gudcwk0sryv3
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FKffw2be032gwcrfodb6hswr8dh
foreign key (store_id)
references ecommerce.stores;
alter table crm.users_specs
add constraint FK7qvsc4p1qi6hx5a8eb4fuql9u
foreign key (user_id)
references crm.users;
alter table ecommerce.categories_translations
add constraint FKtiocd34bxare1dffuyfrfje0e
foreign key (translation_id)
references crm.translations;
alter table ecommerce.categories_translations
add constraint FK811cpj5ahrgngxsevcgbvqeax
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKqt6m2o5dly3luqcm00f5t4h2p
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKtj1vdea8qwerbjqie4xldl1el
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.products_translations
add constraint FKckn1e460u8nmap2b5rerycfwm
foreign key (translation_id)
references crm.translations;
alter table ecommerce.products_translations
add constraint FKrb4l1n108cy7ifj53kuvfw0hr
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.stores
add constraint FKoi3i5uaki2wfnk0mjvf4513gb
foreign key (city_id)
references crm.cities;
alter table ecommerce.stores_products
add constraint FKkr69gr3x80v60hd9d2bmjpbti
foreign key (store_id)
references ecommerce.stores;
alter table ecommerce.stores_products
add constraint FKnql58gp9lehxhda6tytrv7cc4
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FK97rl4on9o8349tff3yc7yt8n5
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FKdn91r1vbqdmcgxrcnwxokfjys
foreign key (user_id)
references crm.users;
alter table ecommerce.users_orders
add constraint FK787nkee14cbw4v063f31e69ro
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_orders
add constraint FKms88pdhtsiuuusjpeij73f6df
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FK41enlc1xt5092gudcwk0sryv3
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FKffw2be032gwcrfodb6hswr8dh
foreign key (store_id)
references ecommerce.stores;
alter table crm.users_specs
add constraint FK7qvsc4p1qi6hx5a8eb4fuql9u
foreign key (user_id)
references crm.users;
alter table ecommerce.categories_translations
add constraint FKtiocd34bxare1dffuyfrfje0e
foreign key (translation_id)
references crm.translations;
alter table ecommerce.categories_translations
add constraint FK811cpj5ahrgngxsevcgbvqeax
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKqt6m2o5dly3luqcm00f5t4h2p
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKtj1vdea8qwerbjqie4xldl1el
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.products_translations
add constraint FKckn1e460u8nmap2b5rerycfwm
foreign key (translation_id)
references crm.translations;
alter table ecommerce.products_translations
add constraint FKrb4l1n108cy7ifj53kuvfw0hr
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.stores
add constraint FKoi3i5uaki2wfnk0mjvf4513gb
foreign key (city_id)
references crm.cities;
alter table ecommerce.stores_products
add constraint FKkr69gr3x80v60hd9d2bmjpbti
foreign key (store_id)
references ecommerce.stores;
alter table ecommerce.stores_products
add constraint FKnql58gp9lehxhda6tytrv7cc4
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FK97rl4on9o8349tff3yc7yt8n5
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FKdn91r1vbqdmcgxrcnwxokfjys
foreign key (user_id)
references crm.users;
alter table ecommerce.users_orders
add constraint FK787nkee14cbw4v063f31e69ro
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_orders
add constraint FKms88pdhtsiuuusjpeij73f6df
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FK41enlc1xt5092gudcwk0sryv3
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FKffw2be032gwcrfodb6hswr8dh
foreign key (store_id)
references ecommerce.stores;
alter table crm.users_specs
add constraint FK7qvsc4p1qi6hx5a8eb4fuql9u
foreign key (user_id)
references crm.users;
alter table ecommerce.categories_translations
add constraint FKtiocd34bxare1dffuyfrfje0e
foreign key (translation_id)
references crm.translations;
alter table ecommerce.categories_translations
add constraint FK811cpj5ahrgngxsevcgbvqeax
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKqt6m2o5dly3luqcm00f5t4h2p
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKtj1vdea8qwerbjqie4xldl1el
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.products_translations
add constraint FKckn1e460u8nmap2b5rerycfwm
foreign key (translation_id)
references crm.translations;
alter table ecommerce.products_translations
add constraint FKrb4l1n108cy7ifj53kuvfw0hr
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.stores
add constraint FKoi3i5uaki2wfnk0mjvf4513gb
foreign key (city_id)
references crm.cities;
alter table ecommerce.stores_products
add constraint FKkr69gr3x80v60hd9d2bmjpbti
foreign key (store_id)
references ecommerce.stores;
alter table ecommerce.stores_products
add constraint FKnql58gp9lehxhda6tytrv7cc4
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FK97rl4on9o8349tff3yc7yt8n5
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FKdn91r1vbqdmcgxrcnwxokfjys
foreign key (user_id)
references crm.users;
alter table ecommerce.users_orders
add constraint FK787nkee14cbw4v063f31e69ro
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_orders
add constraint FKms88pdhtsiuuusjpeij73f6df
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FK41enlc1xt5092gudcwk0sryv3
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FKffw2be032gwcrfodb6hswr8dh
foreign key (store_id)
references ecommerce.stores;
alter table crm.users_specs
add constraint FK7qvsc4p1qi6hx5a8eb4fuql9u
foreign key (user_id)
references crm.users;
alter table ecommerce.categories_translations
add constraint FKtiocd34bxare1dffuyfrfje0e
foreign key (translation_id)
references crm.translations;
alter table ecommerce.categories_translations
add constraint FK811cpj5ahrgngxsevcgbvqeax
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKqt6m2o5dly3luqcm00f5t4h2p
foreign key (category_id)
references ecommerce.categories;
alter table ecommerce.products_categories
add constraint FKtj1vdea8qwerbjqie4xldl1el
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.products_translations
add constraint FKckn1e460u8nmap2b5rerycfwm
foreign key (translation_id)
references crm.translations;
alter table ecommerce.products_translations
add constraint FKrb4l1n108cy7ifj53kuvfw0hr
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.stores
add constraint FKoi3i5uaki2wfnk0mjvf4513gb
foreign key (city_id)
references crm.cities;
alter table ecommerce.stores_products
add constraint FKkr69gr3x80v60hd9d2bmjpbti
foreign key (store_id)
references ecommerce.stores;
alter table ecommerce.stores_products
add constraint FKnql58gp9lehxhda6tytrv7cc4
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FK97rl4on9o8349tff3yc7yt8n5
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_cart
add constraint FKdn91r1vbqdmcgxrcnwxokfjys
foreign key (user_id)
references crm.users;
alter table ecommerce.users_orders
add constraint FK787nkee14cbw4v063f31e69ro
foreign key (product_id)
references ecommerce.products;
alter table ecommerce.users_orders
add constraint FKms88pdhtsiuuusjpeij73f6df
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FK41enlc1xt5092gudcwk0sryv3
foreign key (user_id)
references crm.users;
alter table ecommerce.users_stores
add constraint FKffw2be032gwcrfodb6hswr8dh
foreign key (store_id)
references ecommerce.stores;