Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated endpoints, added job to load github metadata, expanded streak… #119

Merged
merged 4 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ usvg = { workspace = true, features = ["text"] }
rocket_prometheus.workspace = true
utoipa = { workspace = true, features = ["rocket_extras", "chrono"] }
utoipa-swagger-ui = { workspace = true, features = ["rocket"] }
octocrab.workspace = true

shared = { workspace = true, features = ["client"] }
63 changes: 63 additions & 0 deletions server/migrations/20240607131417_streak_repo_metadata.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
BEGIN;

-- Step 1: Create the new streak table
CREATE TABLE IF NOT EXISTS streak (
id INTEGER PRIMARY KEY,
name TEXT UNIQUE NOT NULL,
period TEXT NOT NULL
);

-- Step 2: Insert any missing streak entries into the new streak table
INSERT INTO
streak (id, name, period)
VALUES
(0, 'Weekly Pull Request', 'Weekly'),
(
1,
'Monthly Pull Request with score higher 8',
'Monthly'
);

ALTER TABLE
streak_user_data
ADD
COLUMN new_streak_id INTEGER;

-- Step 4: Copy data from the old streak_id column to the new_streak_id column
UPDATE
streak_user_data
SET
new_streak_id = streak_user_data.streak_id;

-- Step 5: Drop the old streak_id column
ALTER TABLE
streak_user_data DROP COLUMN streak_id;

-- Step 6: Rename the new_streak_id column to streak_id
ALTER TABLE
streak_user_data RENAME COLUMN new_streak_id TO streak_id;

-- Step 7: Add the foreign key constraint to the new streak_id column
ALTER TABLE
streak_user_data
ADD
CONSTRAINT fk_streak_id FOREIGN KEY (streak_id) REFERENCES streak(id) ON DELETE CASCADE;

-- Step 8: Re-add the primary key constraint
ALTER TABLE
streak_user_data
ADD
PRIMARY KEY (user_id, streak_id);

ALTER TABLE
repos
ADD
COLUMN primary_language TEXT,
ADD
COLUMN open_issues INTEGER,
ADD
COLUMN stars INTEGER,
ADD
COLUMN forks INTEGER;

COMMIT;
3 changes: 3 additions & 0 deletions server/sql/get_leaderboard.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ SELECT
prs_merged,
best as streak_best,
amount as streak_amount,
period as streak_type,
streak.name as streak_name,
latest_time_string as streak_latest_time_string
FROM
user_period_data
JOIN users ON users.id = user_period_data.user_id
JOIN streak_user_data ON streak_user_data.user_id = users.id
JOIN streak ON streak.id = streak_user_data.streak_id
WHERE
period_type = $1
and streak_user_data.streak_id = $2
Expand Down
12 changes: 10 additions & 2 deletions server/sql/get_repo_leaderboard.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ SELECT
r.name AS name,
COALESCE(COUNT(pr.id), 0) AS total_prs,
COALESCE(SUM(pr.score), 0) AS total_score,
tc.contributor_name AS top_contributor
tc.contributor_name AS top_contributor,
r.primary_language,
r.open_issues,
r.stars,
r.forks
FROM
repos r
JOIN organizations o ON r.organization_id = o.id
Expand All @@ -30,7 +34,11 @@ FROM
GROUP BY
o.name,
r.name,
tc.contributor_name
tc.contributor_name,
r.primary_language,
r.open_issues,
r.stars,
r.forks
ORDER BY
total_score DESC,
total_prs DESC
Expand Down
7 changes: 7 additions & 0 deletions server/sql/get_repos.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
r.id as repo_id,
r.name as repo,
o.name as organization
from
repos as r
JOIN organizations o ON r.organization_id = o.id
12 changes: 12 additions & 0 deletions server/sql/get_streaks_for_user_id.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
SELECT
streak.id as streak_id,
name,
period as streak_type,
amount,
best,
latest_time_string
FROM
streak_user_data
JOIN streak ON streak.id = streak_user_data.streak_id
WHERE
user_id = $1
Loading
Loading