diff --git a/sql/swh-vault-schema.sql b/sql/swh-vault-schema.sql index b7dad47..1d477f1 100644 --- a/sql/swh-vault-schema.sql +++ b/sql/swh-vault-schema.sql @@ -1,59 +1,59 @@ create table dbversion ( version int primary key, release timestamptz not null, description text not null ); comment on table dbversion is 'Schema update tracking'; insert into dbversion (version, release, description) values (1, now(), 'Initial version'); create domain obj_hash as bytea; create type cook_type as enum ('directory', 'revision_gitfast'); comment on type cook_type is 'Type of the requested bundle'; create type cook_status as enum ('new', 'pending', 'done', 'failed'); comment on type cook_status is 'Status of the cooking'; create table vault_bundle ( id bigserial primary key, type cook_type not null, -- requested cooking type object_id obj_hash not null, -- requested object ID task_id integer, -- scheduler task id task_status cook_status not null default 'new', -- status of the task sticky boolean not null default false, -- bundle cannot expire ts_created timestamptz not null default now(), -- timestamp of creation ts_done timestamptz, -- timestamp of the cooking result ts_last_access timestamptz not null default now(), -- last access progress_msg text -- progress message ); create unique index concurrently vault_bundle_type_object on vault_bundle (type, object_id); create index concurrently vault_bundle_task_id on vault_bundle (task_id); 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); create index concurrently vault_notif_email_email on vault_notif_email (email); create table vault_batch ( id bigserial primary key ); 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 index 0000000..309bf3a --- /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;