Skip to content

Commit

Permalink
Fix: view counts for many-to-many relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
dabico committed Apr 12, 2024
1 parent e69ae90 commit 102d135
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 5 additions & 3 deletions flyway/sql/V15__label.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ DROP TABLE IF EXISTS label_ranked;

CREATE OR REPLACE VIEW count_git_repo_by_label AS
SELECT
label_id,
label.id AS label_id,
COUNT(repo_id) AS count
FROM git_repo_label
GROUP BY label_id;
FROM label
LEFT JOIN git_repo_label
ON git_repo_label.label_id = label.id
GROUP BY label.id;

CREATE TABLE label_statistics (
label_id BIGINT NOT NULL
Expand Down
8 changes: 5 additions & 3 deletions flyway/sql/V16__topic.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ DROP TABLE IF EXISTS topic_ranked;

CREATE OR REPLACE VIEW count_git_repo_by_topic AS
SELECT
topic_id,
topic.id AS topic_id,
COUNT(repo_id) AS count
FROM git_repo_topic
GROUP BY topic_id;
FROM topic
LEFT JOIN git_repo_topic
ON topic.id = git_repo_topic.topic_id
GROUP BY topic.id;

CREATE TABLE topic_statistics (
topic_id BIGINT NOT NULL
Expand Down

0 comments on commit 102d135

Please sign in to comment.