From ded6174c0f682b63491eea23c551c9fc4719cd92 Mon Sep 17 00:00:00 2001 From: Dmitry Marakasov Date: Tue, 17 Dec 2024 18:01:54 +0300 Subject: [PATCH] Rename repositories_history table (repology/repology-rs#120) --- sql.d/schema/create_schema_tables.sql | 4 ++-- sql.d/update/update_histories.sql | 25 +------------------------ sql.d/update/update_post.sql | 8 ++++---- 3 files changed, 7 insertions(+), 30 deletions(-) diff --git a/sql.d/schema/create_schema_tables.sql b/sql.d/schema/create_schema_tables.sql index 64f10123..61d067c0 100644 --- a/sql.d/schema/create_schema_tables.sql +++ b/sql.d/schema/create_schema_tables.sql @@ -258,9 +258,9 @@ CREATE TABLE repositories ( CREATE UNIQUE INDEX ON repositories(name); -- history -DROP TABLE IF EXISTS repositories_history_new CASCADE; +DROP TABLE IF EXISTS repositories_history CASCADE; -CREATE TABLE repositories_history_new ( +CREATE TABLE repositories_history ( repository_id smallint NOT NULL, ts timestamp with time zone NOT NULL, num_problems integer, diff --git a/sql.d/update/update_histories.sql b/sql.d/update/update_histories.sql index 82f30da7..e1d59859 100644 --- a/sql.d/update/update_histories.sql +++ b/sql.d/update/update_histories.sql @@ -19,30 +19,7 @@ -- History snapshot -------------------------------------------------------------------------------- --- per-repository counters ---INSERT INTO repositories_history ( --- ts, --- snapshot ---) ---SELECT --- now(), --- jsonb_object_agg(snapshot.name, to_jsonb(snapshot) - 'name') ---FROM ( --- SELECT --- name, --- num_metapackages, --- num_metapackages_unique, --- num_metapackages_newest, --- num_metapackages_outdated, --- num_metapackages_comparable, --- num_metapackages_problematic, --- num_problems, --- num_maintainers, --- num_metapackages_vulnerable --- FROM repositories ---) AS snapshot; - -INSERT INTO repositories_history_new ( +INSERT INTO repositories_history ( repository_id, ts, num_problems, diff --git a/sql.d/update/update_post.sql b/sql.d/update/update_post.sql index 9e664b6c..355d198e 100644 --- a/sql.d/update/update_post.sql +++ b/sql.d/update/update_post.sql @@ -90,7 +90,7 @@ WITH duplicate_rows AS ( row({{ fields() }}) AS cur, lead(row({{ fields() }}), 1) OVER w AS next, lag(row({{ fields() }}), 1) OVER w AS prev - FROM repositories_history_new + FROM repositories_history -- Don't unnecessarily thin out the whole table each time - -- just process last week worth of history. This may produce -- leftovers for repostories which had no stat changes for more @@ -100,10 +100,10 @@ WITH duplicate_rows AS ( ) AS tmp WHERE cur = next AND cur = prev ) -DELETE FROM repositories_history_new USING duplicate_rows +DELETE FROM repositories_history USING duplicate_rows WHERE - repositories_history_new.repository_id = duplicate_rows.repository_id AND - repositories_history_new.ts = duplicate_rows.ts; + repositories_history.repository_id = duplicate_rows.repository_id AND + repositories_history.ts = duplicate_rows.ts; {# do it manually for now