diff --git a/sql/upgrades/124.sql b/sql/upgrades/124.sql index 249560a2f..c2018c830 100644 --- a/sql/upgrades/124.sql +++ b/sql/upgrades/124.sql @@ -1,35 +1,36 @@ -- SWH DB schema upgrade -- from_version: 123 -- to_version: 124 -- description: Enable to paginate, filter and count snapshot content insert into dbversion(version, release, description) values(124, now(), 'Work In Progress'); DROP FUNCTION swh_snapshot_get_by_id(id public.sha1_git); CREATE TYPE snapshot_size AS ( target_type public.snapshot_target, "count" bigint ); -CREATE OR REPLACE FUNCTION swh_snapshot_count_branches(id public.sha1_git) RETURNS SETOF public.snapshot_size - LANGUAGE sql STABLE - AS $$ - SELECT target_type, count(name) - from swh_snapshot_get_by_id(swh_snapshot_count_branches.id) - group by target_type; -$$; - CREATE OR REPLACE FUNCTION swh_snapshot_get_by_id(id public.sha1_git, branches_from bytea = '\x'::bytea, branches_count bigint = NULL::bigint, target_types public.snapshot_target[] = NULL::public.snapshot_target[]) RETURNS SETOF public.snapshot_result LANGUAGE sql STABLE AS $$ select swh_snapshot_get_by_id.id as snapshot_id, name, target, target_type from snapshot_branches inner join snapshot_branch on snapshot_branches.branch_id = snapshot_branch.object_id where snapshot_id = (select object_id from snapshot where snapshot.id = swh_snapshot_get_by_id.id) and (target_types is null or target_type = any(target_types)) and name >= branches_from order by name limit branches_count -$$; \ No newline at end of file +$$; + +CREATE OR REPLACE FUNCTION swh_snapshot_count_branches(id public.sha1_git) RETURNS SETOF public.snapshot_size + LANGUAGE sql STABLE + AS $$ + SELECT target_type, count(name) + from swh_snapshot_get_by_id(swh_snapshot_count_branches.id) + group by target_type; +$$; + diff --git a/sql/upgrades/125.sql b/sql/upgrades/125.sql index 30f251b58..664eb51a7 100644 --- a/sql/upgrades/125.sql +++ b/sql/upgrades/125.sql @@ -1,70 +1,60 @@ -- SWH DB schema upgrade -- from_version: 124 -- to_version: 125 -- description: Drop useless entity tables insert into dbversion(version, release, description) values(125, now(), 'Work In Progress'); DROP FUNCTION swh_entity_from_tmp_entity_lister(); DROP FUNCTION swh_entity_get(entity_uuid uuid); DROP FUNCTION swh_entity_history_add(); DROP FUNCTION swh_mktemp_entity_history(); DROP FUNCTION swh_mktemp_entity_lister(); -DROP FUNCTION swh_update_entity_from_entity_history(); +DROP FUNCTION swh_update_entity_from_entity_history() cascade; ALTER TABLE origin - DROP CONSTRAINT origin_lister_fkey; - -ALTER TABLE origin - DROP CONSTRAINT origin_project_fkey; - -DROP TABLE entity; - -DROP TABLE entity_equivalence; - -DROP TABLE entity_history; + DROP COLUMN lister, + DROP COLUMN project; DROP TABLE list_history; DROP TABLE listable_entity; -DROP SEQUENCE entity_history_id_seq; +DROP TABLE entity_equivalence; -DROP SEQUENCE list_history_id_seq; +DROP TABLE entity; -DROP TYPE entity_type; +DROP TABLE entity_history; DROP TYPE entity_id; -ALTER TABLE origin - DROP COLUMN lister, - DROP COLUMN project; +DROP TYPE entity_type; CREATE OR REPLACE FUNCTION swh_stat_counters() RETURNS SETOF public.counter LANGUAGE sql STABLE AS $$ select object_type as label, value as value from object_counts where object_type in ( 'content', 'directory', 'directory_entry_dir', 'directory_entry_file', 'directory_entry_rev', 'occurrence_history', 'origin', 'origin_visit', 'person', 'release', 'revision', 'revision_history', 'skipped_content', 'snapshot' ); $$;