Keep views tracked when a pkg or repo is removed (#2572)

Signed-off-by: Sergio Castaño Arteaga <tegioz@icloud.com>
This commit is contained in:
Sergio Castaño Arteaga 2022-12-05 15:08:01 +01:00 committed by GitHub
parent a4be2500a9
commit 81a085be12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -62,6 +62,7 @@ returns setof json as $$
sum(total) as total
from package_views
where day = current_date
and package_id is not null
group by package_id
order by total desc
limit 10
@ -79,6 +80,7 @@ returns setof json as $$
from package_views
where date_trunc('year', day) = date_trunc('year', current_date)
and date_trunc('month', day) = date_trunc('month', current_date)
and package_id is not null
group by package_id
order by total desc
limit 10

View File

@ -0,0 +1,18 @@
alter table package_views alter column package_id drop not null;
alter table package_views alter column version drop not null;
alter table package_views drop constraint package_views_package_id_version_fkey;
alter table package_views add constraint package_views_package_id_version_fkey
foreign key (package_id, version)
references snapshot (package_id, version)
on delete set null;
---- create above / drop below ----
delete from package_views where package_id is null;
alter table package_views alter column package_id set not null;
alter table package_views alter column version set not null;
alter table package_views drop constraint package_views_package_id_version_fkey;
alter table package_views add constraint package_views_package_id_version_fkey
foreign key (package_id, version)
references snapshot (package_id, version)
on delete cascade;