generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 7
/
deleteUbsUser.sql
149 lines (104 loc) · 4.98 KB
/
deleteUbsUser.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
-- This SQL script delete all UBS User's;
-- Drop all constraint for change constraint type to cascade;
alter table orders drop constraint fk1evtdroba5rlynltqtprpcaay;
alter table orders
add constraint fk1evtdroba5rlynltqtprpcaay
foreign key (ubs_user_id) references ubs_user
on delete cascade ;
alter table events drop constraint fk_events_order_id;
alter table events add constraint fk_events_order_id
foreign key (order_id) references orders
on delete cascade;
alter table order_additional drop constraint fkpry0lrfjcpcpjo0wl6w6spscy;
alter table order_additional
add constraint fkpry0lrfjcpcpjo0wl6w6spscy
foreign key (orders_id) references orders
on delete cascade;
alter table order_bag_mapping drop constraint fkpkamv5em3c345mcyo3b6gr50a;
alter table order_bag_mapping
add constraint fkpkamv5em3c345mcyo3b6gr50a
foreign key (order_id) references orders
on delete cascade;
alter table payment drop constraint fk_payment_to_order;
alter table payment
add constraint fk_payment_to_order
foreign key (order_id) references orders
on delete cascade ;
alter table user_notifications drop constraint fk_user_notifications_order_id;
alter table user_notifications
add constraint fk_user_notifications_order_id
foreign key (order_id) references orders
on DELETE cascade;
alter table violations_description_mapping drop constraint fk5d5vb0bsddsipw5kdyd5bhfx;
alter table violations_description_mapping
add constraint fk5d5vb0bsddsipw5kdyd5bhfx
foreign key (order_id) references orders
on update restrict on delete cascade;
alter table certificate drop constraint fkpk7mwwg8e6a5owtr4bmxpum7b;
alter table certificate
add constraint fkpk7mwwg8e6a5owtr4bmxpum7b
foreign key(order_id) references orders
on delete cascade ;
alter table change_of_points drop constraint fk5s2hfa0bsddsipw5kdyd5bhfx;
alter table change_of_points
add constraint fk5s2hfa0bsddsipw5kdyd5bhfx
foreign key (order_id) references orders
on update restrict on delete cascade ;
alter table notification_parameters drop constraint fk_notification_id;
alter table notification_parameters
add constraint fk_notification_id
foreign key (notification_id) references user_notifications
on delete cascade ;
alter table violation_images drop constraint fk_violation_image_mapping;
alter table violation_images
add constraint fk_violation_image_mapping
foreign key (violation_id) references violations_description_mapping
on DELETE cascade ;
-- Now we can delete all data and reference from table ubs_users and
delete from ubs_user;
-- Restore all references to previous state
alter table orders drop constraint fk1evtdroba5rlynltqtprpcaay;
alter table orders
add constraint fk1evtdroba5rlynltqtprpcaay
foreign key (ubs_user_id) references ubs_user;
alter table events drop constraint fk_events_order_id;
alter table events add constraint fk_events_order_id
foreign key (order_id) references orders;
alter table order_additional drop constraint fkpry0lrfjcpcpjo0wl6w6spscy;
alter table order_additional
add constraint fkpry0lrfjcpcpjo0wl6w6spscy
foreign key (orders_id) references orders;
alter table order_bag_mapping drop constraint fkpkamv5em3c345mcyo3b6gr50a;
alter table order_bag_mapping
add constraint fkpkamv5em3c345mcyo3b6gr50a
foreign key (order_id) references orders;
alter table payment drop constraint fk_payment_to_order;
alter table payment
add constraint fk_payment_to_order
foreign key (order_id) references orders;
alter table user_notifications drop constraint fk_user_notifications_order_id;
alter table user_notifications
add constraint fk_user_notifications_order_id
foreign key (order_id) references orders;
alter table violations_description_mapping drop constraint fk5d5vb0bsddsipw5kdyd5bhfx;
alter table violations_description_mapping
add constraint fk5d5vb0bsddsipw5kdyd5bhfx
foreign key (order_id) references orders
on update restrict on delete restrict;
alter table certificate drop constraint fkpk7mwwg8e6a5owtr4bmxpum7b;
alter table certificate
add constraint fkpk7mwwg8e6a5owtr4bmxpum7b
foreign key(order_id) references orders;
alter table change_of_points drop constraint fk5s2hfa0bsddsipw5kdyd5bhfx;
alter table change_of_points
add constraint fk5s2hfa0bsddsipw5kdyd5bhfx
foreign key (order_id) references orders
on update restrict on delete restrict;
alter table notification_parameters drop constraint fk_notification_id;
alter table notification_parameters
add constraint fk_notification_id
foreign key (notification_id) references user_notifications;
alter table violation_images drop constraint fk_violation_image_mapping;
alter table violation_images
add constraint fk_violation_image_mapping
foreign key (violation_id) references violations_description_mapping;