Skip to content

Commit

Permalink
Rename repositories_history table (repology/repology-rs#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
AMDmi3 committed Dec 17, 2024
1 parent 8dfc3bc commit ded6174
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 30 deletions.
4 changes: 2 additions & 2 deletions sql.d/schema/create_schema_tables.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
25 changes: 1 addition & 24 deletions sql.d/update/update_histories.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions sql.d/update/update_post.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit ded6174

Please sign in to comment.