Skip to content

Commit

Permalink
Merge pull request #185 from sebadob/fix-fk-cascade-user-attr-values
Browse files Browse the repository at this point in the history
Add an FK constraint for `user_attr_values` and cascade on user deletion
  • Loading branch information
sebadob authored Nov 24, 2023
2 parents ed76418 + e01ecc1 commit 1dc730c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions migrations/postgres/14_user_attr_values_fk_fix.sql
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;
22 changes: 22 additions & 0 deletions migrations/sqlite/14_user_attr_values_fk_fix.sql
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;

0 comments on commit 1dc730c

Please sign in to comment.