+ create index concurrently on revision(directory); -- to be reviewed
+ create unique index concurrently on revision(object_id); -- to be reviewed
+\endif
+
+-- revision_history
+create unique index concurrently revision_history_pkey on revision_history(id, parent_rank);
+alter table revision_history add primary key using index revision_history_pkey;
+
+\if :dbflavor_default
+ create index concurrently on revision_history(parent_id); -- to be reviewed
+\endif
+
+\if :dbflavor_does_deduplication
+ alter table revision_history add constraint revision_history_id_fkey foreign key (id) references revision(id) not valid;
+ alter table revision_history validate constraint revision_history_id_fkey;
+\endif
+
+-- snapshot
+create unique index concurrently snapshot_pkey on snapshot(object_id);
+alter table snapshot add primary key using index snapshot_pkey;
+
+\if :dbflavor_does_deduplication
+ create unique index concurrently on snapshot(id);
+\else
+ create index concurrently on snapshot(id);
+\endif
+
+-- snapshot_branch
+create unique index concurrently snapshot_branch_pkey on snapshot_branch(object_id);
+alter table snapshot_branch add primary key using index snapshot_branch_pkey;
+
+\if :dbflavor_does_deduplication
+ 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;
+\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 :dbflavor_does_deduplication
+ alter table snapshot_branches add constraint snapshot_branches_snapshot_id_fkey foreign key (snapshot_id) references snapshot(object_id) not valid;
+ alter table snapshot_branches validate constraint snapshot_branches_snapshot_id_fkey;
+
+ alter table snapshot_branches add constraint snapshot_branches_branch_id_fkey foreign key (branch_id) references snapshot_branch(object_id) not valid;
+ alter table snapshot_branches validate constraint snapshot_branches_branch_id_fkey;
+\endif
+
+-- origin_visit
+create unique index concurrently origin_visit_pkey on origin_visit(origin, visit);
+alter table origin_visit add primary key using index origin_visit_pkey;
+
+\if :dbflavor_default
+ create index concurrently on origin_visit(date); -- to be reviewed
+ create index concurrently origin_visit_type_date on origin_visit(type, date); -- to be reviewed
+\endif
+
+\if :dbflavor_does_deduplication
+ alter table origin_visit add constraint origin_visit_origin_fkey foreign key (origin) references origin(id) not valid;
+ alter table origin_visit validate constraint origin_visit_origin_fkey;
+\endif
+
+-- origin_visit_status
+
+create unique index concurrently origin_visit_status_pkey on origin_visit_status(origin, visit, date);
+alter table origin_visit_status add primary key using index origin_visit_status_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;
+
+\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;
+
+\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(target, authority_id, discovery_date, fetcher_id);
+
+\if :dbflavor_default
+ alter table raw_extrinsic_metadata add constraint raw_extrinsic_metadata_authority_fkey foreign key (authority_id) references metadata_authority(id) not valid;
+ alter table raw_extrinsic_metadata validate constraint raw_extrinsic_metadata_authority_fkey;
+
+ alter table raw_extrinsic_metadata add constraint raw_extrinsic_metadata_fetcher_fkey foreign key (fetcher_id) references metadata_fetcher(id) not valid;
+ alter table raw_extrinsic_metadata validate constraint raw_extrinsic_metadata_fetcher_fkey;
+\endif
+
+-- object_counts
+create unique index concurrently object_counts_pkey on object_counts(object_type);
+alter table object_counts add primary key using index object_counts_pkey;
+
+-- object_counts_bucketed
+create unique index concurrently object_counts_bucketed_pkey on object_counts_bucketed(line);
+alter table object_counts_bucketed add primary key using index object_counts_bucketed_pkey;