manned/util/update_indices.sql
Yorhel 902048e282 Change database dump format + add import & export scripts
The new format allows for downloading and importing only a part of the
database - useful when only the metadata is required - and doesn't
include the wasteful preformatted HTML cache.

This also ensures that the new import.sql script is actually usable and
in sync with the actual database. The old schema.sql was neither.

(And this simplifies my backup scripts)
2025-10-08 09:40:53 +02:00

21 lines
976 B
PL/PgSQL

-- Create a new table before replacing in order to avoid a long-held lock on
-- the table being replaced. The site should remain responsive while these
-- queries are run.
BEGIN;
CREATE TABLE stats_cache_new AS
SELECT (SELECT count(*) FROM contents) AS hashes,
(SELECT count(distinct name) FROM mans) AS mans, *
FROM (SELECT count(*), count(distinct pkgver) FROM files) x(files, packages);
DROP TABLE IF EXISTS stats_cache;
ALTER TABLE stats_cache_new RENAME TO stats_cache;
COMMIT;
-- Update c_hasman.
-- This query is commented out because the indexer will take care to set the
-- c_hasman column automatically. It's included here as "documentation" so it
-- can be run manually when package versions or man pages are removed from the
-- database.
--
-- UPDATE packages SET c_hasman = NOT c_hasman
-- WHERE c_hasman <> EXISTS(SELECT 1 FROM package_versions pv WHERE pv.package = packages.id AND EXISTS(SELECT 1 FROM files f WHERE f.pkgver = pv.id));