create extension if not exists btree_gist;

create domain sha1 as bytea check (length(value) = 20);
create domain sha1_git as bytea check (length(value) = 20);

create table origin_intrinsic_metadata(
  origin_id                 bigserial  not null,
  metadata                  jsonb,
  indexer_configuration_id  bigint     not null,
  from_revision             sha1_git   not null,
  metadata_tsvector         tsvector,
  mappings                  text array not null
);

comment on table origin_intrinsic_metadata is 'keeps intrinsic metadata for an origin';
comment on column origin_intrinsic_metadata.origin_id is 'the entry id in origin';
comment on column origin_intrinsic_metadata.metadata is 'metadata extracted from a revision';
comment on column origin_intrinsic_metadata.indexer_configuration_id is 'tool used to generate this metadata';
comment on column origin_intrinsic_metadata.from_revision is 'sha1 of the revision this metadata was copied from.';
comment on column origin_intrinsic_metadata.mappings is 'type of metadata files used to obtain this metadata (eg. pkg-info, npm)';
