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

Fixed Migrations, and added difference sum for budgets #1619

Merged
merged 2 commits into from
Apr 27, 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
9 changes: 3 additions & 6 deletions .github/workflows/docker-build-on-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -44,6 +44,3 @@ jobs:
--platform linux/amd64,linux/arm64,linux/arm/v7 \
--tag "${{ secrets.DOCKER_HUB_USER }}/sphinx-tribes:master" \
--output "type=registry" ./
2 changes: 1 addition & 1 deletion .github/workflows/frontend-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Cypress Frontend E2E tests
on:
pull_request:
branches:
- master
- "*"

jobs:
cypress-run:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/prjob_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Tests
on:
pull_request:
branches:
- master
- "*"
jobs:
test-go:
name: Go
Expand Down
14 changes: 14 additions & 0 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand All @@ -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{})
}
}

Expand Down
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
21 changes: 12 additions & 9 deletions db/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 18 additions & 9 deletions db/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading