+ create unique index concurrently on snapshot_branch (target_type, target, name);
+ alter table snapshot_branch add constraint snapshot_branch_target_check check ((target_type is null) = (target is null)) not valid;
+ alter table snapshot_branch validate constraint snapshot_branch_target_check;
+ alter table snapshot_branch add constraint snapshot_target_check check (target_type not in ('content', 'directory', 'revision', 'release', 'snapshot') or length(target) = 20) not valid;
+ alter table snapshot_branch validate constraint snapshot_target_check;
-create unique index concurrently on snapshot_branch (name) where target_type is null and target is null;
+ create unique index concurrently on snapshot_branch (name) where target_type is null and target is null;
+\endif
-- snapshot_branches
create unique index concurrently snapshot_branches_pkey on snapshot_branches(snapshot_id, branch_id);
alter table snapshot_branches add primary key using index snapshot_branches_pkey;
+ -- if the author is null, then the date must be null
+ alter table release add constraint release_author_date_check check ((date is null) or (author is not null)) not valid;
+ alter table release validate constraint release_author_date_check;
+\endif
-- metadata_fetcher
create unique index metadata_fetcher_pkey on metadata_fetcher(id);
alter table metadata_fetcher add primary key using index metadata_fetcher_pkey;
-create unique index metadata_fetcher_name_version on metadata_fetcher(name, version);
+\if :dbflavor_does_deduplication
+ create unique index metadata_fetcher_name_version on metadata_fetcher(name, version);
+\else
+ create index metadata_fetcher_name_version on metadata_fetcher(name, version);
+\endif
-- metadata_authority
create unique index concurrently metadata_authority_pkey on metadata_authority(id);
alter table metadata_authority add primary key using index metadata_authority_pkey;
-create unique index metadata_authority_type_url on metadata_authority(type, url);
+\if :dbflavor_does_deduplication
+ create unique index concurrently metadata_authority_type_url on metadata_authority(type, url);
+\else
+ create index concurrently metadata_authority_type_url on metadata_authority(type, url);
+\endif
+
-- raw_extrinsic_metadata
create unique index concurrently raw_extrinsic_metadata_content_authority_date_fetcher on raw_extrinsic_metadata(id, authority_id, discovery_date, fetcher_id);