From eaf660abca3bdfac1f169899362927884f960047 Mon Sep 17 00:00:00 2001 From: Anthony Buisset Date: Wed, 29 Nov 2023 16:37:04 +0100 Subject: [PATCH 1/2] stop projecting project contributors --- api/src/domain/projectors/projections.rs | 10 --- api/src/models/mod.rs | 6 -- api/src/models/projects_contributors/mod.rs | 20 ------ .../projects_contributors/repository.rs | 64 ------------------- .../projects_pending_contributors/mod.rs | 20 ------ .../repository.rs | 62 ------------------ api/src/presentation/http/bootstrap.rs | 2 - api/tests/context/mod.rs | 2 - 8 files changed, 186 deletions(-) delete mode 100644 api/src/models/projects_contributors/mod.rs delete mode 100644 api/src/models/projects_contributors/repository.rs delete mode 100644 api/src/models/projects_pending_contributors/mod.rs delete mode 100644 api/src/models/projects_pending_contributors/repository.rs diff --git a/api/src/domain/projectors/projections.rs b/api/src/domain/projectors/projections.rs index 363268c31a..6739afc01f 100644 --- a/api/src/domain/projectors/projections.rs +++ b/api/src/domain/projectors/projections.rs @@ -20,8 +20,6 @@ pub struct Projector { project_repository: Arc>, project_lead_repository: Arc>, project_github_repos_repository: Arc>, - projects_contributors_repository: Arc, - projects_pending_contributors_repository: Arc, project_budgets_repository: Arc>, applications_repository: Arc>, budget_repository: Arc>, @@ -240,20 +238,12 @@ impl EventListener for Projector { github_repo_id, })?; self.github_repo_index_repository.start_indexing(github_repo_id)?; - self.projects_contributors_repository - .refresh_project_contributor_list(&project_id)?; - self.projects_pending_contributors_repository - .refresh_project_pending_contributor_list(&project_id)?; }, ProjectEvent::GithubRepoUnlinked { id: project_id, github_repo_id, } => { self.project_github_repos_repository.delete((project_id, github_repo_id))?; - self.projects_contributors_repository - .refresh_project_contributor_list(&project_id)?; - self.projects_pending_contributors_repository - .refresh_project_pending_contributor_list(&project_id)?; }, ProjectEvent::Applied { .. } => (), }, diff --git a/api/src/models/mod.rs b/api/src/models/mod.rs index 3d56cc49e4..b729dee3f1 100644 --- a/api/src/models/mod.rs +++ b/api/src/models/mod.rs @@ -19,8 +19,6 @@ mod project_github_repos; mod project_leads; mod projects; mod projects_budgets; -mod projects_contributors; -mod projects_pending_contributors; mod projects_rewarded_users; mod projects_sponsors; mod sponsors; @@ -55,10 +53,6 @@ pub use project_github_repos::{ProjectGithubRepo, Repository as ProjectGithubRep pub use project_leads::ProjectLead; pub use projects::Project; pub use projects_budgets::ProjectsBudget; -pub use projects_contributors::{ProjectsContributor, Repository as ProjectsContributorRepository}; -pub use projects_pending_contributors::{ - ProjectsPendingContributor, Repository as ProjectsPendingContributorRepository, -}; pub use projects_rewarded_users::{ ProjectsRewardedUser, Repository as ProjectsRewardedUserRepository, }; diff --git a/api/src/models/projects_contributors/mod.rs b/api/src/models/projects_contributors/mod.rs deleted file mode 100644 index ef0b7398d7..0000000000 --- a/api/src/models/projects_contributors/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -mod repository; -use diesel::Identifiable; -use domain::{GithubUserId, ProjectId}; -use infrastructure::database::schema::projects_contributors; -pub use repository::Repository; - -#[derive(Debug, Insertable, Identifiable, Queryable, ImmutableModel)] -#[diesel(primary_key(project_id, github_user_id))] -pub struct ProjectsContributor { - pub project_id: ProjectId, - pub github_user_id: GithubUserId, -} - -impl Identifiable for ProjectsContributor { - type Id = (ProjectId, GithubUserId); - - fn id(self) -> Self::Id { - (self.project_id, self.github_user_id) - } -} diff --git a/api/src/models/projects_contributors/repository.rs b/api/src/models/projects_contributors/repository.rs deleted file mode 100644 index 778029c8d9..0000000000 --- a/api/src/models/projects_contributors/repository.rs +++ /dev/null @@ -1,64 +0,0 @@ -use diesel::{Connection, ExpressionMethods, QueryDsl, RunQueryDsl}; -use domain::{GithubRepoId, GithubUserId, ProjectId}; -use infrastructure::{ - contextualized_error::IntoContextualizedError, - database::{ - enums::ContributionStatus, - schema::{contributions, project_github_repos, projects_contributors::dsl}, - }, - dbclient, - dbclient::Result, -}; - -use super::ProjectsContributor; - -pub trait Repository: dbclient::ImmutableRepository { - fn refresh_project_contributor_list(&self, project_id: &ProjectId) - -> Result>; -} - -impl Repository for dbclient::Client { - fn refresh_project_contributor_list( - &self, - project_id: &ProjectId, - ) -> Result> { - let mut connection = self.connection()?; - - let mut contributors: Vec = vec![]; - connection - .transaction::<_, diesel::result::Error, _>(|tx| { - diesel::delete(dsl::projects_contributors) - .filter(dsl::project_id.eq(project_id)) - .execute(&mut *tx)?; - - let repos: Vec = project_github_repos::dsl::project_github_repos - .select(project_github_repos::dsl::github_repo_id) - .filter(project_github_repos::dsl::project_id.eq(project_id)) - .load(&mut *tx)?; - - contributors = contributions::dsl::contributions - .select(contributions::dsl::user_id) - .distinct() - .filter(contributions::dsl::repo_id.eq_any(repos)) - .filter(contributions::dsl::status.eq(ContributionStatus::Complete)) - .load(&mut *tx)?; - - contributors.iter().try_for_each(|user_id| { - diesel::insert_into(dsl::projects_contributors) - .values(( - dsl::project_id.eq(project_id), - dsl::github_user_id.eq(user_id), - )) - .on_conflict_do_nothing() - .execute(&mut *tx)?; - Ok::<(), diesel::result::Error>(()) - })?; - - Ok(()) - }) - .err_with_context(format!( - "refreshing contributors of project with id={project_id}" - ))?; - Ok(contributors) - } -} diff --git a/api/src/models/projects_pending_contributors/mod.rs b/api/src/models/projects_pending_contributors/mod.rs deleted file mode 100644 index 38416f7a50..0000000000 --- a/api/src/models/projects_pending_contributors/mod.rs +++ /dev/null @@ -1,20 +0,0 @@ -mod repository; -use diesel::Identifiable; -use domain::{GithubUserId, ProjectId}; -use infrastructure::database::schema::projects_pending_contributors; -pub use repository::Repository; - -#[derive(Debug, Insertable, Identifiable, Queryable, ImmutableModel)] -#[diesel(primary_key(project_id, github_user_id))] -pub struct ProjectsPendingContributor { - pub project_id: ProjectId, - pub github_user_id: GithubUserId, -} - -impl Identifiable for ProjectsPendingContributor { - type Id = (ProjectId, GithubUserId); - - fn id(self) -> Self::Id { - (self.project_id, self.github_user_id) - } -} diff --git a/api/src/models/projects_pending_contributors/repository.rs b/api/src/models/projects_pending_contributors/repository.rs deleted file mode 100644 index b7c250d4e2..0000000000 --- a/api/src/models/projects_pending_contributors/repository.rs +++ /dev/null @@ -1,62 +0,0 @@ -use diesel::{Connection, ExpressionMethods, QueryDsl, RunQueryDsl}; -use domain::{GithubRepoId, GithubUserId, ProjectId}; -use infrastructure::{ - contextualized_error::IntoContextualizedError, - database::schema::{contributions, project_github_repos, projects_pending_contributors::dsl}, - dbclient, - dbclient::Result, -}; - -use super::ProjectsPendingContributor; - -pub trait Repository: dbclient::ImmutableRepository { - fn refresh_project_pending_contributor_list( - &self, - project_id: &ProjectId, - ) -> Result>; -} - -impl Repository for dbclient::Client { - fn refresh_project_pending_contributor_list( - &self, - project_id: &ProjectId, - ) -> Result> { - let mut connection = self.connection()?; - - let mut contributors: Vec = vec![]; - connection - .transaction::<_, diesel::result::Error, _>(|tx| { - diesel::delete(dsl::projects_pending_contributors) - .filter(dsl::project_id.eq(project_id)) - .execute(&mut *tx)?; - - let repos: Vec = project_github_repos::dsl::project_github_repos - .select(project_github_repos::dsl::github_repo_id) - .filter(project_github_repos::dsl::project_id.eq(project_id)) - .load(&mut *tx)?; - - contributors = contributions::dsl::contributions - .select(contributions::dsl::user_id) - .distinct() - .filter(contributions::dsl::repo_id.eq_any(repos)) - .load(&mut *tx)?; - - contributors.iter().try_for_each(|user_id| { - diesel::insert_into(dsl::projects_pending_contributors) - .values(( - dsl::project_id.eq(project_id), - dsl::github_user_id.eq(user_id), - )) - .on_conflict_do_nothing() - .execute(&mut *tx)?; - Ok::<(), diesel::result::Error>(()) - })?; - - Ok(()) - }) - .err_with_context(format!( - "refreshing pending contributors of project with id={project_id}" - ))?; - Ok(contributors) - } -} diff --git a/api/src/presentation/http/bootstrap.rs b/api/src/presentation/http/bootstrap.rs index 1f24c949d3..747827e3b4 100644 --- a/api/src/presentation/http/bootstrap.rs +++ b/api/src/presentation/http/bootstrap.rs @@ -49,8 +49,6 @@ pub async fn bootstrap(config: Config) -> Result> { database.clone(), database.clone(), database.clone(), - database.clone(), - database.clone(), ); let event_publisher = CompositePublisher::new(vec![ diff --git a/api/tests/context/mod.rs b/api/tests/context/mod.rs index 6ccf2013df..3e20cc0f29 100644 --- a/api/tests/context/mod.rs +++ b/api/tests/context/mod.rs @@ -143,8 +143,6 @@ impl<'a> Context<'a> { database.client.clone(), database.client.clone(), database.client.clone(), - database.client.clone(), - database.client.clone(), ))), ]); From 0e3dfe92e7861d06f61548621f3a5c7652cfb290 Mon Sep 17 00:00:00 2001 From: Anthony Buisset Date: Wed, 29 Nov 2023 17:49:29 +0100 Subject: [PATCH 2/2] fix integration tests --- api/src/models/crypto_usd_quotes copy.rs | 33 -------- api/tests/crypto_quotes_sync_it.rs | 2 +- api/tests/payment_it.rs | 81 ------------------- .../quote_sync_upon_budget_creation_it.rs | 1 + .../up.sql | 2 +- .../up.sql | 14 ++-- .../up.sql | 4 +- .../up.sql | 12 +-- .../up.sql | 12 +-- .../up.sql | 4 +- .../up.sql | 12 +-- .../up.sql | 2 +- .../up.sql | 12 +-- .../up.sql | 6 +- .../up.sql | 8 +- .../up.sql | 8 +- .../up.sql | 8 +- .../up.sql | 6 +- .../up.sql | 4 +- .../up.sql | 8 +- 20 files changed, 63 insertions(+), 176 deletions(-) delete mode 100644 api/src/models/crypto_usd_quotes copy.rs diff --git a/api/src/models/crypto_usd_quotes copy.rs b/api/src/models/crypto_usd_quotes copy.rs deleted file mode 100644 index ec505fcbe3..0000000000 --- a/api/src/models/crypto_usd_quotes copy.rs +++ /dev/null @@ -1,33 +0,0 @@ -use chrono::{NaiveDateTime, Utc}; -use diesel::{Identifiable, Queryable}; -use infrastructure::database::{enums::Currency, schema::crypto_usd_quotes}; -use rust_decimal::Decimal; -use serde::{Deserialize, Serialize}; - -#[derive( - Debug, Clone, Insertable, Identifiable, Serialize, Deserialize, AsChangeset, Queryable, Model, -)] -#[diesel(primary_key(currency))] -pub struct CryptoUsdQuote { - pub currency: Currency, - pub price: Decimal, - pub updated_at: NaiveDateTime, -} - -impl CryptoUsdQuote { - pub fn new(currency: Currency, price: Decimal) -> Self { - Self { - currency, - price, - updated_at: Utc::now().naive_utc(), - } - } -} - -impl Identifiable for CryptoUsdQuote { - type Id = Currency; - - fn id(self) -> Self::Id { - self.currency - } -} diff --git a/api/tests/crypto_quotes_sync_it.rs b/api/tests/crypto_quotes_sync_it.rs index 26b451bf8e..5201ccdca2 100644 --- a/api/tests/crypto_quotes_sync_it.rs +++ b/api/tests/crypto_quotes_sync_it.rs @@ -42,7 +42,7 @@ impl<'a> Test<'a> { info!("should_fetch_and_store_all_usd_prices"); // Given - self.context.database.client.insert_all(vec![ + self.context.database.client.try_insert_all(vec![ CryptoUsdQuote { currency: Currency::Eth, price: Decimal::ZERO, diff --git a/api/tests/payment_it.rs b/api/tests/payment_it.rs index 8e12de8eb2..b75257ed87 100644 --- a/api/tests/payment_it.rs +++ b/api/tests/payment_it.rs @@ -46,7 +46,6 @@ pub async fn payment_processing(docker: &'static Cli) { test.project_lead_can_request_payments_in_eth() .await .expect("project_lead_can_request_payments_in_eth"); - test.indexing_can_block_payment().await.expect("indexing_can_block_payment"); test.anyone_cannot_request_payments() .await .expect("anyone_cannot_request_payments"); @@ -317,86 +316,6 @@ impl<'a> Test<'a> { Ok(()) } - async fn indexing_can_block_payment(&mut self) -> Result<()> { - info!("indexing_can_block_payment"); - - // Given - let project_id = ProjectId::new(); - let budget_id = BudgetId::new(); - - self.context - .event_publisher - .publish_many(&[ - ProjectEvent::Created { id: project_id }.into(), - ProjectEvent::BudgetLinked { - id: project_id, - budget_id, - currency: currencies::USD, - } - .into(), - BudgetEvent::Created { - id: budget_id, - currency: currencies::USD, - } - .into(), - BudgetEvent::Allocated { - id: budget_id, - amount: Decimal::from(1_000), - sponsor_id: None, - } - .into(), - ]) - .await?; - - let request = json!({ - "projectId": project_id, - "recipientId": 595505, - "amount": 10, - "currency": "USD", - "hoursWorked": 1, - "reason": { - "workItems": [{ - "type": "PULL_REQUEST", - "id": "123456", - "repoId": 498695724, - "number": 111 - }, - { - "type": "PULL_REQUEST", - "id": "123456", - "repoId": 1181927, - "number": 111 - }] - } - }); - - // When - let response = self - .context - .http_client - .post("/api/payments") - .header(ContentType::JSON) - .header(api_key_header()) - .header(Header::new("x-hasura-role", "registered_user")) - .header(Header::new( - "Authorization", - format!("Bearer {}", jwt(Some(project_id.to_string()))), - )) - .body(request.to_string()) - .dispatch() - .await; - - // Then - assert_eq!( - response.status(), - Status::InternalServerError, - "{}", - response.into_string().await.unwrap_or_default() - ); - - Ok(()) - } - async fn anyone_cannot_request_payments(&mut self) -> Result<()> { info!("anyone_cannot_request_payments"); diff --git a/api/tests/quote_sync_upon_budget_creation_it.rs b/api/tests/quote_sync_upon_budget_creation_it.rs index eb6e1adb56..0b1aeb46d6 100644 --- a/api/tests/quote_sync_upon_budget_creation_it.rs +++ b/api/tests/quote_sync_upon_budget_creation_it.rs @@ -36,6 +36,7 @@ impl<'a> Test<'a> { // Given let before = Utc::now().naive_utc(); + ImmutableRepository::::clear(self.context.database.client.as_ref())?; // When self.context diff --git a/migrations/2023-08-07-210042_create-contributions-projection/up.sql b/migrations/2023-08-07-210042_create-contributions-projection/up.sql index b8a23756cb..8d5b246709 100644 --- a/migrations/2023-08-07-210042_create-contributions-projection/up.sql +++ b/migrations/2023-08-07-210042_create-contributions-projection/up.sql @@ -1,4 +1,4 @@ -CREATE TYPE contribution_type AS enum('issue', 'pull_request', 'code_review'); +CREATE TYPE contribution_type AS enum('ISSUE', 'PULL_REQUEST', 'CODE_REVIEW'); CREATE TABLE diff --git a/migrations/2023-08-17-143042_2023-08-16_update-contributions-table-and-views/up.sql b/migrations/2023-08-17-143042_2023-08-16_update-contributions-table-and-views/up.sql index b08e6ed1b2..a73317ec64 100644 --- a/migrations/2023-08-17-143042_2023-08-16_update-contributions-table-and-views/up.sql +++ b/migrations/2023-08-17-143042_2023-08-16_update-contributions-table-and-views/up.sql @@ -91,15 +91,15 @@ SELECT DATE_PART('week'::TEXT, c.created_at) AS week, COUNT(c.details_id) FILTER ( WHERE - c.type = 'issue' + c.type = 'ISSUE' ) AS issue_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'code_review' + c.type = 'CODE_REVIEW' ) AS code_review_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'pull_request' + c.type = 'PULL_REQUEST' ) AS pull_request_count FROM api.completed_contributions c @@ -117,15 +117,15 @@ SELECT COUNT(*) AS total_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'issue' + c.type = 'ISSUE' ) AS issue_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'code_review' + c.type = 'CODE_REVIEW' ) AS code_review_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'pull_request' + c.type = 'PULL_REQUEST' ) AS pull_request_count, MIN(c.created_at) AS min_date, MAX(c.created_at) AS max_date @@ -150,4 +150,4 @@ CREATE TABLE CREATE TABLE - projects_pending_contributors (project_id UUID NOT NULL, github_user_id BIGINT NOT NULL, PRIMARY KEY (project_id, github_user_id)); + projects_pending_contributors (project_id UUID NOT NULL, github_user_id BIGINT NOT NULL, PRIMARY KEY (project_id, github_user_id)); \ No newline at end of file diff --git a/migrations/2023-09-05-092911_migrate-work-items/up.sql b/migrations/2023-09-05-092911_migrate-work-items/up.sql index 2cac79eddf..a18c95f1c0 100644 --- a/migrations/2023-09-05-092911_migrate-work-items/up.sql +++ b/migrations/2023-09-05-092911_migrate-work-items/up.sql @@ -46,8 +46,8 @@ UPDATE work_items SET id = twi.id, "type" = CASE - WHEN twi.type = 'ISSUE' THEN 'issue'::contribution_type - ELSE 'pull_request'::contribution_type + WHEN twi.type = 'ISSUE' THEN 'ISSUE'::contribution_type + ELSE 'PULL_REQUEST'::contribution_type END FROM temp_work_items twi diff --git a/migrations/2023-09-05-133220_add-code-review-id/up.sql b/migrations/2023-09-05-133220_add-code-review-id/up.sql index 3092ed14b0..d619d6d4fd 100644 --- a/migrations/2023-09-05-133220_add-code-review-id/up.sql +++ b/migrations/2023-09-05-133220_add-code-review-id/up.sql @@ -88,15 +88,15 @@ SELECT DATE_PART('week'::TEXT, c.created_at) AS week, COUNT(c.details_id) FILTER ( WHERE - c.type = 'issue' + c.type = 'ISSUE' ) AS issue_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'code_review' + c.type = 'CODE_REVIEW' ) AS code_review_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'pull_request' + c.type = 'PULL_REQUEST' ) AS pull_request_count FROM api.completed_contributions c @@ -114,15 +114,15 @@ SELECT COUNT(*) AS total_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'issue' + c.type = 'ISSUE' ) AS issue_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'code_review' + c.type = 'CODE_REVIEW' ) AS code_review_count, COUNT(c.details_id) FILTER ( WHERE - c.type = 'pull_request' + c.type = 'PULL_REQUEST' ) AS pull_request_count, MIN(c.created_at) AS min_date, MAX(c.created_at) AS max_date diff --git a/migrations/2023-09-05-155357_add-contribution-id/up.sql b/migrations/2023-09-05-155357_add-contribution-id/up.sql index 84a0510283..ba4f43484e 100644 --- a/migrations/2023-09-05-155357_add-contribution-id/up.sql +++ b/migrations/2023-09-05-155357_add-contribution-id/up.sql @@ -73,15 +73,15 @@ SELECT count(*) AS total_count, count(c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, count(c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, count(c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count, min(c.created_at) AS min_date, max(c.created_at) AS max_date @@ -100,15 +100,15 @@ SELECT date_part('week'::text, c.created_at) AS week, count(c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, count(c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, count(c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count FROM api.completed_contributions c diff --git a/migrations/2023-09-05-194537_create-ignored-contributions-table/up.sql b/migrations/2023-09-05-194537_create-ignored-contributions-table/up.sql index 90b3bc01ab..a88509b6e8 100644 --- a/migrations/2023-09-05-194537_create-ignored-contributions-table/up.sql +++ b/migrations/2023-09-05-194537_create-ignored-contributions-table/up.sql @@ -13,7 +13,7 @@ FROM AND igi.issue_number = gpr."number" INNER JOIN contributions c ON c.repo_id = gpr.repo_id AND c.details_id::BIGINT = gpr.id - AND c."type" = 'pull_request'::contribution_type; + AND c."type" = 'PULL_REQUEST'::contribution_type; INSERT INTO @@ -27,7 +27,7 @@ FROM AND igi.issue_number = gi."number" INNER JOIN contributions c ON c.repo_id = gi.repo_id AND c.details_id::BIGINT = gi.id - AND c."type" = 'issue'::contribution_type; + AND c."type" = 'ISSUE'::contribution_type; DROP TABLE ignored_github_issues; \ No newline at end of file diff --git a/migrations/2023-09-06-124029_add-ignored-in-contributions-views/up.sql b/migrations/2023-09-06-124029_add-ignored-in-contributions-views/up.sql index 841ff13e64..0277a37027 100644 --- a/migrations/2023-09-06-124029_add-ignored-in-contributions-views/up.sql +++ b/migrations/2023-09-06-124029_add-ignored-in-contributions-views/up.sql @@ -41,15 +41,15 @@ SELECT count(*) AS total_count, count(c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, count(c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, count(c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count, min(c.created_at) AS min_date, max(c.created_at) AS max_date @@ -68,15 +68,15 @@ SELECT date_part('week'::text, c.created_at) AS week, count(c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, count(c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, count(c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count FROM api.completed_contributions c diff --git a/migrations/2023-09-06-154541_update-code-review-details-id/up.sql b/migrations/2023-09-06-154541_update-code-review-details-id/up.sql index a335090555..c2e41ca79d 100644 --- a/migrations/2023-09-06-154541_update-code-review-details-id/up.sql +++ b/migrations/2023-09-06-154541_update-code-review-details-id/up.sql @@ -5,5 +5,5 @@ FROM github_pull_request_reviews gr WHERE details_id = gr.pull_request_id::text - AND "type" = 'code_review'::contribution_type + AND "type" = 'CODE_REVIEW'::contribution_type AND user_id = gr.reviewer_id; \ No newline at end of file diff --git a/migrations/2023-09-11-133622_fix-contributions-and-work-items-relationships/up.sql b/migrations/2023-09-11-133622_fix-contributions-and-work-items-relationships/up.sql index b6026f8b74..74e88c3790 100644 --- a/migrations/2023-09-11-133622_fix-contributions-and-work-items-relationships/up.sql +++ b/migrations/2023-09-11-133622_fix-contributions-and-work-items-relationships/up.sql @@ -14,15 +14,15 @@ SELECT c.created_at, pgr.project_id, CASE - WHEN c.type = 'issue'::contribution_type THEN c.details_id::BIGINT + WHEN c.type = 'ISSUE'::contribution_type THEN c.details_id::BIGINT ELSE NULL END AS github_issue_id, CASE - WHEN c.type = 'pull_request'::contribution_type THEN c.details_id::BIGINT + WHEN c.type = 'PULL_REQUEST'::contribution_type THEN c.details_id::BIGINT ELSE NULL END AS github_pull_request_id, CASE - WHEN c.type = 'code_review'::contribution_type THEN c.details_id + WHEN c.type = 'CODE_REVIEW'::contribution_type THEN c.details_id ELSE NULL END AS github_code_review_id, EXISTS ( @@ -50,15 +50,15 @@ SELECT w.project_id, w.recipient_id, CASE - WHEN w.type = 'issue'::contribution_type THEN w.id::BIGINT + WHEN w.type = 'ISSUE'::contribution_type THEN w.id::BIGINT ELSE NULL END AS github_issue_id, CASE - WHEN w.type = 'pull_request'::contribution_type THEN w.id::BIGINT + WHEN w.type = 'PULL_REQUEST'::contribution_type THEN w.id::BIGINT ELSE NULL END AS github_pull_request_id, CASE - WHEN w.type = 'code_review'::contribution_type THEN w.id + WHEN w.type = 'CODE_REVIEW'::contribution_type THEN w.id ELSE NULL END AS github_code_review_id FROM diff --git a/migrations/2023-09-15-131612_uppercase-contribution-type/up.sql b/migrations/2023-09-15-131612_uppercase-contribution-type/up.sql index 816c697fed..6eac6c462c 100644 --- a/migrations/2023-09-15-131612_uppercase-contribution-type/up.sql +++ b/migrations/2023-09-15-131612_uppercase-contribution-type/up.sql @@ -14,15 +14,15 @@ SELECT c.created_at, pgr.project_id, CASE - WHEN c.type = 'issue'::contribution_type THEN c.details_id::bigint + WHEN c.type = 'ISSUE'::contribution_type THEN c.details_id::bigint ELSE NULL::bigint END AS github_issue_id, CASE - WHEN c.type = 'pull_request'::contribution_type THEN c.details_id::bigint + WHEN c.type = 'PULL_REQUEST'::contribution_type THEN c.details_id::bigint ELSE NULL::bigint END AS github_pull_request_id, CASE - WHEN c.type = 'code_review'::contribution_type THEN c.details_id + WHEN c.type = 'CODE_REVIEW'::contribution_type THEN c.details_id ELSE NULL::text END AS github_code_review_id, ( diff --git a/migrations/2023-09-19-124157_compute-contributions-and-contributors-in-views/up.sql b/migrations/2023-09-19-124157_compute-contributions-and-contributors-in-views/up.sql index e4fde9deb0..556413f124 100644 --- a/migrations/2023-09-19-124157_compute-contributions-and-contributors-in-views/up.sql +++ b/migrations/2023-09-19-124157_compute-contributions-and-contributors-in-views/up.sql @@ -12,7 +12,7 @@ SET FROM github_issues gi WHERE - c."type" = 'issue'::contribution_type + c."type" = 'ISSUE'::contribution_type AND gi.id = c.details_id::BIGINT; @@ -30,7 +30,7 @@ SET FROM github_pull_requests pr WHERE - c."type" = 'pull_request'::contribution_type + c."type" = 'PULL_REQUEST'::contribution_type AND pr.id = c.details_id::BIGINT; @@ -53,7 +53,7 @@ FROM github_pull_request_reviews r JOIN github_pull_requests pr ON pr.id = r.pull_request_id WHERE - c."type" = 'code_review'::contribution_type + c."type" = 'CODE_REVIEW'::contribution_type AND r.id = c.details_id; @@ -82,4 +82,4 @@ SELECT DISTINCT c.user_id FROM contributions c - JOIN project_github_repos pgr ON pgr.github_repo_id = c.repo_id; + JOIN project_github_repos pgr ON pgr.github_repo_id = c.repo_id; \ No newline at end of file diff --git a/migrations/2023-09-20-132835_fix-contribution_counts/up.sql b/migrations/2023-09-20-132835_fix-contribution_counts/up.sql index c88e890ebf..7d5ae9dffc 100644 --- a/migrations/2023-09-20-132835_fix-contribution_counts/up.sql +++ b/migrations/2023-09-20-132835_fix-contribution_counts/up.sql @@ -6,19 +6,19 @@ SELECT DATE_PART('week'::TEXT, c.created_at) AS week, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count FROM api.completed_contributions c GROUP BY c.github_user_id, (DATE_PART('year'::TEXT, c.created_at)), - (DATE_PART('week'::TEXT, c.created_at)); + (DATE_PART('week'::TEXT, c.created_at)); \ No newline at end of file diff --git a/migrations/2023-09-20-142450_fix-contribution_counts-again/up.sql b/migrations/2023-09-20-142450_fix-contribution_counts-again/up.sql index e18f434eb9..ad75e0e7bd 100644 --- a/migrations/2023-09-20-142450_fix-contribution_counts-again/up.sql +++ b/migrations/2023-09-20-142450_fix-contribution_counts-again/up.sql @@ -9,19 +9,19 @@ SELECT DATE_PART('week'::TEXT, c.created_at) AS week, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count FROM api.completed_contributions c GROUP BY c.github_user_id, (DATE_PART('year'::TEXT, c.created_at)), - (DATE_PART('week'::TEXT, c.created_at)); + (DATE_PART('week'::TEXT, c.created_at)); \ No newline at end of file diff --git a/migrations/2023-09-29-055836_add-pr-author-as-contributor/up.sql b/migrations/2023-09-29-055836_add-pr-author-as-contributor/up.sql index 539b39a20b..3b1ab305e8 100644 --- a/migrations/2023-09-29-055836_add-pr-author-as-contributor/up.sql +++ b/migrations/2023-09-29-055836_add-pr-author-as-contributor/up.sql @@ -1,10 +1,10 @@ INSERT INTO contributions (id, repo_id, user_id, "type", details_id, status, created_at, closed_at) ( SELECT - encode(sha256(row ('pull_request'::contribution_type, id, author_id)::text::bytea), 'hex') as id, + encode(sha256(row ('PULL_REQUEST'::contribution_type, id, author_id)::text::bytea), 'hex') as id, repo_id, author_id, - 'pull_request'::contribution_type as "type", + 'PULL_REQUEST'::contribution_type as "type", id as details_id, CASE WHEN status = 'open'::github_pull_request_status THEN 'in_progress'::contribution_status @@ -16,4 +16,4 @@ INSERT INTO from github_pull_requests ) ON CONFLICT -DO NOTHING; +DO NOTHING; \ No newline at end of file diff --git a/migrations/2023-09-29-140256_fix-duplicate-contributions/up.sql b/migrations/2023-09-29-140256_fix-duplicate-contributions/up.sql index 06645e8864..e5df835bdc 100644 --- a/migrations/2023-09-29-140256_fix-duplicate-contributions/up.sql +++ b/migrations/2023-09-29-140256_fix-duplicate-contributions/up.sql @@ -9,7 +9,7 @@ INSERT INTO encode(sha256(row ('PULL_REQUEST', id, author_id)::text::bytea), 'hex') as id, repo_id, author_id, - 'pull_request'::contribution_type as "type", + 'PULL_REQUEST'::contribution_type as "type", id as details_id, CASE WHEN status = 'open'::github_pull_request_status THEN 'in_progress'::contribution_status @@ -21,4 +21,4 @@ INSERT INTO from github_pull_requests ) ON CONFLICT -DO NOTHING; +DO NOTHING; \ No newline at end of file diff --git a/migrations/2023-10-02-153619_fix-contribution-counts/up.sql b/migrations/2023-10-02-153619_fix-contribution-counts/up.sql index ef66b82a3f..078f147165 100644 --- a/migrations/2023-10-02-153619_fix-contribution-counts/up.sql +++ b/migrations/2023-10-02-153619_fix-contribution-counts/up.sql @@ -6,19 +6,19 @@ SELECT DATE_PART('week'::TEXT, c.created_at) AS "week", COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'issue'::contribution_type + c.type = 'ISSUE'::contribution_type ) AS issue_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'code_review'::contribution_type + c.type = 'CODE_REVIEW'::contribution_type ) AS code_review_count, COUNT(DISTINCT c.details_id) FILTER ( WHERE - c.type = 'pull_request'::contribution_type + c.type = 'PULL_REQUEST'::contribution_type ) AS pull_request_count FROM api.completed_contributions c GROUP BY c.github_user_id, "year", - "week"; + "week"; \ No newline at end of file