-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #185 from sebadob/fix-fk-cascade-user-attr-values
Add an FK constraint for `user_attr_values` and cascade on user deletion
- Loading branch information
Showing
2 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
alter table user_attr_values | ||
add constraint user_attr_values_users_id_fk | ||
foreign key (user_id) references users | ||
on update cascade on delete cascade; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
create table user_attr_values_dg_tmp | ||
( | ||
user_id varchar not null | ||
constraint user_attr_values_users_id_fk | ||
references users | ||
on update cascade on delete cascade, | ||
key varchar not null | ||
references user_attr_config | ||
on update cascade on delete cascade, | ||
value blob not null, | ||
constraint user_attr_values_pk | ||
primary key (user_id, key) | ||
); | ||
|
||
insert into user_attr_values_dg_tmp(user_id, key, value) | ||
select user_id, key, value | ||
from user_attr_values; | ||
|
||
drop table user_attr_values; | ||
|
||
alter table user_attr_values_dg_tmp | ||
rename to user_attr_values; |