From 709d6011ff882dc26140c4e8d1cb9fe8c2f2078b Mon Sep 17 00:00:00 2001 From: elraphty Date: Fri, 26 Apr 2024 13:30:54 +0100 Subject: [PATCH 1/2] fixed migration org uuid --- .github/workflows/docker-build-on-master.yml | 9 +++------ .github/workflows/frontend-e2e.yml | 2 +- .github/workflows/prjob_tests.yml | 2 +- db/config.go | 14 ++++++++++++++ 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/.github/workflows/docker-build-on-master.yml b/.github/workflows/docker-build-on-master.yml index df0cb0219..8bba45a8f 100644 --- a/.github/workflows/docker-build-on-master.yml +++ b/.github/workflows/docker-build-on-master.yml @@ -4,13 +4,13 @@ env: on: push: - branch: - - master + branches: + - master jobs: build: runs-on: ubuntu-20.04 - name: Build and push Tribes image + name: Build and push Tribes image env: ACTIONS_ALLOW_UNSECURE_COMMANDS: true steps: @@ -44,6 +44,3 @@ jobs: --platform linux/amd64,linux/arm64,linux/arm/v7 \ --tag "${{ secrets.DOCKER_HUB_USER }}/sphinx-tribes:master" \ --output "type=registry" ./ - - - diff --git a/.github/workflows/frontend-e2e.yml b/.github/workflows/frontend-e2e.yml index d284d6a53..36675e00b 100644 --- a/.github/workflows/frontend-e2e.yml +++ b/.github/workflows/frontend-e2e.yml @@ -2,7 +2,7 @@ name: Cypress Frontend E2E tests on: pull_request: branches: - - master + - "*" jobs: cypress-run: diff --git a/.github/workflows/prjob_tests.yml b/.github/workflows/prjob_tests.yml index 810e6a84e..38a579912 100644 --- a/.github/workflows/prjob_tests.yml +++ b/.github/workflows/prjob_tests.yml @@ -2,7 +2,7 @@ name: Tests on: pull_request: branches: - - master + - "*" jobs: test-go: name: Go diff --git a/db/config.go b/db/config.go index 9789078b9..f635fa4ef 100644 --- a/db/config.go +++ b/db/config.go @@ -177,6 +177,8 @@ func (db database) MigrateTablesWithOrgUuid() { if !db.db.Migrator().HasTable("bounty") { if !db.db.Migrator().HasColumn(Bounty{}, "workspace_uuid") { db.db.AutoMigrate(&Bounty{}) + } else { + db.db.AutoMigrate(&NewBounty{}) } } if !db.db.Migrator().HasTable("budget_histories") { @@ -187,28 +189,40 @@ func (db database) MigrateTablesWithOrgUuid() { if !db.db.Migrator().HasTable("payment_histories") { if !db.db.Migrator().HasColumn(PaymentHistory{}, "workspace_uuid") { db.db.AutoMigrate(&PaymentHistory{}) + } else { + db.db.AutoMigrate(&NewPaymentHistory{}) } } if !db.db.Migrator().HasTable("invoice_list") { if !db.db.Migrator().HasColumn(InvoiceList{}, "workspace_uuid") { db.db.AutoMigrate(&InvoiceList{}) + } else { + db.db.AutoMigrate(&NewInvoiceList{}) } } if !db.db.Migrator().HasTable("bounty_budgets") { if !db.db.Migrator().HasColumn(BountyBudget{}, "workspace_uuid") { db.db.AutoMigrate(&BountyBudget{}) + } else { + db.db.AutoMigrate(&NewBountyBudget{}) } } if !db.db.Migrator().HasTable("workspace_user_roles") { if !db.db.Migrator().HasColumn(UserRoles{}, "workspace_uuid") { db.db.AutoMigrate(&UserRoles{}) } + } else { + db.db.AutoMigrate(&WorkspaceUserRoles{}) } if !db.db.Migrator().HasTable("workspaces") { db.db.AutoMigrate(&Organization{}) + } else { + db.db.AutoMigrate(&Workspace{}) } if !db.db.Migrator().HasTable("workspace_users") { db.db.AutoMigrate(&OrganizationUsers{}) + } else { + db.db.AutoMigrate(&WorkspaceUsers{}) } } From 78e347052b62d1a9a51d1d25fcdbf55aba5c516a Mon Sep 17 00:00:00 2001 From: elraphty Date: Fri, 26 Apr 2024 16:50:14 +0100 Subject: [PATCH 2/2] added difference in budget --- db/db.go | 2 +- db/structs.go | 21 ++++++++++++--------- db/workspaces.go | 27 ++++++++++++++++++--------- 3 files changed, 31 insertions(+), 19 deletions(-) diff --git a/db/db.go b/db/db.go index d2af69fb5..ed1fd7e18 100644 --- a/db/db.go +++ b/db/db.go @@ -1142,7 +1142,7 @@ func (db database) GetAllBounties(r *http.Request) []NewBounty { languageArray := strings.Split(languages, ",") languageLength := len(languageArray) - if workspaceUuid != "" && orgUuid != "" { + if workspaceUuid == "" && orgUuid != "" { workspaceUuid = orgUuid } diff --git a/db/structs.go b/db/structs.go index 7f1bf8ea6..6ab15f38d 100644 --- a/db/structs.go +++ b/db/structs.go @@ -581,15 +581,18 @@ type NewBountyBudget struct { } type StatusBudget struct { - OrgUuid string `json:"org_uuid"` - WorkspaceUuid string `json:"workspace_uuid"` - CurrentBudget uint `json:"current_budget"` - OpenBudget uint `json:"open_budget"` - OpenCount int64 `json:"open_count"` - AssignedBudget uint `json:"assigned_budget"` - AssignedCount int64 `json:"assigned_count"` - CompletedBudget uint `json:"completed_budget"` - CompletedCount int64 `json:"completed_count"` + OrgUuid string `json:"org_uuid"` + WorkspaceUuid string `json:"workspace_uuid"` + CurrentBudget uint `json:"current_budget"` + OpenBudget uint `json:"open_budget"` + OpenCount int64 `json:"open_count"` + OpenDifference int `json:"open_difference"` + AssignedBudget uint `json:"assigned_budget"` + AssignedCount int64 `json:"assigned_count"` + AssignedDifference int `json:"assigned_difference"` + CompletedBudget uint `json:"completed_budget"` + CompletedCount int64 `json:"completed_count"` + CompletedDifference int `json:"completed_difference"` } type BudgetInvoiceRequest struct { diff --git a/db/workspaces.go b/db/workspaces.go index d1e77b596..f737bdd31 100644 --- a/db/workspaces.go +++ b/db/workspaces.go @@ -162,28 +162,37 @@ func (db database) GetWorkspaceStatusBudget(workspace_uuid string) StatusBudget var openCount int64 db.db.Model(&Bounty{}).Where("assignee = '' ").Where("paid != true").Count(&openCount) + var openDifference int = int(orgBudget.TotalBudget - openBudget) + var assignedBudget uint db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Select("SUM(price)").Row().Scan(&assignedBudget) var assignedCount int64 db.db.Model(&Bounty{}).Where("assignee != '' ").Where("paid != true").Count(&assignedCount) + var assignedDifference int = int(orgBudget.TotalBudget - assignedBudget) + var completedBudget uint db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Select("SUM(price)").Row().Scan(&completedBudget) var completedCount int64 db.db.Model(&Bounty{}).Where("completed = true ").Where("paid != true").Count(&completedCount) + var completedDifference int = int(orgBudget.TotalBudget - completedBudget) + statusBudget := StatusBudget{ - OrgUuid: workspace_uuid, - WorkspaceUuid: workspace_uuid, - CurrentBudget: orgBudget.TotalBudget, - OpenBudget: openBudget, - OpenCount: openCount, - AssignedBudget: assignedBudget, - AssignedCount: assignedCount, - CompletedBudget: completedBudget, - CompletedCount: completedCount, + OrgUuid: workspace_uuid, + WorkspaceUuid: workspace_uuid, + CurrentBudget: orgBudget.TotalBudget, + OpenBudget: openBudget, + OpenCount: openCount, + OpenDifference: openDifference, + AssignedBudget: assignedBudget, + AssignedCount: assignedCount, + AssignedDifference: assignedDifference, + CompletedBudget: completedBudget, + CompletedCount: completedCount, + CompletedDifference: completedDifference, } return statusBudget