-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1644 from Bee-lee/account-number-out
Part 1 of `org_id`/`account_number` c.r.c. migration
- Loading branch information
Showing
29 changed files
with
523 additions
and
242 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,4 @@ then | |
go get github.com/fzipp/gocyclo/cmd/gocyclo | ||
fi | ||
|
||
gocyclo -over 10 -avg . | ||
gocyclo -over 12 -avg . |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2022 Red Hat, Inc | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// This migration adds a new column "org_id" to cluster_rule_toggle, | ||
// cluster_rule_user_feedback and cluster_user_rule_disable_feedback tables, | ||
// then it populates the new column based on the report table, where we have | ||
// information about cluster_id + org_id, so we don't have to use the org_id | ||
// populator from c.r.c. team. | ||
|
||
package migration | ||
|
||
import ( | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/RedHatInsights/insights-results-aggregator/types" | ||
) | ||
|
||
const ( | ||
addOrgIDQuery = "ALTER TABLE %v ADD COLUMN org_id VARCHAR NOT NULL DEFAULT '0'" | ||
updateOrgIDQuery = "UPDATE %v as t SET org_id = report.org_id FROM report WHERE report.cluster = t.cluster_id" | ||
dropOrgIDQuery = "ALTER TABLE %v DROP COLUMN IF EXISTS org_id" | ||
) | ||
|
||
var tablesToUpdate = []string{ | ||
"cluster_rule_toggle", | ||
"cluster_rule_user_feedback", | ||
"cluster_user_rule_disable_feedback", | ||
} | ||
|
||
var mig0026AddAndPopulateOrgIDColumns = Migration{ | ||
StepUp: func(tx *sql.Tx, driver types.DBDriver) error { | ||
|
||
for _, table := range tablesToUpdate { | ||
alterQuery := fmt.Sprintf(addOrgIDQuery, table) | ||
updateQuery := fmt.Sprintf(updateOrgIDQuery, table) | ||
|
||
// add org_id column | ||
_, err := tx.Exec(alterQuery) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if driver == types.DBDriverPostgres { | ||
// update org_id from report table | ||
_, err = tx.Exec(updateQuery) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
StepDown: func(tx *sql.Tx, driver types.DBDriver) error { | ||
|
||
for _, table := range tablesToUpdate { | ||
dropQuery := fmt.Sprintf(dropOrgIDQuery, table) | ||
|
||
// Remove the columns | ||
_, err := tx.Exec(dropQuery) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.