diff --git a/sql/swh-vault-schema.sql b/sql/swh-vault-schema.sql index 3f5640e..8e874e7 100644 --- a/sql/swh-vault-schema.sql +++ b/sql/swh-vault-schema.sql @@ -1,42 +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 - - unique(type, object_id) ); +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) ); +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) +); +create unique index concurrently vault_batch_bundle_pkey + on vault_batch_bundle (batch_id, bundle_id); diff --git a/sql/upgrades/002.sql b/sql/upgrades/002.sql new file mode 100644 index 0000000..42c1da8 --- /dev/null +++ b/sql/upgrades/002.sql @@ -0,0 +1,28 @@ +-- SWH DB schema upgrade +-- from_version: 001 +-- to_version: 002 +-- description: Add batches and various indexes + +insert into dbversion(version, release, description) + values(2, now(), 'Add batches and various indexes'); + +create unique index concurrently if not exists vault_bundle_type_object + on vault_bundle (type, object_id); +create index concurrently if not exists vault_bundle_task_id + on vault_bundle (task_id); + +create index concurrently if not exists vault_notif_email_bundle + on vault_notif_email (bundle_id); +create index concurrently if not exists vault_notif_email_email + on vault_notif_email (email); + +create table if not exists vault_batch ( + id bigserial primary key +); + +create table if not exists vault_batch_bundle ( + batch_id bigint not null references vault_batch(id), + bundle_id bigint not null references vault_bundle(id) +); +create unique index concurrently if not exists vault_batch_bundle_pkey + on vault_batch_bundle (batch_id, bundle_id);