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,15 @@ +-- SWH DB schema upgrade +-- from_version: 2 +-- to_version: 3 +-- description: keep unique indices for origins and locations in a hash column + + +create extension pgcrypto; + +insert into dbversion(version, release, description) + values(3, now(), 'Work In Progress'); + +drop index if exists location_path_key; +create unique index on location(digest(path::bytea, 'sha1'::text)); + +drop index if exists origin_url_key; diff --git a/swh/provenance/sql/30-schema.sql b/swh/provenance/sql/30-schema.sql --- a/swh/provenance/sql/30-schema.sql +++ b/swh/provenance/sql/30-schema.sql @@ -16,7 +16,7 @@ -- latest schema version insert into dbversion(version, release, description) - values(2, now(), 'Work In Progress'); + values(3, now(), 'Work In Progress'); -- a Git object ID, i.e., a Git-style salted SHA1 checksum create domain sha1_git as bytea check (length(value) = 20); @@ -70,7 +70,7 @@ create table location ( id bigserial primary key, -- internal identifier of the location - path unix_path unique not null -- path to the location + path unix_path -- path to the location ); comment on column location.id is 'Location internal identifier'; comment on column location.path is 'Path to the location'; @@ -79,7 +79,7 @@ ( id bigserial primary key, -- internal identifier of the origin sha1 sha1_git unique not null, -- intrinsic identifier of the origin - url text unique not null -- url of the origin + url text -- url of the origin ); comment on column origin.id is 'Origin internal identifier'; comment on column origin.sha1 is 'Origin intrinsic identifier'; diff --git a/swh/provenance/sql/60-indexes.sql b/swh/provenance/sql/60-indexes.sql --- a/swh/provenance/sql/60-indexes.sql +++ b/swh/provenance/sql/60-indexes.sql @@ -13,6 +13,8 @@ create unique index on content_in_directory(content); \endif +create extension if not exists pgcrypto; +create unique index on location(digest(path::bytea, 'sha1'::text)); alter table revision_in_origin add primary key (revision, origin); alter table revision_before_revision add primary key (prev, next);