Skip to content

Commit

Permalink
modified migration
Browse files Browse the repository at this point in the history
  • Loading branch information
elraphty committed Apr 22, 2024
1 parent ca433a5 commit 9e0e8ff
Show file tree
Hide file tree
Showing 6 changed files with 1,230 additions and 10 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 14 additions & 9 deletions db/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ func InitDB() {
db.AutoMigrate(&LeaderBoard{})
db.AutoMigrate(&ConnectionCodes{})
db.AutoMigrate(&Bounty{})
db.AutoMigrate(&Organization{})
db.AutoMigrate(&OrganizationUsers{})
db.AutoMigrate(&BountyRoles{})
db.AutoMigrate(&UserRoles{})
db.AutoMigrate(&BountyBudget{})
Expand All @@ -76,6 +74,13 @@ func InitDB() {
db.AutoMigrate(&InvoiceList{})
db.AutoMigrate(&UserInvoiceData{})

if !db.Migrator().HasTable("workspaces") {
db.AutoMigrate(&Organization{})
}
if !db.Migrator().HasTable("workspace_users") {
db.AutoMigrate(&OrganizationUsers{})
}

DB.MigrateOrganizationToWorkspace()

people := DB.GetAllPeople()
Expand Down Expand Up @@ -186,44 +191,44 @@ func (db database) MigrateOrganizationToWorkspace() {
}

if (db.db.Migrator().HasTable(&OrganizationUsers{}) && !db.db.Migrator().HasTable("workspace_users")) {
if !db.db.Migrator().HasColumn(&OrganizationUsers{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&OrganizationUsers{}, "org_uuid") {
db.db.Migrator().RenameColumn(&OrganizationUsers{}, "org_uuid", "workspace_uuid")
}
db.db.Migrator().RenameTable(&OrganizationUsers{}, "workspace_users")
}

if (db.db.Migrator().HasTable(&UserRoles{})) {
if !db.db.Migrator().HasColumn(&UserRoles{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&UserRoles{}, "org_uuid") {
db.db.Migrator().RenameColumn(&UserRoles{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&Bounty{})) {
if !db.db.Migrator().HasColumn(&Bounty{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&Bounty{}, "org_uuid") {
db.db.Migrator().RenameColumn(&Bounty{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&BountyBudget{})) {
if !db.db.Migrator().HasColumn(&BountyBudget{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&BountyBudget{}, "org_uuid") {
db.db.Migrator().RenameColumn(&BountyBudget{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&BudgetHistory{})) {
if !db.db.Migrator().HasColumn(&BudgetHistory{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&BudgetHistory{}, "org_uuid") {
db.db.Migrator().RenameColumn(&BudgetHistory{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&PaymentHistory{})) {
if !db.db.Migrator().HasColumn(&PaymentHistory{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&PaymentHistory{}, "org_uuid") {
db.db.Migrator().RenameColumn(&PaymentHistory{}, "org_uuid", "workspace_uuid")
}
}

if (db.db.Migrator().HasTable(&InvoiceList{})) {
if !db.db.Migrator().HasColumn(&InvoiceList{}, "workspace_uuid") {
if db.db.Migrator().HasColumn(&InvoiceList{}, "org_uuid") {
db.db.Migrator().RenameColumn(&InvoiceList{}, "org_uuid", "workspace_uuid")
}
}
Expand Down
2 changes: 1 addition & 1 deletion db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,7 @@ func (db database) GetAllBounties(r *http.Request) []Bounty {
assingned := keys.Get("Assigned")
completed := keys.Get("Completed")
paid := keys.Get("Paid")
orgUuid := keys.Get("org_uuid")
orgUuid := keys.Get("workspace_uuid")
languages := keys.Get("languages")
languageArray := strings.Split(languages, ",")
languageLength := len(languageArray)
Expand Down
Loading

0 comments on commit 9e0e8ff

Please sign in to comment.