diff --git a/sql/swh-vault-schema.sql b/sql/swh-vault-schema.sql --- a/sql/swh-vault-schema.sql +++ b/sql/swh-vault-schema.sql @@ -40,7 +40,7 @@ create table vault_notif_email ( id bigserial primary key, email text not null, -- e-mail to notify - bundle_id bigint not null references vault_bundle(id) + bundle_id bigint not null references vault_bundle(id) on delete cascade ); create index concurrently vault_notif_email_bundle on vault_notif_email (bundle_id); @@ -52,8 +52,8 @@ ); create table vault_batch_bundle ( - batch_id bigint not null references vault_batch(id), - bundle_id bigint not null references vault_bundle(id) + batch_id bigint not null references vault_batch(id) on delete cascade, + bundle_id bigint not null references vault_bundle(id) on delete cascade ); create unique index concurrently vault_batch_bundle_pkey on vault_batch_bundle (batch_id, bundle_id); diff --git a/sql/upgrades/003.sql b/sql/upgrades/003.sql new file mode 100644 --- /dev/null +++ b/sql/upgrades/003.sql @@ -0,0 +1,28 @@ +-- SWH DB schema upgrade +-- from_version: 002 +-- to_version: 003 +-- description: Add delete cascade conditions + +insert into dbversion(version, release, description) + values(3, now(), 'Add delete cascade conditions'); + +alter table vault_notif_email + drop constraint "vault_notif_email_bundle_id_fkey", + add constraint "vault_notif_email_bundle_id_fkey" + foreign key(bundle_id) + references vault_bundle + on delete cascade; + +alter table vault_batch_bundle + drop constraint "vault_batch_bundle_bundle_id_fkey", + add constraint "vault_batch_bundle_bundle_id_fkey" + foreign key(bundle_id) + references vault_bundle + on delete cascade; + +alter table vault_batch_bundle + drop constraint "vault_batch_bundle_batch_id_fkey", + add constraint "vault_batch_bundle_batch_id_fkey" + foreign key(batch_id) + references vault_batch + on delete cascade;